Skip to content

Commit

Permalink
Docs(ActionList): use internal AriaStatus to announce updates in exam…
Browse files Browse the repository at this point in the history
…ple story (#5096)

* Docs(ActionList): use internal LiveRegion to announce updates

* Docs(ActionList): use AriaStatus to announce status instead of LiveRegion, async story

* Update packages/react/src/ActionList/ActionList.examples.stories.tsx

Co-authored-by: Josh Black <joshblack@github.com>

* docs(ActionList): format

---------

Co-authored-by: Josh Black <joshblack@github.com>
  • Loading branch information
francinelucca and joshblack authored Oct 10, 2024
1 parent 0083642 commit 799ead8
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions packages/react/src/ActionList/ActionList.examples.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ import TextInput from '../TextInput'
import Spinner from '../Spinner'
import Box from '../Box'
import Text from '../Text'
import VisuallyHidden from '../_VisuallyHidden'
import FormControl from '../FormControl'
import {AriaStatus} from '../live-region'
import {VisuallyHidden} from '../VisuallyHidden'

const meta: Meta = {
title: 'Components/ActionList/Examples',
Expand Down Expand Up @@ -177,15 +178,24 @@ export function AsyncListWithSpinner(): JSX.Element {
const [results, setResults] = React.useState(branches.slice(0, 6))
const [loading, setLoading] = React.useState(false)
const [selected, setSelected] = React.useState('main')
const [filterVal, setFilterVal] = React.useState('')

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const filter = async (event: any) => {
setLoading(true)
const filteredResults = await filterSlowly(event.target.value)
setResults(filteredResults.slice(0, 6))
setFilterVal(event.target.value)
setLoading(false)
}

const getStatusMessage = () => {
if (loading) return 'Loading results'
if (!filterVal) return 'Showing top 6 branches'
if (results.length === 0) return 'No branches match that query'
return `Branches filtered, showing ${results.length} branches`
}

return (
<>
<h1>Async List</h1>
Expand All @@ -198,13 +208,13 @@ export function AsyncListWithSpinner(): JSX.Element {
<FormControl.Label>Search branches</FormControl.Label>
<TextInput onChange={filter} block />
</FormControl>
<div role="status">
{results.length === 0 ? (
<Text sx={{display: 'block', fontSize: 1, m: 2}}>No branches match that query</Text>
) : (
<VisuallyHidden>{results.length} branches match that query</VisuallyHidden>
)}
</div>
{results.length === 0 ? (
<Text sx={{display: 'block', fontSize: 1, m: 2}}>No branches match that query</Text>
) : null}

<VisuallyHidden>
<AriaStatus>{getStatusMessage()}</AriaStatus>
</VisuallyHidden>

<ActionList selectionVariant="single" role="listbox" aria-label="Branch" sx={{height: 208, overflow: 'auto'}}>
{loading ? (
Expand Down

0 comments on commit 799ead8

Please sign in to comment.