Browse Source

Simplify initial field focus logic in form prop component

Replaces the IntersectionObserver-based focus logic with a simpler requestAnimationFrame approach for focusing the first field. This reduces complexity and potential timing issues when focusing the field after view initialization.
pull/24187/head
Fahri Gedik 7 months ago
parent
commit
47fec83ae1
  1. 29
      npm/ng-packs/packages/components/extensible/src/lib/components/extensible-form/extensible-form-prop.component.ts

29
npm/ng-packs/packages/components/extensible/src/lib/components/extensible-form/extensible-form-prop.component.ts

@ -155,33 +155,10 @@ export class ExtensibleFormPropComponent implements OnChanges, AfterViewInit {
ngAfterViewInit() {
if (this.isFirstGroup && this.first && this.fieldRef) {
this.focusField();
}
}
private focusField() {
const element = this.fieldRef.nativeElement;
if (this.isElementVisible(element)) {
element.focus();
return;
}
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting && entry.intersectionRatio > 0) {
element.focus();
observer.disconnect();
}
requestAnimationFrame(() => {
this.fieldRef.nativeElement.focus();
});
}, { threshold: 0.01 });
observer.observe(element);
setTimeout(() => observer.disconnect(), 5000);
}
private isElementVisible(element: HTMLElement): boolean {
return element.offsetParent !== null;
}
}
getComponent(prop: FormProp): string {

Loading…
Cancel
Save