Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SelectPanel] Add checks for existence of filter input #3038

Merged
merged 3 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/quiet-phones-scream.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@primer/view-components': patch
---

SelectPanel: check for filter input when loading remote items.
11 changes: 6 additions & 5 deletions app/components/primer/alpha/select_panel_element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,7 @@ export class SelectPanelElement extends HTMLElement {
}

#setTextFieldLoadingSpinnerTimer() {
if (!this.#filterInputTextFieldElement) return
if (this.#loadingDelayTimeoutId) clearTimeout(this.#loadingDelayTimeoutId)
if (this.#loadingAnnouncementTimeoutId) clearTimeout(this.#loadingAnnouncementTimeoutId)

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

this.#loadingDelayTimeoutId = setTimeout(() => {
this.#filterInputTextFieldElement.showLeadingSpinner()
this.#filterInputTextFieldElement?.showLeadingSpinner()
}, 1000) as unknown as number
}

Expand Down Expand Up @@ -547,7 +548,7 @@ export class SelectPanelElement extends HTMLElement {
}

case 'loadend': {
this.#filterInputTextFieldElement.hideLeadingSpinner()
this.#filterInputTextFieldElement?.hideLeadingSpinner()
this.dispatchEvent(new CustomEvent('loadend'))
break
}
Expand Down Expand Up @@ -610,7 +611,7 @@ export class SelectPanelElement extends HTMLElement {
}

case 'loadend': {
this.#filterInputTextFieldElement.hideLeadingSpinner()
this.#filterInputTextFieldElement?.hideLeadingSpinner()
if (this.#loadingAnnouncementTimeoutId) clearTimeout(this.#loadingAnnouncementTimeoutId)
if (this.#loadingDelayTimeoutId) clearTimeout(this.#loadingDelayTimeoutId)
this.dispatchEvent(new CustomEvent('loadend'))
Expand Down Expand Up @@ -799,8 +800,8 @@ export class SelectPanelElement extends HTMLElement {
}
}

get #filterInputTextFieldElement(): PrimerTextFieldElement {
return this.filterInputTextField.closest('primer-text-field') as PrimerTextFieldElement
get #filterInputTextFieldElement(): PrimerTextFieldElement | null {
return this.filterInputTextField?.closest('primer-text-field') as PrimerTextFieldElement | null
}

#performFilteringLocally(): boolean {
Expand Down
5 changes: 3 additions & 2 deletions previews/primer/alpha/select_panel_preview.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,9 @@ def local_fetch(open_on_load: false)
#
# @snapshot interactive
# @param open_on_load toggle
def eventually_local_fetch(open_on_load: false)
render_with_template(locals: { open_on_load: open_on_load })
# @param show_filter toggle
def eventually_local_fetch(open_on_load: false, show_filter: true)
render_with_template(locals: { open_on_load: open_on_load, show_filter: show_filter })
end

# @label Remote fetch
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
src: select_panel_items_path,
select_variant: :multiple,
fetch_strategy: :eventually_local,
open_on_load: open_on_load
open_on_load: open_on_load,
show_filter: show_filter,
)) do |panel| %>
<% panel.with_show_button { "Sci-fi equipment" } %>
<% panel.with_footer(show_divider: true) do %>
Expand Down
11 changes: 11 additions & 0 deletions test/system/alpha/select_panel_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -877,6 +877,17 @@ def test_ev_loc_initial_failure
refute_selector "[data-target='select-panel.bannerErrorElement']"
end

def test_ev_loc_items_load_without_filter
visit_preview(:eventually_local_fetch, show_filter: false)

wait_for_items_to_load do
click_on_invoker_button
end

# items should render without error
assert_selector "select-panel ul li"
end

########## REMOTE TESTS ############

def test_remote_items_load
Expand Down
Loading