Skip to content

feat: add disabledIndices prop to disable individual segments - #936

Merged
Naturalclar merged 3 commits into
react-native-segmented-control:masterfrom
officialasishkumar:feat/disabled-segments
Nov 23, 2026
Merged

Naturalclar merged 3 commits into
react-native-segmented-control:masterfrom
officialasishkumar:feat/disabled-segments

Conversation

@officialasishkumar

Copy link
Copy Markdown
Contributor

Overview

Adds a disabledIndices prop (array of segment indexes) so individual segments can be disabled while the rest of the control stays interactive. Closes #615, closes #519.

<SegmentedControl values={['S', 'M', 'L']} disabledIndices={[1]} ... />
  • iOS: the prop is forwarded to the native view, which calls setEnabled:forSegmentAtIndex: for each segment. It is reapplied whenever values changes, because UISegmentedControl loses per-segment state when segments are rebuilt.
  • Android/web: matching tabs are disabled and dimmed. If the whole control is disabled via enabled={false}, every segment stays disabled.
  • Flow and TypeScript typings and README docs added.

Test Plan

  • Added jest tests covering: only listed segments are disabled (including accessibilityState), other segments still fire onChange, enabled={false} overrides, and out-of-range indexes are ignored.
  • pnpm exec jest --runInBand, pnpm lint, pnpm flow check and pnpm tsc all pass.
  • The iOS native change is small and follows the existing prop pattern, but I have not run it in a simulator.

Allow disabling specific segments while the rest of the control stays
interactive (react-native-segmented-control#615, react-native-segmented-control#519).

- iOS: forward the new prop to the native view, which calls
  setEnabled:forSegmentAtIndex: for every segment. The state is reapplied
  when the values change, since UISegmentedControl drops it when its
  segments are rebuilt.
- Android/web: disable and dim the matching tabs; a control disabled via
  `enabled` keeps all of its segments disabled.
- Add typings (Flow and TypeScript), README docs and unit tests.
Naturalclar and others added 2 commits November 23, 2026 12:48
$ReadOnlyArray is flagged as a deprecated utility type by the Flow
version the repository now uses (0.331, since react-native-segmented-control#939).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@Naturalclar Naturalclar left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you!

@Naturalclar
Naturalclar merged commit 2817e3d into react-native-segmented-control:master Nov 23, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature: disabled segments per Tab customization

2 participants