diff --git a/core/pfe-core/controllers/listbox-controller.ts b/core/pfe-core/controllers/listbox-controller.ts index fbea4a4568..f621431529 100644 --- a/core/pfe-core/controllers/listbox-controller.ts +++ b/core/pfe-core/controllers/listbox-controller.ts @@ -53,10 +53,10 @@ export class ListboxController< /** event listeners for host element */ #listeners = { + 'click': this.#onOptionClick.bind(this), + 'focus': this.#onOptionFocus.bind(this), 'keydown': this.#onOptionKeydown.bind(this), 'keyup': this.#onOptionKeyup.bind(this), - 'optionfocus': this.#onOptionFocus.bind(this), - 'click': this.#onOptionClick.bind(this), }; /** @@ -224,18 +224,7 @@ export class ListboxController< * adds event listeners to host */ hostConnected() { - for (const [event, listener] of Object.entries(this.#listeners)) { - this.host?.addEventListener(event, listener as (event: Event | null) => void); - } - } - - /** - * removes event listeners from host - */ - hostDisconnected() { - for (const [event, listener] of Object.entries(this.#listeners)) { - this.host?.removeEventListener(event, listener as (event: Event | null) => void); - } + this.#internals.role = 'listbox'; } /** @@ -264,12 +253,12 @@ export class ListboxController< } this.options.forEach(option => { if (matchedOptions.includes(option)) { - option.removeAttribute('hidden-by-filter'); + option.removeAttribute('filtered'); } else { if (document.activeElement === option) { this.#updateFocus = true; } - option.setAttribute('hidden-by-filter', 'hidden-by-filter'); + option.setAttribute('filtered', 'filtered'); } }); return matchedOptions; @@ -492,11 +481,16 @@ export class ListboxController< * @param oldOptions {ListboxOptionElement[]} */ #optionsChanged(oldOptions: ListboxOptionElement[]) { - const setSize = oldOptions.length; - if (setSize !== this.#options.length || !oldOptions.every((element, index) => element === this.#options[index])) { - oldOptions.forEach((option, posInSet) => { - option.setSize = setSize; - option.posInSet = posInSet; + const setSize = this.#options.length; + if (setSize !== oldOptions.length || !oldOptions.every((element, index) => element === this.#options[index])) { + this.#options.forEach((option, posInSet) => { + if (!oldOptions.includes(option)) { + option.setSize = setSize; + option.posInSet = posInSet; + for (const [event, listener] of Object.entries(this.#listeners)) { + option?.addEventListener(event, listener as (event: Event | null) => void); + } + } }); this.#tabindex.initItems(this.visibleOptions); } diff --git a/core/pfe-core/controllers/toggle-controller.ts b/core/pfe-core/controllers/toggle-controller.ts index be27d7791c..9455368e3e 100644 --- a/core/pfe-core/controllers/toggle-controller.ts +++ b/core/pfe-core/controllers/toggle-controller.ts @@ -323,9 +323,6 @@ export class ToggleController implements ReactiveController { for (const [event, listener] of Object.entries(this.#triggerListeners)) { triggerElement?.addEventListener(event, listener as (event: KeyboardEvent | MouseEvent | Event | null) => void); } - for (const [event, listener] of Object.entries(this.#hostListeners)) { - triggerElement?.addEventListener(event, listener as (event: KeyboardEvent | MouseEvent | Event | null) => void); - } triggerElement?.setAttribute('aria-haspopup', this.#popupType); triggerElement?.setAttribute('aria-controls', this.#popupElement?.id || ''); triggerElement?.setAttribute('aria-expanded', this.expanded ? 'true' : 'false'); @@ -342,9 +339,6 @@ export class ToggleController implements ReactiveController { for (const [event, listener] of Object.entries(this.#triggerListeners)) { triggerElement?.removeEventListener(event, listener as (event: KeyboardEvent | MouseEvent | Event | null) => void); } - for (const [event, listener] of Object.entries(this.#hostListeners)) { - triggerElement?.removeEventListener(event, listener as (event: KeyboardEvent | MouseEvent | Event | null) => void); - } triggerElement?.removeAttribute('aria-haspopup'); triggerElement?.removeAttribute('aria-controls'); triggerElement?.removeAttribute('aria-expanded'); diff --git a/elements/pf-select/demo/multiple-selections.html b/elements/pf-select/demo/multiple-selections.html index a2d22fa2dc..64185bd998 100644 --- a/elements/pf-select/demo/multiple-selections.html +++ b/elements/pf-select/demo/multiple-selections.html @@ -7,7 +7,7 @@ Shift will toggling off multiple items. Ctrl+A will toggle selection on all items.

- + Blue Green Magenta @@ -41,7 +41,7 @@

Display as badge

- + Blue Green Magenta @@ -57,7 +57,7 @@

Display as chips

- + Blue Green Magenta diff --git a/elements/pf-select/demo/typeahead.html b/elements/pf-select/demo/typeahead.html index e175be1dbe..2e78f7c3fb 100644 --- a/elements/pf-select/demo/typeahead.html +++ b/elements/pf-select/demo/typeahead.html @@ -27,7 +27,7 @@

Typeahead example

Typeahead example with chips