Skip to content

Commit e4b5220

Browse files
committed
ui-core: sync RadioGroup value prop with internal state
Signed-off-by: Mathieu <mathieu.coulibaly@sncf.fr>
1 parent 3065004 commit e4b5220

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

front/ui/ui-core/src/components/RadioGroup.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { type ChangeEvent, useState } from 'react';
1+
import React, { type ChangeEvent, useEffect, useState } from 'react';
22

33
import { RequiredInput } from '@osrd-project/ui-icons';
44
import cx from 'classnames';
@@ -34,6 +34,12 @@ const RadioGroup = ({
3434
}: RadioGroupProps) => {
3535
const [selectedValue, setSelectedValue] = useState<string | undefined>(value);
3636

37+
useEffect(() => {
38+
setSelectedValue(value);
39+
}, [value]);
40+
41+
const statusClassname = statusWithMessage?.status ? { [statusWithMessage.status]: true } : {};
42+
3743
const handleOptionChange = (e: ChangeEvent<HTMLInputElement>, nextOption: RadioButtonProps) => {
3844
if (!readOnly) {
3945
setSelectedValue(nextOption.value);
@@ -42,8 +48,6 @@ const RadioGroup = ({
4248
}
4349
};
4450

45-
const statusClassname = statusWithMessage?.status ? { [statusWithMessage.status]: true } : {};
46-
4751
return (
4852
<div className={cx('ui-radio-button-wrapper', statusClassname)}>
4953
{label && (

0 commit comments

Comments
 (0)