Skip to content

Commit 6b4983e

Browse files
authoredAug 29, 2024··
[SelectPanel] Add checks for existence of filter input (#3038)
1 parent 3fb46ed commit 6b4983e

File tree

5 files changed

+27
-8
lines changed

5 files changed

+27
-8
lines changed
 

‎.changeset/quiet-phones-scream.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@primer/view-components': patch
3+
---
4+
5+
SelectPanel: check for filter input when loading remote items.

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

+6-5
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,7 @@ export class SelectPanelElement extends HTMLElement {
411411
}
412412

413413
#setTextFieldLoadingSpinnerTimer() {
414+
if (!this.#filterInputTextFieldElement) return
414415
if (this.#loadingDelayTimeoutId) clearTimeout(this.#loadingDelayTimeoutId)
415416
if (this.#loadingAnnouncementTimeoutId) clearTimeout(this.#loadingAnnouncementTimeoutId)
416417

@@ -419,7 +420,7 @@ export class SelectPanelElement extends HTMLElement {
419420
}, 2000) as unknown as number
420421

421422
this.#loadingDelayTimeoutId = setTimeout(() => {
422-
this.#filterInputTextFieldElement.showLeadingSpinner()
423+
this.#filterInputTextFieldElement?.showLeadingSpinner()
423424
}, 1000) as unknown as number
424425
}
425426

@@ -547,7 +548,7 @@ export class SelectPanelElement extends HTMLElement {
547548
}
548549

549550
case 'loadend': {
550-
this.#filterInputTextFieldElement.hideLeadingSpinner()
551+
this.#filterInputTextFieldElement?.hideLeadingSpinner()
551552
this.dispatchEvent(new CustomEvent('loadend'))
552553
break
553554
}
@@ -610,7 +611,7 @@ export class SelectPanelElement extends HTMLElement {
610611
}
611612

612613
case 'loadend': {
613-
this.#filterInputTextFieldElement.hideLeadingSpinner()
614+
this.#filterInputTextFieldElement?.hideLeadingSpinner()
614615
if (this.#loadingAnnouncementTimeoutId) clearTimeout(this.#loadingAnnouncementTimeoutId)
615616
if (this.#loadingDelayTimeoutId) clearTimeout(this.#loadingDelayTimeoutId)
616617
this.dispatchEvent(new CustomEvent('loadend'))
@@ -799,8 +800,8 @@ export class SelectPanelElement extends HTMLElement {
799800
}
800801
}
801802

802-
get #filterInputTextFieldElement(): PrimerTextFieldElement {
803-
return this.filterInputTextField.closest('primer-text-field') as PrimerTextFieldElement
803+
get #filterInputTextFieldElement(): PrimerTextFieldElement | null {
804+
return this.filterInputTextField?.closest('primer-text-field') as PrimerTextFieldElement | null
804805
}
805806

806807
#performFilteringLocally(): boolean {

‎previews/primer/alpha/select_panel_preview.rb

+3-2
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,9 @@ def local_fetch(open_on_load: false)
7777
#
7878
# @snapshot interactive
7979
# @param open_on_load toggle
80-
def eventually_local_fetch(open_on_load: false)
81-
render_with_template(locals: { open_on_load: open_on_load })
80+
# @param show_filter toggle
81+
def eventually_local_fetch(open_on_load: false, show_filter: true)
82+
render_with_template(locals: { open_on_load: open_on_load, show_filter: show_filter })
8283
end
8384

8485
# @label Remote fetch

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
src: select_panel_items_path,
66
select_variant: :multiple,
77
fetch_strategy: :eventually_local,
8-
open_on_load: open_on_load
8+
open_on_load: open_on_load,
9+
show_filter: show_filter,
910
)) do |panel| %>
1011
<% panel.with_show_button { "Sci-fi equipment" } %>
1112
<% panel.with_footer(show_divider: true) do %>

‎test/system/alpha/select_panel_test.rb

+11
Original file line numberDiff line numberDiff line change
@@ -877,6 +877,17 @@ def test_ev_loc_initial_failure
877877
refute_selector "[data-target='select-panel.bannerErrorElement']"
878878
end
879879

880+
def test_ev_loc_items_load_without_filter
881+
visit_preview(:eventually_local_fetch, show_filter: false)
882+
883+
wait_for_items_to_load do
884+
click_on_invoker_button
885+
end
886+
887+
# items should render without error
888+
assert_selector "select-panel ul li"
889+
end
890+
880891
########## REMOTE TESTS ############
881892

882893
def test_remote_items_load

0 commit comments

Comments
 (0)
Please sign in to comment.