Skip to content

Commit c6bda10

Browse files
authored
[SelectPanel] Announce loading prop changes (#6404)
1 parent 3f68aa7 commit c6bda10

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

.changeset/thin-badgers-struggle.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@primer/react": patch
3+
---
4+
5+
SelectPanel announces loading prop changes

packages/react/src/SelectPanel/SelectPanel.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,23 @@ function Panel({
407407
}
408408
}, [inputRef, open])
409409

410+
// Manage loading announcements when loadingManagedExternally
411+
useEffect(() => {
412+
if (loadingManagedExternally) {
413+
if (isLoading) {
414+
// Delay the announcement a bit, just in case the loading is quick
415+
loadingDelayTimeoutId.current = safeSetTimeout(() => {
416+
announceLoading()
417+
}, LONG_DELAY_MS)
418+
} else {
419+
// If loading is done, we can clear the loading announcement
420+
if (loadingDelayTimeoutId.current) {
421+
safeClearTimeout(loadingDelayTimeoutId.current)
422+
}
423+
}
424+
}
425+
}, [isLoading, loadingManagedExternally, safeSetTimeout, safeClearTimeout])
426+
410427
// Populate panel with items on first open
411428
useEffect(() => {
412429
if (loadingManagedExternally) return

0 commit comments

Comments
 (0)