Handle options component with no value set.

Fixes #43244

Signed-off-by: Stan Silvert <ssilvert@redhat.com>
This commit is contained in:
Stan Silvert 2025-10-14 15:15:12 -04:00 committed by Pedro Igor
parent 4c4a333365
commit afd4d04dcf

View File

@ -37,15 +37,15 @@ export const OptionComponent = (props: UserProfileFieldProps) => {
data-testid={option}
label={label(props.t, optionLabel[option], option, prefix)}
value={option}
isChecked={field.value.includes(option)}
isChecked={field.value?.includes(option)}
onChange={() => {
if (isMultiSelect) {
if (field.value.includes(option)) {
if (field.value?.includes(option)) {
field.onChange(
field.value.filter((item: string) => item !== option),
field.value?.filter((item: string) => item !== option),
);
} else {
field.onChange([...field.value, option]);
field.onChange([...(field.value || []), option]);
}
} else {
field.onChange([option]);