Skip to content

Commit

Permalink
fix: small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
revolunet committed Jul 14, 2024
1 parent 218c5bf commit 43f9eb6
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 19 deletions.
46 changes: 30 additions & 16 deletions src/components/WidgetRadio.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ChangeEvent, FocusEvent } from 'react'
import {
enumOptionsIsSelected,
enumOptionsValueForIndex,
FormContextType,
RJSFSchema,
Expand Down Expand Up @@ -37,28 +38,41 @@ export default function RadioWidget<
const _onFocus = ({ target: { value } }: FocusEvent<HTMLInputElement>) =>
onFocus(id, enumOptionsValueForIndex<S>(value, enumOptions, emptyValue))

const radioValues = Array.isArray(value) ? value : [value]
const inline = Boolean(options && options.inline)

console.log(value, options)
return (
<div style={{ marginTop: '1rem', marginBottom: '-1rem' }}>
<RadioButtons
options={
(options &&
options.enumOptions?.map((option) => ({
label: (
<LabelWithHelp
helpText={
uiSchema !== undefined ? uiSchema['ui:help'] : undefined
}
>
{option.label}
</LabelWithHelp>
),
nativeInputProps: {
checked: value === option.value,
onChange: (e) => onChange(option.value),
},
}))) ||
options.enumOptions?.map((option) => {
const checked = enumOptionsIsSelected<S>(
option.value,
radioValues,
)
const itemDisabled =
Array.isArray(enumDisabled) &&
enumDisabled.indexOf(option.value) !== -1

return {
label: (
<LabelWithHelp
helpText={
uiSchema !== undefined ? uiSchema['ui:help'] : undefined
}
>
{option.label}
</LabelWithHelp>
),
nativeInputProps: {
checked,
disabled: itemDisabled,
onChange: (e) => onChange(option.value),
value: option.value,
},
}
})) ||
[]
}
/>
Expand Down
11 changes: 8 additions & 3 deletions src/components/WidgetSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export default function <
hideError,
hideLabel,
uiSchema,
multiple,
...props
}: WidgetProps<T, S, F>) {
const { enumOptions, emptyValue: optEmptyVal } = props.options
Expand Down Expand Up @@ -74,13 +75,17 @@ export default function <
label={undefined}
{...props}
>
{!props.multiple &&
{(!props.multiple &&
props.schema.default === undefined &&
props.options.placeholder && (
<option value="" disabled>
<option value="" disabled selected>
{props.options.placeholder}
</option>
)}
)) || (
<option value="" disabled selected>
Séléctionner une option
</option>
)}
{props.options.enumOptions?.map((item, index) => (
<option key={index} value={String(index)}>
{item.label}
Expand Down

0 comments on commit 43f9eb6

Please sign in to comment.