rc-segmented is a foundational React component for building highly customizable segmented controls, extensively utilized within the Ant Design ecosystem. It presents choices as a group of buttons where typically only one can be active at a time, akin to a radio group. The component supports various data types for options (strings, numbers, or objects), robust `onChange` event handling, and manages selection state. Currently stable at version `2.7.1`, the package maintains a moderate release cadence, focusing on bug fixes, performance enhancements, and crucial accessibility improvements. While `rc-segmented` is the primary package, a newer scoped version, `@rc-component/segmented`, sometimes receives parallel updates, which can be a point of confusion for developers. Key differentiators include its deep integration with Ant Design's principles, a strong emphasis on accessibility, and a clear, functional API for managing segmented choices efficiently within React applications.
npm install rc-segmentedVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates a basic segmented control with state management, custom options, and event handling using modern React hooks and `createRoot`.
Update your `onChange` handler to accept a single argument representing the selected `value` (string | number).
Add `import 'rc-segmented/assets/index.css';` to your entry file or component where `rc-segmented` is used.
Verify your `package.json` and import statements refer to the correct package (`rc-segmented` or `@rc-component/segmented`) to maintain consistency.
Upgrade to the latest stable version of `rc-segmented` to benefit from improved accessibility features and compliance.
Change `import { Segmented } from 'rc-segmented';` to `import Segmented from 'rc-segmented';`Ensure `import 'rc-segmented/assets/index.css';` is present in your application's entry point or component, and your build tool (e.g., Webpack, Vite) is configured to handle CSS imports.
Ensure the `options` prop is always an array, for example: `<Segmented options={['Option 1', 'Option 2']} />`.