Skip to content

Commit

Permalink
Use same timeout for loading spinner + announcement; add loading anno…
Browse files Browse the repository at this point in the history
…uncement on open
  • Loading branch information
camertron committed Dec 9, 2024
1 parent be3fdf9 commit 16d1847
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Procfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
vite: cd demo; script/start-vite
css: cd demo; script/start-css
web: cd demo; bin/rails s -p 4000
web: cd demo; bin/rails s -p 4000 -b 0.0.0.0
21 changes: 13 additions & 8 deletions app/components/primer/alpha/select_panel_element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ export class SelectPanelElement extends HTMLElement {
#inputName = ''
#selectedItems: Map<string, SelectedItem> = new Map()
#loadingDelayTimeoutId: number | null = null
#loadingAnnouncementTimeoutId: number | null = null
#hasLoadedData = false

get open(): boolean {
Expand Down Expand Up @@ -400,14 +399,18 @@ export class SelectPanelElement extends HTMLElement {
#setTextFieldLoadingSpinnerTimer() {
if (!this.#filterInputTextFieldElement) return
if (this.#loadingDelayTimeoutId) clearTimeout(this.#loadingDelayTimeoutId)
if (this.#loadingAnnouncementTimeoutId) clearTimeout(this.#loadingAnnouncementTimeoutId)

this.#loadingAnnouncementTimeoutId = setTimeout(() => {
this.#loadingDelayTimeoutId = setTimeout(() => {
this.#filterInputTextFieldElement?.showLeadingSpinner()
this.liveRegion.announce('Loading')
}, 2000) as unknown as number
}, 1000) as unknown as number
}

#setBodyLoadingTimer() {
if (this.#loadingDelayTimeoutId) clearTimeout(this.#loadingDelayTimeoutId)

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

Expand Down Expand Up @@ -599,16 +602,18 @@ export class SelectPanelElement extends HTMLElement {
this.#clearErrorState()
this.bodySpinner?.removeAttribute('hidden')

if (this.bodySpinner) break
this.#setTextFieldLoadingSpinnerTimer()
if (this.bodySpinner) {
this.#setBodyLoadingTimer()
} else {
this.#setTextFieldLoadingSpinnerTimer()
}
}

break
}

case 'loadend': {
this.#filterInputTextFieldElement?.hideLeadingSpinner()
if (this.#loadingAnnouncementTimeoutId) clearTimeout(this.#loadingAnnouncementTimeoutId)
if (this.#loadingDelayTimeoutId) clearTimeout(this.#loadingDelayTimeoutId)
this.dispatchEvent(new CustomEvent('loadend'))
break
Expand Down

0 comments on commit 16d1847

Please sign in to comment.