diff --git a/.changeset/silent-wasps-peel.md b/.changeset/silent-wasps-peel.md new file mode 100644 index 0000000000..ae576fb25a --- /dev/null +++ b/.changeset/silent-wasps-peel.md @@ -0,0 +1,5 @@ +--- +'@primer/view-components': patch +--- + +[SelectPanel] Don't clear selection if input field doesn't exist diff --git a/app/components/primer/alpha/select_panel_element.ts b/app/components/primer/alpha/select_panel_element.ts index 23f6d3e44f..f390b1cf41 100644 --- a/app/components/primer/alpha/select_panel_element.ts +++ b/app/components/primer/alpha/select_panel_element.ts @@ -465,10 +465,13 @@ export class SelectPanelElement extends HTMLElement { this.dialog.removeAttribute('data-ready') this.invokerElement?.setAttribute('aria-expanded', 'false') // When we close the dialog, clear the filter input - const fireSearchEvent = this.filterInputTextField.value.length > 0 - this.filterInputTextField.value = '' - if (fireSearchEvent) { - this.filterInputTextField.dispatchEvent(new Event('input')) + + if (this.filterInputTextField) { + const fireSearchEvent = this.filterInputTextField.value.length > 0 + this.filterInputTextField.value = '' + if (fireSearchEvent) { + this.filterInputTextField.dispatchEvent(new Event('input')) + } } this.dispatchEvent(