Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
ce2bf6d
fix: use onPrimaryContainer for the selected switch icon
likevy Sep 3, 2026
48b428e
fix: apply focus handle color and focus state layer to switch
likevy Sep 3, 2026
10f274a
fix: meet the 48dp minimum touch target on switch
likevy Sep 3, 2026
c9767c2
fix: grow the switch handle immediately on press
likevy Sep 3, 2026
c8515a8
feat(switch): render a switch without onValueChange as read-only
likevy Sep 3, 2026
055347f
fix: allow readOnly to be set dynamically on a switch
likevy Sep 4, 2026
81fbf92
fix: clear switch interaction state when it becomes non-interactive
likevy Sep 4, 2026
863c604
test: assert aria-readonly on a read-only switch
likevy Sep 4, 2026
82fc033
fix: announce a switch with no way to be operated as read-only
likevy Sep 4, 2026
4edb635
test: cover pointer focus on web leaving the indicator hidden
likevy Sep 4, 2026
b7bd7b5
test: cover the switch handle growing on press
likevy Sep 4, 2026
1dfee10
fix: override onPrimaryContainer in the tertiary switch example
likevy Sep 4, 2026
783de49
test: assert a read-only switch does not toggle
likevy Sep 4, 2026
a4e25ea
test: catch a reintroduced delay in the switch press growth
likevy Sep 4, 2026
0102fcc
test: restore mocks in afterEach so a failure cannot leak
likevy Sep 4, 2026
b85118b
fix(switch): address accessibility review feedback
likevy Sep 23, 2026
e2ab697
fix(switch): keep the flat props type and rely on the runtime warning
likevy Oct 30, 2026
6a29603
test(switch): assert the values each interaction test covers
likevy Oct 30, 2026
b53613d
fix(switch): drop the pointer cursor from a read-only switch on web
likevy Oct 30, 2026
447a275
fix(switch): set keyboard focusability with tabIndex only
likevy Oct 30, 2026
444a5d7
docs(switch): expose a row that owns the press as one switch
likevy Oct 30, 2026
452ad6b
refactor(switch): spell the centering helper the American way
likevy Oct 30, 2026
2c1972b
fix(switch): let a press on a read-only switch reach its row on web
likevy Oct 30, 2026
f22c828
fix(switch): show focus again when a focused switch becomes operable
likevy Oct 30, 2026
9971d87
test(switch): cover read-only and disabled switches not warning
likevy Oct 30, 2026
1c3095f
docs(switch): describe the switch icon color and size for 5.x readers
likevy Oct 30, 2026
61a45c3
test(switch): cover pressing an operable switch inside a row on web
likevy Oct 30, 2026
0d7cf03
test(switch): cover focus handling on a read-only switch
likevy Oct 30, 2026
1740a52
docs(switch): tie the icon color note to checkedIcon
likevy Oct 30, 2026
830711b
fix(switch): type the web Space handlers with React Native key events
likevy Nov 6, 2026
09c7880
fix(switch): type key events for legacy React Native types
likevy Nov 6, 2026
9e2d6d7
Merge main into feat/fix-residual-md3-deviations-in-switch
jacekAtCK Nov 16, 2026
54fed08
refactor(switch): reuse useSpaceKeyPress hook and warn from an effect
jacekAtCK Nov 16, 2026
320c35c
Merge branch 'main' into fix/switch-md3-deviations
jacekAtCK Nov 16, 2026
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
71 changes: 71 additions & 0 deletions docs/6.x/docs/guides/migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -1359,6 +1359,77 @@ A standalone `Checkbox` has no visible label, so it now warns in development whe
+/>
```

#### Size

`Switch` draws a 52×32 track inside a 48dp tall touch target, so rows containing a switch may change height.

#### Switches without `onValueChange`

A `Switch` with no `onValueChange` used to render as an enabled, focusable control that did nothing when activated, and screen readers announced it as operable. It now renders as read-only and logs a warning. Pass `onValueChange` to make it interactive, or set `readOnly` or `disabled` to render it as a state indicator:

```tsx
// Before (v5)
<Switch value={isDarkTheme} />

