Merge pull request #10738 from mfo/US/fix-not-expanded-type-de-champ-textarea

ETQ usager, j'aimerais avoir les champs de type texte long d'une hauteur differente des champs de type texte court
This commit is contained in:
mfo 2024-09-03 15:24:25 +00:00 committed by GitHub
commit 0b8212f151
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -3,16 +3,31 @@ import { attach } from '@frsource/autoresize-textarea';
import { isTextAreaElement } from '@coldwired/utils'; import { isTextAreaElement } from '@coldwired/utils';
export class AutoresizeController extends ApplicationController { export class AutoresizeController extends ApplicationController {
declare observer: IntersectionObserver;
#detach?: () => void; #detach?: () => void;
connect(): void { connect(): void {
if (isTextAreaElement(this.element)) { if (isTextAreaElement(this.element)) {
this.#detach = attach(this.element)?.detach;
this.element.classList.add('resize-none'); this.element.classList.add('resize-none');
this.observer = new IntersectionObserver(this.onIntersect.bind(this), {
threshold: [0]
});
this.observer.observe(this.element);
}
}
onIntersect(entries: IntersectionObserverEntry[]): void {
const visible = entries[0].isIntersecting == true;
if (visible) {
this.#detach = attach(this.element as HTMLTextAreaElement)?.detach;
this.observer.unobserve(this.element);
} }
} }
disconnect(): void { disconnect(): void {
this.#detach?.(); this.#detach?.();
this.observer.unobserve(this.element);
this.element.classList.remove('resize-none'); this.element.classList.remove('resize-none');
} }
} }