How can I wrap a radio button group with a 200px width and maintain proper keyboard navigation? I noticed that when I implement a parent div using a Container component
const Container = ({ children }) => ( <div style={{ width: "200px" }}>{children}</div>);
, the keyboard navigation stops working properly after moving to a different radio button. However, if I use plain HTML code <div style={{ width: "200px"}}>
, the keyboard navigation functions correctly. Both methods seem to be semantically similar when inspected using dev tools. Can anyone shed light on why the Container component affects keyboard navigation while hardcoding in HTML does not? https://codesandbox.io/s/radio-button-example-3t8l80?file=/App.js
import { Stack, RadioButton } from "@shopify/polaris";
import { useState, useCallback } from "react";
function RadioButtonExample() {
const [value, setValue] = useState("disabled");
const handleChange = useCallback(
(_checked, newValue) => setValue(newValue),
[]
);
const Container = ({ children }) => (
<div style={{ width: "200px" }}>{children}</div>
);
return (
<Container> // keyboard navigation doesn't work properly with this
{/* <div style={{ width: "200px"}}> */} // keyboard navigation works fine
<Stack vertical>
<RadioButton
label="Accounts are disabled"
helpText="Customers will only be able to check out as guests."
checked={value === "disabled"}
id="disabled"
name="accounts"
onChange={handleChange}
/>
<RadioButton
label="Accounts are optional"
helpText="Customers will be able to check out with a customer account or as a guest."
id="optional"
name="accounts"
checked={value === "optional"}
onChange={handleChange}
/>
</Stack>
{/* </div> */}
</Container>
);
}
export default RadioButtonExample;