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
8 changes: 7 additions & 1 deletion docs/6.x/docs/guides/migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -1883,7 +1883,13 @@ When selected, an icon set with `checkedIcon` uses `onPrimaryContainer`. If you
```tsx
import { Switch, useTheme } from 'react-native-paper';

const TertiarySwitch = ({ value, onValueChange }) => {
const TertiarySwitch = ({
value,
onValueChange,
}: {
value: boolean;
onValueChange: (value: boolean) => void;
}) => {
const theme = useTheme();
const switchTheme = {
colors: {
Expand Down
2 changes: 1 addition & 1 deletion example/src/Examples/SwitchExample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ const SwitchExample = () => {
</Row>

<Row label="Read-only">
<Switch value={defaultOn} readOnly />
<Switch value={defaultOn} readOnly aria-label="Read-only" />
</Row>

<View
Expand Down
2 changes: 1 addition & 1 deletion src/components/Switch/Switch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ const Switch = ({
disabled={Platform.OS === 'web' ? isDisabled : !isInteractive}
tabIndex={isInteractive ? 0 : -1}
aria-readonly={
Platform.OS === 'web' ? isAnnouncedReadOnly : undefined
Platform.OS === 'web' && isAnnouncedReadOnly ? true : undefined
}
onFocus={(e) => {
// Not the ring - it's real CSS on web now. This drives the
Expand Down
13 changes: 11 additions & 2 deletions src/components/__tests__/Switch.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,9 @@ describe('Switch operability', () => {

await render(<Switch value {...{ [prop]: true }} />);

expect(console.warn).not.toHaveBeenCalled();
expect(console.warn).not.toHaveBeenCalledWith(
expect.stringContaining('Switch:')
);
}
);

Expand Down Expand Up @@ -393,7 +395,7 @@ describe('Switch operability', () => {
await render(<Switch value disabled readOnly />);

expect(screen.getByRole('switch')).toBeDisabled();
expect(screen.getByRole('switch')).not.toHaveProp('aria-readonly', true);
expect(screen.getByRole('switch')).not.toHaveProp('aria-readonly');
});
});

Expand Down Expand Up @@ -422,6 +424,13 @@ describe('Switch operability', () => {
expect(screen.getByRole('switch')).toBeEnabled();
});

it('does not expose aria-readonly on an operable switch on web', async () => {
jest.replaceProperty(Platform, 'OS', 'web');
await render(<Switch value onValueChange={() => {}} />);

expect(screen.getByRole('switch')).not.toHaveProp('aria-readonly');
});

it('exposes a missing-handler fallback as read-only on web', async () => {
jest.replaceProperty(Platform, 'OS', 'web');
jest.spyOn(console, 'warn').mockImplementation(() => {});
Expand Down
Loading