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:
commit
0b8212f151
1 changed files with 16 additions and 1 deletions
|
@ -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');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue