Skip to content

Commit 43f9eb6

Browse files
committed
fix: small fixes
1 parent 218c5bf commit 43f9eb6

File tree

2 files changed

+38
-19
lines changed

2 files changed

+38
-19
lines changed

src/components/WidgetRadio.tsx

+30-16
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { ChangeEvent, FocusEvent } from 'react'
22
import {
3+
enumOptionsIsSelected,
34
enumOptionsValueForIndex,
45
FormContextType,
56
RJSFSchema,
@@ -37,28 +38,41 @@ export default function RadioWidget<
3738
const _onFocus = ({ target: { value } }: FocusEvent<HTMLInputElement>) =>
3839
onFocus(id, enumOptionsValueForIndex<S>(value, enumOptions, emptyValue))
3940

41+
const radioValues = Array.isArray(value) ? value : [value]
4042
const inline = Boolean(options && options.inline)
41-
43+
console.log(value, options)
4244
return (
4345
<div style={{ marginTop: '1rem', marginBottom: '-1rem' }}>
4446
<RadioButtons
4547
options={
4648
(options &&
47-
options.enumOptions?.map((option) => ({
48-
label: (
49-
<LabelWithHelp
50-
helpText={
51-
uiSchema !== undefined ? uiSchema['ui:help'] : undefined
52-
}
53-
>
54-
{option.label}
55-
</LabelWithHelp>
56-
),
57-
nativeInputProps: {
58-
checked: value === option.value,
59-
onChange: (e) => onChange(option.value),
60-
},
61-
}))) ||
49+
options.enumOptions?.map((option) => {
50+
const checked = enumOptionsIsSelected<S>(
51+
option.value,
52+
radioValues,
53+
)
54+
const itemDisabled =
55+
Array.isArray(enumDisabled) &&
56+
enumDisabled.indexOf(option.value) !== -1
57+
58+
return {
59+
label: (
60+
<LabelWithHelp
61+
helpText={
62+
uiSchema !== undefined ? uiSchema['ui:help'] : undefined
63+
}
64+
>
65+
{option.label}
66+
</LabelWithHelp>
67+
),
68+
nativeInputProps: {
69+
checked,
70+
disabled: itemDisabled,
71+
onChange: (e) => onChange(option.value),
72+
value: option.value,
73+
},
74+
}
75+
})) ||
6276
[]
6377
}
6478
/>

src/components/WidgetSelect.tsx

+8-3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export default function <
2323
hideError,
2424
hideLabel,
2525
uiSchema,
26+
multiple,
2627
...props
2728
}: WidgetProps<T, S, F>) {
2829
const { enumOptions, emptyValue: optEmptyVal } = props.options
@@ -74,13 +75,17 @@ export default function <
7475
label={undefined}
7576
{...props}
7677
>
77-
{!props.multiple &&
78+
{(!props.multiple &&
7879
props.schema.default === undefined &&
7980
props.options.placeholder && (
80-
<option value="" disabled>
81+
<option value="" disabled selected>
8182
{props.options.placeholder}
8283
</option>
83-
)}
84+
)) || (
85+
<option value="" disabled selected>
86+
Séléctionner une option
87+
</option>
88+
)}
8489
{props.options.enumOptions?.map((item, index) => (
8590
<option key={index} value={String(index)}>
8691
{item.label}

0 commit comments

Comments
 (0)