demarches-normaliennes/app/javascript/controllers/autoresize_controller.ts
2024-03-25 19:53:29 +01:00

18 lines
542 B
TypeScript

import { ApplicationController } from './application_controller';
import { attach } from '@frsource/autoresize-textarea';
import { isTextAreaElement } from '@coldwired/utils';
export class AutoresizeController extends ApplicationController {
#detach?: () => void;
connect(): void {
if (isTextAreaElement(this.element)) {
this.#detach = attach(this.element)?.detach;
this.element.classList.add('resize-none');
}
}
disconnect(): void {
this.#detach?.();
this.element.classList.remove('resize-none');
}
}