Skip to content

Commit

Permalink
feat(Button): add support for aria-current prop (#7643)
Browse files Browse the repository at this point in the history
  • Loading branch information
TimonVS authored Jan 22, 2025
1 parent 9bb6ed9 commit 7b7b461
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/@react-aria/button/src/useButton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ export function useButton(props: AriaButtonOptions<ElementType>, ref: RefObject<
'aria-expanded': props['aria-expanded'],
'aria-controls': props['aria-controls'],
'aria-pressed': props['aria-pressed'],
'aria-current': props['aria-current'],
onClick: (e) => {
if (deprecatedOnClick) {
deprecatedOnClick(e);
Expand Down
2 changes: 2 additions & 0 deletions packages/@react-types/button/src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ interface AriaBaseButtonProps extends FocusableDOMProps, AriaLabelingProps {
'aria-controls'?: string,
/** Indicates the current "pressed" state of toggle buttons. */
'aria-pressed'?: boolean | 'true' | 'false' | 'mixed',
/** Indicates whether this element represents the current item within a container or set of related elements. */
'aria-current'?: boolean | 'true' | 'false' | 'page' | 'step' | 'location' | 'date' | 'time',
/**
* The behavior of the button when used in an HTML form.
* @default 'button'
Expand Down
6 changes: 6 additions & 0 deletions packages/react-aria-components/test/Button.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ describe('Button', () => {
expect(button).toHaveAttribute('formMethod', 'post');
});

it('should support accessibility props', () => {
let {getByRole} = render(<Button aria-current="page">Test</Button>);
let button = getByRole('button');
expect(button).toHaveAttribute('aria-current', 'page');
});

it('should support slot', () => {
let {getByRole} = render(
<ButtonContext.Provider value={{slots: {test: {'aria-label': 'test'}}}}>
Expand Down

1 comment on commit 7b7b461

@rspbot
Copy link

@rspbot rspbot commented on 7b7b461 Jan 22, 2025

Choose a reason for hiding this comment

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

Please sign in to comment.