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
6 changes: 6 additions & 0 deletions src/components/Button/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ export type Props = Omit<ViewProps, 'style'> & {
* Accessibility label for the button. This is read by the screen reader when the user taps the button.
*/
'aria-label'?: string;
/**
* Indicates whether the element's controlled content is expanded.
*/
'aria-expanded'?: boolean;
/**
* Accessibility hint for the button. This is read by the screen reader when the user taps the button.
*/
Expand Down Expand Up @@ -171,6 +175,7 @@ const Button = ({
textColor: customTextColor,
children,
'aria-label': ariaLabel,
'aria-expanded': ariaExpanded,
Comment thread
alpharius-ck marked this conversation as resolved.
Resolved
accessibilityHint,
role = 'button',
hitSlop,
Expand Down Expand Up @@ -328,6 +333,7 @@ const Button = ({
onPressOut={hasPassedTouchHandler ? handlePressOut : undefined}
delayLongPress={delayLongPress}
aria-label={ariaLabel}
aria-expanded={ariaExpanded}
Comment thread
alpharius-ck marked this conversation as resolved.
Resolved
accessibilityHint={accessibilityHint}
role={role}
aria-disabled={disabled}
Expand Down
16 changes: 16 additions & 0 deletions src/components/__tests__/Button.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,22 @@ it('renders text button by default', async () => {
expect(tree).toMatchSnapshot();
});

it.each<[boolean, 'toBeExpanded' | 'toBeCollapsed']>([
[true, 'toBeExpanded'],
[false, 'toBeCollapsed'],
])(
'exposes aria-expanded=%s on the interactive button',
async (expanded, matcher) => {
await render(
<Button aria-expanded={expanded} onPress={() => {}}>
Show details
</Button>
);

expect(screen.getByRole('button', { name: 'Show details' }))[matcher]();
}
);

it('renders text button with mode', async () => {
const tree = (
await render(<Button mode="text">Text Button</Button>)
Expand Down
Loading