Skip to content

Commit

Permalink
fix: keep focus on <select> element (#1981)
Browse files Browse the repository at this point in the history
  • Loading branch information
y-lakhdar authored Jul 24, 2024
1 parent 4835fc6 commit 761d2bf
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/ui/SortDropdown/SortDropdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,16 @@ export class SortDropdown extends Component {
this.buildDropdown();
}

private clearDropdown() {
private clearDropdown(): boolean {
const hasFocus = this.dropdown && document.activeElement === this.dropdown.getElement();
this.dropdown && this.element.removeChild(this.dropdown.getElement());
this.dropdown = null;
return hasFocus;
}

private buildDropdown() {
this.sortComponents = this.getEnabledSortComponents();
this.clearDropdown();
const hasFocus = this.clearDropdown();

if (!this.sortComponents.length) {
return;
Expand All @@ -88,6 +90,7 @@ export class SortDropdown extends Component {
);
this.element.appendChild(this.dropdown.getElement());
this.update();
hasFocus && this.dropdown.getElement().focus();
}

private getEnabledSortComponents() {
Expand All @@ -99,9 +102,7 @@ export class SortDropdown extends Component {
return sortCmp;
} else {
this.logger.warn(
`Each Sort component inside a SortDropdown should have only one sort criteria. Skipping ${
sortCmp.options.caption
} in the SortDropdown.`
`Each Sort component inside a SortDropdown should have only one sort criteria. Skipping ${sortCmp.options.caption} in the SortDropdown.`
);
return;
}
Expand Down

0 comments on commit 761d2bf

Please sign in to comment.