// After (v6)
<Switch value={isDarkTheme} onValueChange={setIsDarkTheme} />
<Switch value={isDarkTheme} readOnly />
<Switch value={isDarkTheme} disabled />
```

A read-only switch keeps its enabled appearance and exposes its on/off state to screen readers, but it cannot be focused with a keyboard or pressed. On web it exposes `aria-readonly`. On iOS and Android it exposes a disabled accessibility state, because React Native has no read-only state for switches. Use `disabled` when you also want the disabled appearance.

This most often shows up where the switch sits inside a row that owns the press. Give the row the switch role and state, and hide the inner switch from assistive technology, so screen readers announce the row as one switch with its on/off state:

```diff
-<TouchableRipple onPress={toggleTheme}>
+<TouchableRipple
+ onPress={toggleTheme}
+ role="switch"
+ aria-checked={isDarkTheme}
+>
<View style={styles.row}>
<Text>Dark Theme</Text>
- <View pointerEvents="none">
- <Switch value={isDarkTheme} />
+ <View pointerEvents="none" aria-hidden>
+ <Switch value={isDarkTheme} readOnly />
</View>
</View>
</TouchableRipple>
```

On web, such a row toggles with Enter but not with Space, because React Native Web only handles Space for elements with the `button` role.

#### Icon color

When selected, an icon set with `checkedIcon` uses `onPrimaryContainer`. If you set `checkedIcon` and pass a `theme` with a partial `theme.colors` override, include `onPrimaryContainer`, because omitted roles fall back to the app theme:

```tsx
import { Switch, useTheme } from 'react-native-paper';

