Skip to content

Commit c4bf4af

Browse files
authored
allow DOM pass-through of aria-disabled on Button (adobe#8756)
1 parent 6b56454 commit c4bf4af

File tree

4 files changed

+23
-1
lines changed

4 files changed

+23
-1
lines changed

packages/@react-aria/button/src/useButton.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ export function useButton(props: AriaButtonOptions<ElementType>, ref: RefObject<
114114
'aria-expanded': props['aria-expanded'],
115115
'aria-controls': props['aria-controls'],
116116
'aria-pressed': props['aria-pressed'],
117-
'aria-current': props['aria-current']
117+
'aria-current': props['aria-current'],
118+
'aria-disabled': props['aria-disabled']
118119
})
119120
};
120121
}

packages/@react-aria/button/test/useButton.test.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,11 @@ describe('useButton tests', function () {
6161
expect(typeof result.current.buttonProps.onKeyDown).toBe('function');
6262
expect(result.current.buttonProps.rel).toBeUndefined();
6363
});
64+
65+
it('handles aria-disabled passthrough for button elements', function () {
66+
let props = {'aria-disabled': 'true'};
67+
let {result} = renderHook(() => useButton(props));
68+
expect(result.current.buttonProps['aria-disabled']).toBeTruthy();
69+
expect(result.current.buttonProps['disabled']).toBeUndefined();
70+
});
6471
});

packages/@react-types/button/src/index.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ export interface LinkButtonProps<T extends ElementType = 'button'> extends AriaB
4747
}
4848

4949
interface AriaBaseButtonProps extends FocusableDOMProps, AriaLabelingProps {
50+
/** Indicates whether the element is disabled to users of assistive technology. */
51+
'aria-disabled'?: boolean | 'true' | 'false',
5052
/** Indicates whether the element, or another grouping element it controls, is currently expanded or collapsed. */
5153
'aria-expanded'?: boolean | 'true' | 'false',
5254
/** Indicates the availability and type of interactive popup element, such as menu or dialog, that can be triggered by an element. */

packages/react-aria-components/test/Button.test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,18 @@ describe('Button', () => {
5757
expect(button).toHaveAttribute('aria-current', 'page');
5858
});
5959

60+
it('should not have aria-disabled defined by default', () => {
61+
let {getByRole} = render(<Button>Test</Button>);
62+
let button = getByRole('button');
63+
expect(button).not.toHaveAttribute('aria-disabled');
64+
});
65+
66+
it('should support aria-disabled passthrough', () => {
67+
let {getByRole} = render(<Button aria-disabled="true">Test</Button>);
68+
let button = getByRole('button');
69+
expect(button).toHaveAttribute('aria-disabled', 'true');
70+
});
71+
6072
it('should support slot', () => {
6173
let {getByRole} = render(
6274
<ButtonContext.Provider value={{slots: {test: {'aria-label': 'test'}}}}>

0 commit comments

Comments
 (0)