Skip to content

Commit 369c303

Browse files
authored
Allow user to override Button and IconButton aria-disabled (#4426)
* Allow user to override button `aria-disabled` * Add test * Add changeset
1 parent 3ec6309 commit 369c303

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

.changeset/smart-cameras-sip.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@primer/react': patch
3+
---
4+
5+
Fixes a bug where consumers cannot override buttons' aria-disabled attribute

packages/react/src/Button/ButtonBase.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,14 @@ const ButtonBase = forwardRef(
8989
<StyledButton
9090
as={Component}
9191
sx={sxStyles}
92+
aria-disabled={loading ? true : undefined}
9293
{...rest}
9394
ref={innerRef}
9495
data-block={block ? 'block' : null}
9596
data-inactive={inactive ? true : undefined}
9697
data-loading={Boolean(loading)}
9798
data-no-visuals={!LeadingVisual && !TrailingVisual && !TrailingAction ? true : undefined}
9899
data-size={size === 'small' || size === 'large' ? size : undefined}
99-
aria-disabled={loading ? true : undefined}
100100
aria-describedby={[loadingAnnouncementID, ariaDescribedBy]
101101
.filter(descriptionID => Boolean(descriptionID))
102102
.join(' ')}

packages/react/src/Button/__tests__/Button.test.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,12 @@ describe('Button', () => {
238238
}, 0)
239239
})
240240

241+
it('allows the consumer to override `aria-disabled`', () => {
242+
const container = render(<Button aria-disabled>content</Button>)
243+
244+
expect(container.getByRole('button')).toHaveAttribute('aria-disabled', 'true')
245+
})
246+
241247
it('should preserve the accessible button name when the button is in a loading state', () => {
242248
const container = render(<Button loading>content</Button>)
243249

0 commit comments

Comments
 (0)