demarches-normaliennes/app/javascript/controllers/autoresize_controller.ts

19 lines
542 B
TypeScript
Raw Normal View History

2024-03-07 12:06:00 +01:00
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');
}
}