Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
97 changes: 68 additions & 29 deletions packages/react/src/Button/Button.features.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import {EyeIcon, TriangleDownIcon, HeartIcon} from '@primer/octicons-react'
import React, {useState} from 'react'
import {Button} from '.'
import {announce} from '@primer/live-region-element'
import Link from '../Link'

export default {
title: 'Components/Button/Features',
Expand All @@ -16,44 +18,81 @@ export const LeadingVisual = () => <Button leadingVisual={HeartIcon}>Leading vis

export const TrailingVisual = () => <Button trailingVisual={EyeIcon}>Trailing visual</Button>

const AccessibilityNote = () => {
{
return (
<>
<p>
<b>Accessibility note</b>: If a button is dynamically updated to communicate a change (e.g. an action was
successful), please make sure that this is also properly communicated to screen reader users. This may not
happen reliably without additional markup considerations. Make sure to choose an approach that is appropriate
for your usecase.
</p>
<p>
Learn more about at{' '}
<Link href="https://github.com/github/accessibility/blob/8b300b36d8bca28fd5e3e70ffa077a6f8ee65c05/docs/wiki/screen-reader-testing/dynamically-updated-buttons-support-april-2024.md">
Staff-only: Dynamically updated button labels
</Link>
.
</p>
</>
)
}
}
export const TrailingCounter = () => {
const [count, setCount] = useState(0)
const onClick = () => {
setCount(count + 1)
announce(`Watch ${count + 1}`)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @joshblack! I decided to update the approaches in these examples to use a live region, based on the conclusion I came to that the aria-live hack shouldn't be used, unless it's already being considered for other reasons.

I am thinking the next steps for me after this PR are:

  • a dedicated storybook page that dives into different approaches for communicating button state.
  • adding a section to the interface guidelines.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah okay, sounds good @khiga8 👍

}
return (
<Button onClick={() => setCount(count + 1)} count={count}>
Watch
</Button>
<>
<Button onClick={onClick} count={count}>
Watch
</Button>
<AccessibilityNote />
<p>In this example, a live region has been implemented to communicate the change.</p>
</>
)
}

export const TrailingCounterAllVariants = () => {
const [count, setCount] = useState(0)
const onClick = () => {
setCount(count + 1)
announce(`Watch ${count + 1}`)
}
return (
<div style={{display: 'flex', flexDirection: 'row', gap: '1rem'}}>
<Button onClick={() => setCount(count + 1)} count={count}>
Watch
</Button>
<Button disabled onClick={() => setCount(count + 1)} count={count}>
Watch
</Button>
<Button variant="primary" onClick={() => setCount(count + 1)} count={count}>
Watch
</Button>
<Button variant="primary" disabled onClick={() => setCount(count + 1)} count={count}>
Watch
</Button>
<Button variant="danger" onClick={() => setCount(count + 1)} count={count}>
Watch
</Button>
<Button variant="danger" disabled onClick={() => setCount(count + 1)} count={count}>
Watch
</Button>
<Button variant="invisible" onClick={() => setCount(count + 1)} count={count}>
Watch
</Button>
<Button variant="invisible" disabled onClick={() => setCount(count + 1)} count={count}>
Watch
</Button>
</div>
<>
<div style={{display: 'flex', flexDirection: 'row', gap: '1rem'}}>
<Button onClick={onClick} count={count}>
Watch
</Button>
<Button onClick={onClick} count={count}>
Watch
</Button>
<Button onClick={onClick} count={count}>
Watch
</Button>
<Button onClick={onClick} variant="primary" disabled count={count}>
Watch
</Button>
<Button onClick={onClick} variant="danger" count={count}>
Watch
</Button>
<Button onClick={onClick} variant="danger" disabled count={count}>
Watch
</Button>
<Button onClick={onClick} variant="invisible" count={count}>
Watch
</Button>
<Button onClick={onClick} variant="invisible" disabled count={count}>
Watch
</Button>
</div>
<AccessibilityNote />
<p>In these examples, a live region has been implemented to communicate the change.</p>
</>
)
}

Expand Down