Skip to content

Commit

Permalink
[BUGFIX] Éviter de throw si l'élément aria-selected de `PixSelect…
Browse files Browse the repository at this point in the history
…` n'existe plus ou pas encore (PIX-15018)

 #746
  • Loading branch information
pix-service-auto-merge authored Nov 22, 2024
2 parents cb479e7 + dbb6d0d commit 1646416
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions addon/components/pix-select.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@ export default class PixSelect extends Component {
element.style.setProperty('--pix-select-width', `${selectWidth}rem`);
});
}

this.elementHelper.waitForElement(`container-${this.selectId}`).then((element) => {
this.rootElement = element;
});
}

get displayDefaultOption() {
Expand Down Expand Up @@ -152,15 +148,16 @@ export default class PixSelect extends Component {
}

@action
focus() {
if (this.isExpanded) {
if (this.args.value) {
this.rootElement.querySelector("[aria-selected='true']").focus();
} else if (this.args.isSearchable) {
document.getElementById(this.searchId).focus();
} else if (this.displayDefaultOption) {
this.rootElement.querySelector("[aria-selected='true']").focus();
}
focus(event) {
if (!event.target) return;
if (!this.isExpanded) return;

if (this.args.value) {
event.target.querySelector("[aria-selected='true']")?.focus();
} else if (this.args.isSearchable) {
event.target.querySelector(`#${this.searchId}`)?.focus();
} else if (this.displayDefaultOption) {
event.target.querySelector("[aria-selected='true']")?.focus();
}
}
}

0 comments on commit 1646416

Please sign in to comment.