Skip to content

Commit

Permalink
Also clear when x button pressed
Browse files Browse the repository at this point in the history
  • Loading branch information
owenniblock committed Sep 17, 2024
1 parent 881adb0 commit 2731ae7
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
6 changes: 3 additions & 3 deletions app/components/primer/alpha/select_panel_element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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', {
Expand Down Expand Up @@ -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()
}

Expand Down
36 changes: 35 additions & 1 deletion test/system/alpha/select_panel_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

Expand Down

0 comments on commit 2731ae7

Please sign in to comment.