I have radio group in my application and this group builds based on array const genders = ["Male", "Female", "Neutral"];, when I press the Tab button focus falls at the first element only and goes further ignoring the rest of elements.
const { useState } = React;
const App = () => {
const genders = ["male", "female", "netural"];
return (
<React.Fragment>
<h1>Hello Example</h1>
<div>
{genders.map((gender) => (
<div key={gender}>
<div>
<input tabIndex={0} type="radio" value={gender} />
{gender}
</div>
</div>
))}
</div>
</React.Fragment>
);
};
const root = ReactDOM.createRoot(document.getElementById("root"));
root.render(<App />);
<div id="root"></div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/18.1.0/umd/react.development.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/18.1.0/umd/react-dom.development.js"></script>
I have prepared working example and sahred it here: sandbox
I have tried to add tabIndex to parent and to input element, but it didn't work.
When I add tabIndex={0} it selects parent element first and goes to the input element after clicking the Tab one more time, it is bad behaviour.
Please tell me how can it be fixed ?