Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,19 @@ should change the heading of the (upcoming) version to include a major version b

-->

# 6.0.0-beta.9

## @rjsf/chakra-ui

- Updated `SelectWidget` to only pick the first element in a list when single selection is active, fixing [#4623](https://github.com/rjsf-team/react-jsonschema-form/issues/4623)

# 6.0.0-beta.8

## @rjsf/chakra-ui

- Added `getChakra` to package exports
- Restored the `ui:options` customization
- Updated `SelectWidget` to only pick the first element in a list when single selection is active, fixing [#4623](https://github.com/rjsf-team/react-jsonschema-form/issues/4623)

## @rjsf/core

Expand Down
17 changes: 5 additions & 12 deletions packages/chakra-ui/src/SelectWidget/SelectWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,12 @@ export default function SelectWidget<T = any, S extends StrictRJSFSchema = RJSFS
const { enumOptions, enumDisabled, emptyValue } = options;

const _onMultiChange = ({ value }: SelectValueChangeDetails) => {
return onChange(
enumOptionsValueForIndex<S>(
value.map((item) => {
return item;
}),
Comment on lines -48 to -50
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seemed unnecessary since it basically returned the same thing as value

enumOptions,
emptyValue,
),
);
return onChange(enumOptionsValueForIndex<S>(value, enumOptions, emptyValue));
};

const _onChange = ({ value }: SelectValueChangeDetails) => {
return onChange(enumOptionsValueForIndex<S>(value, enumOptions, emptyValue));
const _onSingleChange = ({ value }: SelectValueChangeDetails) => {
const selected = enumOptionsValueForIndex<S>(value, enumOptions, emptyValue);
return onChange(Array.isArray(selected) && selected.length === 1 ? selected[0] : selected);
};

const _onBlur = ({ target }: FocusEvent<HTMLInputElement>) =>
Expand Down Expand Up @@ -137,7 +130,7 @@ export default function SelectWidget<T = any, S extends StrictRJSFSchema = RJSFS
multiple={isMultiple}
closeOnSelect={!isMultiple}
onBlur={_onBlur}
onValueChange={isMultiple ? _onMultiChange : _onChange}
onValueChange={isMultiple ? _onMultiChange : _onSingleChange}
onFocus={_onFocus}
autoFocus={autofocus}
value={formValue}
Expand Down