const TertiarySwitch = ({ value, onValueChange }) => {
const theme = useTheme();
const switchTheme = {
colors: {
primary: theme.colors.tertiary,
onPrimary: theme.colors.onTertiary,
primaryContainer: theme.colors.tertiaryContainer,
onPrimaryContainer: theme.colors.onTertiaryContainer,
},
};

return (
<Switch
value={value}
onValueChange={onValueChange}
checkedIcon="check"
theme={switchTheme}
/>
);
};
```

### Icon

`Icon`'s `source` prop is typed as `IconSource` instead of `any`, so a value that isn't an icon name, an image source or a render function, such as a boolean or `undefined`, is now a type error. `Icon` still renders nothing for those values.
Expand Down
60 changes: 42 additions & 18 deletions example/src/DrawerItems.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -172,58 +172,82 @@ function DrawerItems() {

<Drawer.Section title="Preferences">
{dynamicThemeSupported ? (
<TouchableRipple onPress={toggleShouldUseDynamicTheme}>
<TouchableRipple
onPress={toggleShouldUseDynamicTheme}
role="switch"
aria-checked={shouldUseDynamicTheme}
>
<View style={[styles.preference, styles.v3Preference]}>
<Text variant="labelLarge">Use Dynamic Theme</Text>
<View pointerEvents="none">
<Switch value={shouldUseDynamicTheme} />
<View pointerEvents="none" aria-hidden>
<Switch value={shouldUseDynamicTheme} readOnly />
</View>
</View>
</TouchableRipple>
) : null}
<TouchableRipple onPress={toggleTheme}>
<TouchableRipple
onPress={toggleTheme}
role="switch"
aria-checked={isDarkTheme}
>
<View style={[styles.preference, styles.v3Preference]}>
<Text variant="labelLarge">Dark Theme</Text>
<View pointerEvents="none">
<Switch value={isDarkTheme} />
<View pointerEvents="none" aria-hidden>
<Switch value={isDarkTheme} readOnly />
</View>
</View>
</TouchableRipple>

<TouchableRipple onPress={_handleToggleRTL}>
<TouchableRipple
onPress={_handleToggleRTL}
role="switch"
aria-checked={isRTL}
>
<View style={[styles.preference, styles.v3Preference]}>
<Text variant="labelLarge">RTL</Text>
<View pointerEvents="none">
<Switch value={isRTL} />
<View pointerEvents="none" aria-hidden>
<Switch value={isRTL} readOnly />
</View>
</View>
</TouchableRipple>

<TouchableRipple onPress={toggleCollapsed}>
<TouchableRipple
onPress={toggleCollapsed}
role="switch"
aria-checked={collapsed}
>
<View style={[styles.preference, styles.v3Preference]}>
<Text variant="labelLarge">Collapsed drawer *</Text>
<View pointerEvents="none">
<Switch value={collapsed} />
<View pointerEvents="none" aria-hidden>
<Switch value={collapsed} readOnly />
</View>
</View>
</TouchableRipple>

<TouchableRipple onPress={toggleCustomFont}>
<TouchableRipple
onPress={toggleCustomFont}
role="switch"
aria-checked={customFontLoaded}
>
<View style={[styles.preference, styles.v3Preference]}>
<Text variant="labelLarge">Custom font *</Text>
<View pointerEvents="none">
<Switch value={customFontLoaded} />
<View pointerEvents="none" aria-hidden>
<Switch value={customFontLoaded} readOnly />
</View>
</View>
</TouchableRipple>

<TouchableRipple onPress={toggleRippleEffect}>
<TouchableRipple
onPress={toggleRippleEffect}
role="switch"
aria-checked={rippleEffectEnabled}
>
<View style={[styles.preference, styles.v3Preference]}>
<Text variant="labelLarge">
{Platform.OS === 'ios' ? 'Highlight' : 'Ripple'} effect *
</Text>
<View pointerEvents="none">
<Switch value={rippleEffectEnabled} />
<View pointerEvents="none" aria-hidden>
<Switch value={rippleEffectEnabled} readOnly />
</View>
</View>
</TouchableRipple>
Expand Down
6 changes: 4 additions & 2 deletions example/src/Examples/FABExample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,11 @@ const FABExample = () => {
/>
<List.Item
title="Show FAB"
role="switch"
aria-checked={showFab}
right={() => (
<View pointerEvents="none">
<Switch value={showFab} />
<View pointerEvents="none" aria-hidden>
<Switch value={showFab} readOnly />
</View>
)}
onPress={() => setShowFab((v) => !v)}
Expand Down
5 changes: 5 additions & 0 deletions example/src/Examples/SwitchExample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const SwitchExample = () => {
primary: theme.colors.tertiary,
onPrimary: theme.colors.onTertiary,
primaryContainer: theme.colors.tertiaryContainer,
onPrimaryContainer: theme.colors.onTertiaryContainer,
secondary: theme.colors.tertiary,
},
}),
Expand Down Expand Up @@ -88,6 +89,10 @@ const SwitchExample = () => {
/>
</Row>

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

<View
style={[
styles.separator,
Expand Down
11 changes: 8 additions & 3 deletions example/src/Examples/TextInputExample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,16 @@ const TextInputDemo = ({ variant }: TextInputDemoProps) => {
{/* Controls */}
<List.Subheader style={styles.subheader}>Controls</List.Subheader>
{SWITCH_CONTROLS.map(({ label, key }) => (
<TouchableRipple key={key} onPress={() => toggleControl(key)}>
<TouchableRipple
key={key}
onPress={() => toggleControl(key)}
role="switch"
aria-checked={controls[key]}
>
<View style={styles.switchRow}>
<Text variant="bodyMedium">{label}</Text>
<View pointerEvents="none">
<Switch value={controls[key]} />
<View pointerEvents="none" aria-hidden>
<Switch value={controls[key]} readOnly />
</View>
</View>
</TouchableRipple>
Expand Down
Loading
Loading