diff --git a/src/components/picker/picker.tsx b/src/components/picker/picker.tsx index 1efed84817..9d9131fa9c 100644 --- a/src/components/picker/picker.tsx +++ b/src/components/picker/picker.tsx @@ -547,9 +547,40 @@ export class Picker { return; } + // Don't clear if a chip's menu is open - focus moved to the menu's portal + if (this.hasOpenChipMenu()) { + return; + } + this.clearInputField(); } + private hasOpenChipMenu(): boolean { + if (!this.chipSet) { + return false; + } + + // Query for any open menus inside the chips + const chips = this.chipSet.shadowRoot?.querySelectorAll('limel-chip'); + if (!chips) { + return false; + } + + for (const chip of chips) { + // Check the `open` property directly rather than using an attribute + // selector, because Stencil batches attribute reflection and + // the [open] attribute may not be on the DOM yet + const menu = chip.shadowRoot?.querySelector( + 'limel-menu' + ) as HTMLLimelMenuElement; + if (menu?.open) { + return true; + } + } + + return false; + } + /** * Input handler for the input field *