Skip to content
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

Allow user to override Button and IconButton aria-disabled #4426

Merged
merged 3 commits into from
Mar 22, 2024
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
5 changes: 5 additions & 0 deletions .changeset/smart-cameras-sip.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@primer/react': patch
---

Fixes a bug where consumers cannot override buttons' aria-disabled attribute
2 changes: 1 addition & 1 deletion packages/react/src/Button/ButtonBase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,14 @@ const ButtonBase = forwardRef(
<StyledButton
as={Component}
sx={sxStyles}
aria-disabled={loading ? true : undefined}
{...rest}
ref={innerRef}
data-block={block ? 'block' : null}
data-inactive={inactive ? true : undefined}
data-loading={Boolean(loading)}
data-no-visuals={!LeadingVisual && !TrailingVisual && !TrailingAction ? true : undefined}
data-size={size === 'small' || size === 'large' ? size : undefined}
aria-disabled={loading ? true : undefined}
aria-describedby={[loadingAnnouncementID, ariaDescribedBy]
.filter(descriptionID => Boolean(descriptionID))
.join(' ')}
Expand Down
6 changes: 6 additions & 0 deletions packages/react/src/Button/__tests__/Button.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,12 @@ describe('Button', () => {
}, 0)
})

it('allows the consumer to override `aria-disabled`', () => {
const container = render(<Button aria-disabled>content</Button>)

expect(container.getByRole('button')).toHaveAttribute('aria-disabled', 'true')
})

it('should preserve the accessible button name when the button is in a loading state', () => {
const container = render(<Button loading>content</Button>)

Expand Down
Loading