-
Notifications
You must be signed in to change notification settings - Fork 646
SelectPanel: Add default empty message to announcement #6346
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
Changes from all commits
be38745
aa3f352
2367c22
995b137
5e43024
b89e853
022bcfb
8f3edce
dd96771
afefece
7a9b42c
0c242ef
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@primer/react': patch | ||
| --- | ||
|
|
||
| SelectPanel: Ensure empty message live region reads from provided or default message |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -43,6 +43,7 @@ export const useAnnouncements = ( | |||||
| inputRef: React.RefObject<HTMLInputElement>, | ||||||
| enabled: boolean = true, | ||||||
| loading: boolean = false, | ||||||
| message?: {title: string; description: string}, | ||||||
| ) => { | ||||||
| const liveRegion = document.querySelector('live-region') | ||||||
|
|
||||||
|
|
@@ -92,7 +93,7 @@ export const useAnnouncements = ( | |||||
| liveRegion?.clear() // clear previous announcements | ||||||
|
|
||||||
| if (items.length === 0 && !loading) { | ||||||
| announce('No matching items.', {delayMs}) | ||||||
| announce(`${message?.title}. ${message?.description}`, {delayMs}) | ||||||
|
||||||
| announce(`${message?.title}. ${message?.description}`, {delayMs}) | |
| announce(message ? `${message.title}. ${message.description}` : 'No matching items.', {delayMs}) |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -30,10 +30,14 @@ import type {ButtonProps, LinkButtonProps} from '../Button/types' | |||||
| // we add a delay so that it does not interrupt default screen reader announcement and queues after it | ||||||
| const SHORT_DELAY_MS = 500 | ||||||
| const LONG_DELAY_MS = 1000 | ||||||
| const EMPTY_MESSAGE = { | ||||||
| title: "You haven't created any items yet", | ||||||
| description: 'Please add or create new items to populate the list.', | ||||||
| } | ||||||
|
|
||||||
| const DefaultEmptyMessage = ( | ||||||
| <SelectPanelMessage variant="empty" title="You haven't created any items yet" key="empty-message"> | ||||||
| Please add or create new items to populate the list. | ||||||
| <SelectPanelMessage variant="empty" title={EMPTY_MESSAGE.title} key="empty-message"> | ||||||
| {EMPTY_MESSAGE.description} | ||||||
| </SelectPanelMessage> | ||||||
| ) | ||||||
|
|
||||||
|
|
@@ -53,7 +57,7 @@ async function announceLoading() { | |||||
| } | ||||||
|
|
||||||
| const announceNoItems = debounce((message?: string) => { | ||||||
| announceText(message ?? 'No matching items.', LONG_DELAY_MS) | ||||||
| announceText(message ?? `${EMPTY_MESSAGE.title}. ${EMPTY_MESSAGE.description}`, LONG_DELAY_MS) | ||||||
| }, 250) | ||||||
|
|
||||||
| interface SelectPanelSingleSelection { | ||||||
|
|
@@ -231,11 +235,11 @@ function Panel({ | |||||
| (node: HTMLElement | null) => { | ||||||
| setListContainerElement(node) | ||||||
| if (!node && needsNoItemsAnnouncement) { | ||||||
| announceNoItems() | ||||||
| if (!usingModernActionList) announceNoItems() | ||||||
| setNeedsNoItemsAnnouncement(false) | ||||||
| } | ||||||
| }, | ||||||
| [needsNoItemsAnnouncement], | ||||||
| [needsNoItemsAnnouncement, usingModernActionList], | ||||||
| ) | ||||||
|
|
||||||
| const onInputRefChanged = useCallback( | ||||||
|
|
@@ -350,7 +354,7 @@ function Panel({ | |||||
| if (open) { | ||||||
| if (items.length === 0 && !(isLoading || loading)) { | ||||||
| // we need to wait for the listContainerElement to disappear before announcing no items, otherwise it will be interrupted | ||||||
| if (!listContainerElement || !usingModernActionList) { | ||||||
| if (!listContainerElement && !usingModernActionList) { | ||||||
| announceNoItems(message?.title) | ||||||
| } else { | ||||||
| setNeedsNoItemsAnnouncement(true) | ||||||
|
|
@@ -821,6 +825,13 @@ function Panel({ | |||||
| // hack because the deprecated ActionList does not support this prop | ||||||
| {...{ | ||||||
| message: getMessage(), | ||||||
| messageText: { | ||||||
| title: message?.title || EMPTY_MESSAGE.title, | ||||||
| description: | ||||||
| typeof message?.body === 'string' | ||||||
| ? message.body | ||||||
| : EMPTY_MESSAGE.description || EMPTY_MESSAGE.description, | ||||||
|
||||||
| : EMPTY_MESSAGE.description || EMPTY_MESSAGE.description, | |
| : message.body || EMPTY_MESSAGE.description, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just so TypeScript doesn't yell. Won't be needed once we remove the FF.