Skip to content
Open
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
3 changes: 2 additions & 1 deletion packages/mobile/src/cells/Cell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ export const Cell = memo(function Cell(_props: CellProps) {
accessibilityHint={accessibilityHint}
accessibilityLabel={accessibilityLabel}
accessibilityRole={accessibilityRole}
accessibilityState={{ disabled, ...accessibilityState }}
accessibilityState={{ disabled, selected, ...accessibilityState }}
background="bg"
blendStyles={blendStyles}
borderRadius={borderRadius}
Expand All @@ -306,6 +306,7 @@ export const Cell = memo(function Cell(_props: CellProps) {
accessibilityLabel,
accessibilityRole,
disabled,
selected,
styles?.pressable,
accessibilityState,
blendStyles,
Expand Down
24 changes: 24 additions & 0 deletions packages/mobile/src/cells/__tests__/ListCell.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,30 @@ describe('ListCell', () => {
expect(screen.getByTestId('listcell-with-a11y')).toBeAccessible();
});

it('sets selected accessibilityState when selected and pressable', () => {
render(
<DefaultThemeProvider>
<ListCell selected onPress={noop} testID="listcell-selected" title="Title" />
</DefaultThemeProvider>,
);

expect(screen.getByTestId('listcell-selected-cell-pressable')).toHaveAccessibilityState({
selected: true,
});
});

it('does not set selected accessibilityState when not selected', () => {
render(
<DefaultThemeProvider>
<ListCell onPress={noop} testID="listcell-not-selected" title="Title" />
</DefaultThemeProvider>,
);

expect(screen.getByTestId('listcell-not-selected-cell-pressable')).not.toHaveAccessibilityState(
{ selected: true },
);
});

it('applies styles to internal components', () => {
const styles = {
accessory: { borderRightWidth: 11 },
Expand Down
11 changes: 9 additions & 2 deletions packages/web/src/cells/Cell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -430,14 +430,20 @@ export const Cell: CellComponent = memo(
};
if (isAnchor)
return (
<Pressable as="a" href={href} target={target} {...pressableSharedProps}>
<Pressable
aria-current={selected ? 'true' : undefined}
as="a"
href={href}
target={target}
{...pressableSharedProps}
>
{content}
</Pressable>
);

if (isButton)
return (
<Pressable as="button" {...pressableSharedProps}>
<Pressable aria-pressed={selected} as="button" {...pressableSharedProps}>
{content}
</Pressable>
);
Expand All @@ -454,6 +460,7 @@ export const Cell: CellComponent = memo(
onClick,
onKeyDown,
onKeyUp,
selected,
tabIndex,
testID,
styles?.pressable,
Expand Down
44 changes: 44 additions & 0 deletions packages/web/src/cells/__tests__/Cell.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -282,4 +282,48 @@ describe('Cell', () => {

expect(onKeyDownSpy).toHaveBeenCalledTimes(1);
});

it('sets aria-pressed on the button when selected', () => {
render(
<DefaultThemeProvider>
<Cell selected onClick={noop}>
{CELL_TEXT}
</Cell>
</DefaultThemeProvider>,
);

expect(screen.getByRole('button')).toHaveAttribute('aria-pressed', 'true');
});

it('does not set aria-pressed on the button when not selected', () => {
render(
<DefaultThemeProvider>
<Cell onClick={noop}>{CELL_TEXT}</Cell>
</DefaultThemeProvider>,
);

expect(screen.getByRole('button')).not.toHaveAttribute('aria-pressed', 'true');
});

it('sets aria-current on the link when selected', () => {
render(
<DefaultThemeProvider>
<Cell selected href={URL}>
{CELL_TEXT}
</Cell>
</DefaultThemeProvider>,
);

expect(screen.getByRole('link')).toHaveAttribute('aria-current', 'true');
});

it('does not set aria-current on the link when not selected', () => {
render(
<DefaultThemeProvider>
<Cell href={URL}>{CELL_TEXT}</Cell>
</DefaultThemeProvider>,
);

expect(screen.getByRole('link')).not.toHaveAttribute('aria-current');
});
});
Loading