Skip to content

Commit eedc6b1

Browse files
authored
refactor(live-region): update live region helpers to match ADR (#4673)
* refactor(live-region): update live region helpers to match ADR * fix: update file paths from moving to live-region folder * feat(live-region): add support for delayMs to announce * feat: add support for delayMs to Announce, AriaStatus, AriaAlert * chore: add changeset * docs: update stories * chore: fix eslint violations * docs: update jsdoc for hook * fix: update signature to include support for "as" * chore: add support for sx to components --------- Co-authored-by: Josh Black <joshblack@users.noreply.github.com>
1 parent 93f2ac0 commit eedc6b1

25 files changed

+615
-188
lines changed

.changeset/five-humans-retire.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@primer/react': minor
3+
---
4+
5+
Add experimental support for the AriaStatus, AriaAlert, and Announce components

packages/react/src/Banner/Banner.examples.stories.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ import {Banner} from '../Banner'
22
import {action} from '@storybook/addon-actions'
33
import Link from '../Link'
44
import type {Meta} from '@storybook/react'
5-
import {Status} from '../internal/components/Status'
6-
import {Alert} from '../internal/components/Alert'
5+
import {AriaAlert, AriaStatus} from '../live-region'
76
import FormControl from '../FormControl'
87
import RadioGroup from '../RadioGroup'
98
import Radio from '../Radio'
@@ -30,7 +29,7 @@ export const WithUserAction = () => {
3029
<Banner
3130
ref={bannerRef}
3231
title="Error"
33-
description={<Alert>Something went wrong. Please try again later.</Alert>}
32+
description={<AriaAlert>Something went wrong. Please try again later.</AriaAlert>}
3433
variant="critical"
3534
/>
3635
) : null}
@@ -60,7 +59,7 @@ export const WithDynamicContent = () => {
6059
<>
6160
<Banner
6261
title="Info"
63-
description={<Status>{messages.get(selected)}</Status>}
62+
description={<AriaStatus>{messages.get(selected)}</AriaStatus>}
6463
onDismiss={action('onDismiss')}
6564
primaryAction={<Banner.PrimaryAction>Button</Banner.PrimaryAction>}
6665
secondaryAction={<Banner.SecondaryAction>Button</Banner.SecondaryAction>}

packages/react/src/Spinner/Spinner.examples.stories.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type {Meta} from '@storybook/react'
33
import Spinner from './Spinner'
44
import {Box, Button} from '..'
55
import {VisuallyHidden} from '../internal/components/VisuallyHidden'
6-
import {Status} from '../internal/components/Status'
6+
import {AriaStatus} from '../live-region'
77

88
export default {
99
title: 'Components/Spinner/Examples',
@@ -47,7 +47,7 @@ export const FullLifecycle = () => {
4747
{state === 'loading' && <Spinner />}
4848
<p>{loadedContent}</p>
4949
<VisuallyHidden>
50-
<Status>{state === 'done' && 'Content finished loading'}</Status>
50+
<AriaStatus>{state === 'done' && 'Content finished loading'}</AriaStatus>
5151
</VisuallyHidden>
5252
</>
5353
)
@@ -84,12 +84,12 @@ export const FullLifecycleVisibleLoadingText = () => {
8484
{state !== 'done' && (
8585
<Box sx={{alignItems: 'center', display: 'flex', gap: '0.25rem'}}>
8686
{state === 'loading' && <Spinner size="small" srText={null} />}
87-
<Status>{state === 'loading' ? 'Content is loading...' : ''}</Status>
87+
<AriaStatus>{state === 'loading' ? 'Content is loading...' : ''}</AriaStatus>
8888
</Box>
8989
)}
9090
<p>{loadedContent}</p>
9191
<VisuallyHidden>
92-
<Status>{state === 'done' && 'Content finished loading'}</Status>
92+
<AriaStatus>{state === 'done' && 'Content finished loading'}</AriaStatus>
9393
</VisuallyHidden>
9494
</Box>
9595
)

packages/react/src/Spinner/Spinner.features.stories.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from 'react'
22
import type {Meta} from '@storybook/react'
33
import Spinner from './Spinner'
44
import {Box} from '..'
5-
import {Status} from '../internal/components/Status'
5+
import {AriaStatus} from '../live-region'
66

77
export default {
88
title: 'Components/Spinner/Features',
@@ -16,6 +16,6 @@ export const Large = () => <Spinner size="large" />
1616
export const SuppressScreenReaderText = () => (
1717
<Box sx={{alignItems: 'center', display: 'flex', gap: '0.25rem'}}>
1818
<Spinner size="small" srText={null} />
19-
<Status>Loading...</Status>
19+
<AriaStatus>Loading...</AriaStatus>
2020
</Box>
2121
)

packages/react/src/__tests__/__snapshots__/exports.test.ts.snap

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,12 @@ exports[`@primer/react/drafts should not update exports without a semver change
242242
[
243243
"ActionBar",
244244
"type ActionBarProps",
245+
"Announce",
246+
"type AnnounceProps",
247+
"AriaAlert",
248+
"type AriaAlertProps",
249+
"AriaStatus",
250+
"type AriaStatusProps",
245251
"Banner",
246252
"type BannerProps",
247253
"Blankslate",
@@ -347,6 +353,12 @@ exports[`@primer/react/experimental should not update exports without a semver c
347353
[
348354
"ActionBar",
349355
"type ActionBarProps",
356+
"Announce",
357+
"type AnnounceProps",
358+
"AriaAlert",
359+
"type AriaAlertProps",
360+
"AriaStatus",
361+
"type AriaStatusProps",
350362
"Banner",
351363
"type BannerProps",
352364
"Blankslate",

packages/react/src/drafts/SelectPanel2/SelectPanel.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import type {OverlayProps} from '../../Overlay/Overlay'
2323
import {StyledOverlay, heightMap} from '../../Overlay/Overlay'
2424
import InputLabel from '../../internal/components/InputLabel'
2525
import {invariant} from '../../utils/invariant'
26-
import {Status} from '../../internal/components/Status'
26+
import {AriaStatus} from '../../live-region'
2727
import {useResponsiveValue} from '../../hooks/useResponsiveValue'
2828
import type {ResponsiveValue} from '../../hooks/useResponsiveValue'
2929

@@ -604,7 +604,8 @@ const SelectPanelSecondaryAction: React.FC<SelectPanelSecondaryActionProps> = ({
604604

605605
const SelectPanelLoading = ({children = 'Fetching items...'}: React.PropsWithChildren) => {
606606
return (
607-
<Status
607+
<AriaStatus
608+
announceOnShow
608609
sx={{
609610
display: 'flex',
610611
flexDirection: 'column',
@@ -618,7 +619,7 @@ const SelectPanelLoading = ({children = 'Fetching items...'}: React.PropsWithChi
618619
>
619620
<Spinner size="medium" srText={null} />
620621
<Text sx={{fontSize: 1, color: 'fg.muted'}}>{children}</Text>
621-
</Status>
622+
</AriaStatus>
622623
)
623624
}
624625

packages/react/src/drafts/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ export * from '../ActionBar'
7575
export {Stack} from '../Stack'
7676
export type {StackProps, StackItemProps} from '../Stack'
7777

78+
export {Announce, AriaStatus, AriaAlert} from '../live-region'
79+
export type {AnnounceProps, AriaStatusProps, AriaAlertProps} from '../live-region'
80+
7881
export * from './UnderlinePanels'
7982

8083
export {SkeletonBox, SkeletonText, SkeletonAvatar} from './Skeleton'

packages/react/src/internal/components/Alert.tsx

Lines changed: 0 additions & 12 deletions
This file was deleted.

packages/react/src/internal/components/Announce.tsx

Lines changed: 0 additions & 71 deletions
This file was deleted.

packages/react/src/internal/components/Status.tsx

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)