Répare la selection dans un choix multiple imbriqué

fix #1890
pull/1892/head
Johan Girod 2021-12-15 17:14:21 +01:00
parent fd02b0095f
commit 4b0c70ae96
1 changed files with 10 additions and 4 deletions

View File

@ -55,7 +55,11 @@ export function MultipleAnswerInput({
const { handleChange, defaultValue, currentSelection } = useSelection(props)
return (
<RadioGroup onChange={handleChange} value={currentSelection ?? undefined}>
<RadioChoice autoFocus={defaultValue} choice={choice} />
<RadioChoice
autoFocus={defaultValue}
choice={choice}
rootDottedName={props.dottedName}
/>
</RadioGroup>
)
}
@ -63,17 +67,19 @@ export function MultipleAnswerInput({
function RadioChoice({
choice,
autoFocus,
rootDottedName,
}: {
choice: Choice
autoFocus?: string
rootDottedName: DottedName
}) {
const relativeDottedName = (radioDottedName: string) =>
radioDottedName.split(choice.dottedName + ' . ')[1]
radioDottedName.split(rootDottedName + ' . ')[1]
const hiddenOptions = useContext(HiddenOptionContext)
return (
<>
{choice.children.map((node, i) => (
{choice.children.map((node) => (
<Fragment key={node.dottedName}>
{' '}
{hiddenOptions.includes(
@ -89,7 +95,7 @@ function RadioChoice({
<H4 id={node.dottedName + '-legend'}>{node.title}</H4>
<Spacing lg />
<StyledSubRadioGroup>
<RadioChoice choice={node} />
<RadioChoice choice={node} rootDottedName={rootDottedName} />
</StyledSubRadioGroup>
</div>
) : (