From 2731ae756928e24dd21fd6432a6fa64335a8f85b Mon Sep 17 00:00:00 2001 From: Owen Niblock Date: Tue, 17 Sep 2024 13:54:44 +0100 Subject: [PATCH] Also clear when x button pressed --- .../primer/alpha/select_panel_element.ts | 6 ++-- test/system/alpha/select_panel_test.rb | 36 ++++++++++++++++++- 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/app/components/primer/alpha/select_panel_element.ts b/app/components/primer/alpha/select_panel_element.ts index a8c11ec6c7..a5424760eb 100644 --- a/app/components/primer/alpha/select_panel_element.ts +++ b/app/components/primer/alpha/select_panel_element.ts @@ -165,7 +165,7 @@ export class SelectPanelElement extends HTMLElement { updateAnchorPosition() { // If the selectPanel is removed from the screen on resize close the dialog if (this && this.offsetParent === null) { - this.dialog.close() + this.hide() } if (this.invokerElement) { @@ -464,6 +464,8 @@ export class SelectPanelElement extends HTMLElement { // Remove data-ready so it can be set the next time the panel is opened this.dialog.removeAttribute('data-ready') this.invokerElement?.setAttribute('aria-expanded', 'false') + // When we close the dialog, clear the filter input + this.filterInputTextField.value = '' this.dispatchEvent( new CustomEvent('panelClosed', { @@ -935,8 +937,6 @@ export class SelectPanelElement extends HTMLElement { } hide() { - // When we close the dialog, clear the filter input - this.filterInputTextField.value = '' this.dialog.close() } diff --git a/test/system/alpha/select_panel_test.rb b/test/system/alpha/select_panel_test.rb index 272ce643c7..dec8398360 100644 --- a/test/system/alpha/select_panel_test.rb +++ b/test/system/alpha/select_panel_test.rb @@ -435,7 +435,7 @@ def test_single_selected_item_cannot_be_unchecked refute_selector "[aria-checked]", visible: :hidden end - def test_single_select_clears_input_on_close + def test_single_select_clears_input_on_selection visit_preview(:single_select) click_on_invoker_button @@ -453,6 +453,40 @@ def test_single_select_clears_input_on_close assert_selector "select-panel input", text: "" end + def test_single_select_clears_input_on_enter + visit_preview(:single_select) + + click_on_invoker_button + + filter_results(query: "it") + + keyboard.type(:enter) + + assert_selector "[aria-selected=true]", text: "Item 1", visible: :hidden + + click_on_invoker_button + + # Check that the input value is empty + assert_selector "select-panel input", text: "" + end + + def test_single_select_clears_input_on_close + visit_preview(:single_select) + + click_on_invoker_button + + filter_results(query: "it") + + click_on_x_button + + assert_no_selector "[aria-selected=true]", text: "Item 1", visible: :hidden + + click_on_invoker_button + + # Check that the input value is empty + assert_selector "select-panel input", text: "" + end + def test_single_select_disabled_item_cannot_be_checked visit_preview(:single_select)