Repository navigation
Conversation
BREAKING CHANGE: a `Switch` with no `onValueChange` that is neither `readOnly` nor `disabled` now renders read-only and logs a warning. `Switch` reserves a 48dp tall touch target.
The handler branch of the union only accepted `readOnly={false}`, so a switch
with a stable handler could not become read-only from state, even though the
runtime already gives `readOnly` precedence and `disabled` allowed exactly that
pattern. The branch that requires `disabled` was equally strict.
A handler still guarantees operability whenever read-only is false, and a
switch with neither a handler nor a statically-true `readOnly`/`disabled` is
still rejected.
Interaction handlers are withheld while a switch is disabled, read-only, or missing a handler, so one that was hovered, pressed, or focused at the moment it flipped never received the matching hover-out, press-out, or blur. The shared value stayed at 1 and the switch kept painting that state -- a disabled switch could show a focus ring, and the stale value was still there if it became interactive again.
The read-only test covered focusability and checked state but never the attribute the read-only contract exists for on web, so dropping it left the test green.
The runtime fallback for an untyped `<Switch value />` withheld the interaction
handlers but still emitted `aria-readonly={false}` alongside
`aria-disabled={false}`, so on web it was still exposed as an enabled switch
rather than the state indicator the guard renders.
Read-only is now derived from the rendered state -- non-operable but not
disabled -- which covers both an explicit `readOnly` and the fallback, while
`aria-disabled` keeps carrying the disabled case on its own.
The focus tests only fired a generic focus event on the default native platform, where `isKeyboardFocusEvent` always returns true, so nothing covered the `:focus-visible` gating that keeps a mouse click from lighting the ring. Adds both web paths, driving `currentTarget.matches` directly.
Removing the 100ms delay was a user-visible fix with no test behind it, so the delay could have come back unnoticed. Asserting the size needs a testID on the view that carries it: `-handle` now names the view holding the handle's size and position, and the tinted fill inside it becomes `-handle-fill`.
Moving the selected icon to `onPrimaryContainer` left the tertiary-theme example with a mixed palette: it overrides `primary`, `onPrimary` and `primaryContainer`, and a partial theme falls back to the app theme for omitted roles, so the icon stayed in the default palette. Documents the role change in the migration guide too, since any partial `Switch` theme in consumer code has the same gap.
The read-only tests checked the exposed metadata but never the guarantee it stands for. The props type deliberately permits `readOnly` alongside `onValueChange`, so read-only has to win at runtime -- and nothing would have caught the handler being attached anyway.
The press test flushed all timers before asserting, so restoring the old `withDelay(100, ...)` snap still reached the pressed size and the test passed. It verified the end state, not the immediacy it was written for. Now asserts the handle has already started growing two frames in, well inside the delay the old implementation waited out, and keeps a separate case for the settled sizes on press and release.
Each test that overrode `Platform.OS` or stubbed `console.warn` restored it on the last line, which never runs when an assertion throws. A single failing test left every later test in the file running as web, turning one real failure into a cascade of misleading ones. Matches the teardown FABExtended and Surface already use.
The operability union rejected props that are valid at runtime, such as a conditional handler paired with `disabled`, and it collapsed in wrappers built with `Omit`. `SwitchProps` is the flat `Props` again, like `Checkbox` and `RadioButton`. A switch with no `onValueChange` that is neither `readOnly` nor `disabled` still renders as read-only and logs a warning.
The focus, press and read-only tests flattened every style in the tree and compared or snapshotted the whole dump, so a change to any internal layer broke them and the snapshots did not show which value mattered. They now read the animated style of the one layer that changes: the focus ring opacity, the state layer opacity, the handle size and the handle color.
React Native Web's Pressable shows a pointer cursor whenever it is not `disabled`, and a read-only switch keeps `disabled` false on web so it can expose `aria-readonly`. The pointer suggested a click that does nothing, so a switch that cannot be operated now uses the default cursor.
`focusable` and `tabIndex` set the same thing. React Native's View
treats `tabIndex` as an alias of `focusable` on Android, and React
Native Web uses `tabIndex` when it is set and ignores the deprecated
`focusable`. The tests check `tabIndex` instead.
The disabled render snapshots now show Pressable's default
`focusable={true}` next to `tabIndex={-1}`, because the jest View mock
skips the aliasing that the real View applies.
In the pattern where a row owns the press and the switch only shows the state, screen readers got the on/off state from neither element: iOS merged the inner switch into the row, Android exposed a clickable row next to a separate disabled switch, and on web the focusable row had no role or `aria-checked`. The migration guide and the drawer, FAB and TextInput example rows now give the row the switch role and state and hide the inner switch from assistive technology. Also drop the em dashes from the Switch migration notes.
A read-only switch keeps `disabled` false on web so it can expose `aria-readonly`, but React Native Web's Pressable then still takes the responder and stops the click, even without `onPress`. Inside a row that owns the press, such as `List.Item` with the switch in `right`, clicking the switch did nothing on web, while iOS and Android pass the press to the row. A switch that cannot be operated now has `pointerEvents: 'none'` on web instead of the `cursor: 'auto'` override, so the click and the cursor come from what is underneath.
On web a focused switch that becomes disabled or read-only keeps DOM focus, because React Native Web only changes its `tabIndex` and ARIA state. The focus handlers were detached and the focus state cleared meanwhile, so once the switch was operable again it was still focused but showed no ring or state layer. Focus and blur are now tracked regardless of interactivity, and the focus ring, state layer and focus handle color are shown only while the switch can be operated.
The guide covers migrating from 5.x, where `Switch` was the platform switch with no icon and no 40dp box, so notes saying the icon color changed from `primary` and the height grew from 40dp only made sense against a 6.0 prerelease. Both notes now describe the 6.x switch: the selected icon uses `onPrimaryContainer`, and the switch is a 52x32 track inside a 48dp tall touch target.
React Native 0.88 types `onKeyDown` and `onKeyUp` as `KeyDownEvent` and `KeyUpEvent`, so the DOM `KeyboardEvent` annotations no longer type check. The handlers only read `nativeEvent.key`, `nativeEvent.repeat` and `preventDefault()`, which both React Native's event and the React synthetic event that React Native Web passes provide.
React Native's legacy types, still the default before 0.87 and checked in CI, export neither KeyDownEvent nor KeyUpEvent. Type the Space handlers with a NativeSyntheticEvent of the fields they read, which both type sets accept.
Main now draws the Switch focus ring with the shared useFocusRing hook (callstack#5107). The switch keeps that ring and drops its own ring view. The hook gets !isInteractive, so a read-only switch shows no ring. The focus tests check the outline on the track on native, and the ring attribute on the track on web. The migration guide keeps the Switch intro and removed props from main, then adds the size, read-only and icon color notes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 16, 2026
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
Takes over #5102 by @likevy and keeps the original commits. It fixes residual MD3 deviations in
Switch: a 48dp tall touch target, focus handle color and state layer, immediate press growth, Space on web, and theonPrimaryContainerselected icon. A switch with no handler renders read-only and warns.The switch now uses the shared focus ring from #5107, and a read-only switch shows no ring.
Also: Switch now reuses useSpaceKeyPress, the hook that also is used by Checkbox.
Warning for a switch without onValueChange ran during render. It now runs in an effect, once per mount (on non prod build).
Related issue
#5102. Merge order: #5150 (small rewrites, after #5110).
Screenshots / Videos
From #5102:
pr5102-switch-android.mp4
Test plan
Switch example: hold (the handle grows at once),
Tab on web (ring on the track) and Space (toggles),
Read-only (ignores taps, skipped by Tab, no ring).