import * as React from 'react'; import { useTheme } from '@mui/material/styles'; import MobileStepper from '@mui/material/MobileStepper'; import Button from '@mui/material/Button'; import KeyboardArrowLeft from '@mui/icons-material/KeyboardArrowLeft'; import KeyboardArrowRight from '@mui/icons-material/KeyboardArrowRight'; export default function ProgressMobileStepper() { const theme = useTheme(); const [activeStep, setActiveStep] = React.useState(0); const handleNext = () => { setActiveStep((prevActiveStep) => prevActiveStep + 1); }; const handleBack = () => { setActiveStep((prevActiveStep) => prevActiveStep - 1); }; const nextButtonRef = React.useRef(null); const backButtonRef = React.useRef(null); const previousActiveStepRef = React.useRef(activeStep); // Manage focus when the active step changes. React.useEffect(() => { const previousActiveStep = previousActiveStepRef.current; if (activeStep === 0 && previousActiveStep === 1) { // If the user is going back to the first step, focus the "Next" button. nextButtonRef.current.focus(); } else if (activeStep === 5 && previousActiveStep === 4) { // If the user is going to the last step, focus the "Back" button. backButtonRef.current.focus(); } previousActiveStepRef.current = activeStep; }, [activeStep]); return ( Next {theme.direction === 'rtl' ? ( ) : ( )} } backButton={ } /> ); }