Only trigger defaultslotchange of select after initialization (#2318)

next^2
Susanne Kirchner 2025-01-02 15:59:18 +01:00 zatwierdzone przez GitHub
rodzic b5e82d676a
commit 81e94f2624
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: B5690EEEBB952194
1 zmienionych plików z 13 dodań i 7 usunięć

Wyświetl plik

@ -34,6 +34,8 @@ export default class SlOption extends ShoelaceElement {
// @ts-expect-error - Controller is currently unused // @ts-expect-error - Controller is currently unused
private readonly localize = new LocalizeController(this); private readonly localize = new LocalizeController(this);
private isInitialized = false;
@query('.option__label') defaultSlot: HTMLSlotElement; @query('.option__label') defaultSlot: HTMLSlotElement;
@state() current = false; // the user has keyed into the option, but hasn't selected it yet (shows a highlight) @state() current = false; // the user has keyed into the option, but hasn't selected it yet (shows a highlight)
@ -57,13 +59,17 @@ export default class SlOption extends ShoelaceElement {
} }
private handleDefaultSlotChange() { private handleDefaultSlotChange() {
// When the label changes, tell the controller to update if (this.isInitialized) {
customElements.whenDefined('sl-select').then(() => { // When the label changes, tell the controller to update
const controller = this.closest('sl-select'); customElements.whenDefined('sl-select').then(() => {
if (controller) { const controller = this.closest('sl-select');
controller.handleDefaultSlotChange(); if (controller) {
} controller.handleDefaultSlotChange();
}); }
});
} else {
this.isInitialized = true;
}
} }
private handleMouseEnter() { private handleMouseEnter() {