React Stepper - Configure a Read-Only Stepper
You can disable all user interaction with Stepper by setting focusStateEnabled to false and assigning the pointer-events: none; CSS style to the component. Define and modify the selectedIndex property to control the Stepper state independently of the component. The code snippet below allows users to change the active step with two Buttons.
App.tsx
styles.css
- export default function App() {
- const [selectedIndex, setSelectedIndex] = useState(0)
- const handlePreviousButtonClick = () => {
- if (selectedIndex > 0) {
- setSelectedIndex(selectedIndex-1);
- }
- }
- const handleNextButtonClick = () => {
- if (selectedIndex < dataSource.length - 1) {
- setSelectedIndex(selectedIndex+1);
- }
- }
- return (
- <Stepper id="stepper" dataSource={dataSource} focusStateEnabled={false} selectedIndex={selectedIndex} />
- <Button text="Previous Step" onClick={handlePreviousButtonClick} />
- <Button text="Next Step" onClick={handleNextButtonClick} />
- )
- }
- #stepper {
- pointer-events: none;
- }