Skip to content

Commit 82c2b0a

Browse files
authoredOct 28, 2024··
[SelectPanel] Fix issue causing no error banner to appear when there are no matches (#3168)
1 parent 400943b commit 82c2b0a

File tree

5 files changed

+32
-4
lines changed

5 files changed

+32
-4
lines changed
 

‎.changeset/quiet-fans-repeat.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@primer/view-components': patch
3+
---
4+
5+
[SelectPanel] Fix issue causing no error banner to appear when there are no matches

‎app/components/primer/alpha/select_panel_element.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -752,8 +752,8 @@ export class SelectPanelElement extends HTMLElement {
752752
#setErrorState(type: ErrorStateType) {
753753
let errorElement = this.fragmentErrorElement
754754

755-
if (type === ErrorStateType.BODY) {
756-
this.fragmentErrorElement?.removeAttribute('hidden')
755+
if (type === ErrorStateType.BODY && this.fragmentErrorElement) {
756+
this.fragmentErrorElement.removeAttribute('hidden')
757757
this.bannerErrorElement.setAttribute('hidden', '')
758758
} else {
759759
errorElement = this.bannerErrorElement

‎previews/primer/alpha/select_panel_preview.rb

+4-1
Original file line numberDiff line numberDiff line change
@@ -227,12 +227,15 @@ def remote_fetch_initial_failure(open_on_load: false)
227227
# @snapshot interactive
228228
# @param open_on_load toggle
229229
# @param banner_scheme [Symbol] select [danger, warning]
230+
# @param show_results toggle
230231
def remote_fetch_filter_failure(
231232
open_on_load: false,
232-
banner_scheme: :danger
233+
banner_scheme: :danger,
234+
show_results: true
233235
)
234236
render_with_template(locals: {
235237
open_on_load: open_on_load,
238+
show_results: show_results,
236239
system_arguments: {
237240
# .to_sym workaround for https://github.com/lookbook-hq/lookbook/issues/640
238241
banner_scheme: banner_scheme.to_sym

‎previews/primer/alpha/select_panel_preview/remote_fetch_filter_failure.html.erb

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
<%= render(Primer::Alpha::SelectPanel.new(
44
data: { interaction_subject: subject_id },
55
# passing a uuid here causes the request to succeed the first time and fail all subsequent times
6-
src: select_panel_items_path(fail: "true", uuid: SecureRandom.uuid),
6+
# set show_results to false to simulate an initial load with no items
7+
src: select_panel_items_path(show_results: show_results.to_s, fail: "true", uuid: SecureRandom.uuid),
78
fetch_strategy: :remote,
89
open_on_load: open_on_load,
910
**system_arguments

‎test/system/alpha/select_panel_test.rb

+19
Original file line numberDiff line numberDiff line change
@@ -1046,6 +1046,25 @@ def test_remote_filter_failure
10461046
refute_selector "[data-target='select-panel.fragmentErrorElement']"
10471047
end
10481048

1049+
def test_no_results_filter_failure
1050+
visit_preview(:remote_fetch_filter_failure, show_results: false)
1051+
1052+
wait_for_items_to_load do
1053+
click_on_invoker_button
1054+
end
1055+
1056+
# no items on initial load
1057+
assert_selector "select-panel", text: "No results found"
1058+
1059+
wait_for_items_to_load do
1060+
filter_results(query: "foobar")
1061+
end
1062+
1063+
# only the banner-based error message should appear
1064+
assert_selector "[data-target='select-panel.bannerErrorElement']", text: "Sorry, something went wrong"
1065+
refute_selector "[data-target='select-panel.fragmentErrorElement']"
1066+
end
1067+
10491068
def test_remote_fetch_clears_input_on_close
10501069
visit_preview(:remote_fetch)
10511070

0 commit comments

Comments
 (0)
Please sign in to comment.