Skip to content

Commit c274839

Browse files
Fix 4623 by properly handling chakra-ui's onChange for single select (#4627)
Fixed #4623 by having the single select version return the element in the returned array - Updated chakra-ui's `SelectWidget` to return a single value from the array
1 parent e444bfc commit c274839

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,19 @@ should change the heading of the (upcoming) version to include a major version b
1616
1717
-->
1818

19+
# 6.0.0-beta.9
20+
21+
## @rjsf/chakra-ui
22+
23+
- 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)
24+
1925
# 6.0.0-beta.8
2026

2127
## @rjsf/chakra-ui
2228

2329
- Added `getChakra` to package exports
2430
- Restored the `ui:options` customization
31+
- 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)
2532

2633
## @rjsf/core
2734

packages/chakra-ui/src/SelectWidget/SelectWidget.tsx

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,12 @@ export default function SelectWidget<T = any, S extends StrictRJSFSchema = RJSFS
4343
const { enumOptions, enumDisabled, emptyValue } = options;
4444

4545
const _onMultiChange = ({ value }: SelectValueChangeDetails) => {
46-
return onChange(
47-
enumOptionsValueForIndex<S>(
48-
value.map((item) => {
49-
return item;
50-
}),
51-
enumOptions,
52-
emptyValue,
53-
),
54-
);
46+
return onChange(enumOptionsValueForIndex<S>(value, enumOptions, emptyValue));
5547
};
5648

57-
const _onChange = ({ value }: SelectValueChangeDetails) => {
58-
return onChange(enumOptionsValueForIndex<S>(value, enumOptions, emptyValue));
49+
const _onSingleChange = ({ value }: SelectValueChangeDetails) => {
50+
const selected = enumOptionsValueForIndex<S>(value, enumOptions, emptyValue);
51+
return onChange(Array.isArray(selected) && selected.length === 1 ? selected[0] : selected);
5952
};
6053

6154
const _onBlur = ({ target }: FocusEvent<HTMLInputElement>) =>
@@ -137,7 +130,7 @@ export default function SelectWidget<T = any, S extends StrictRJSFSchema = RJSFS
137130
multiple={isMultiple}
138131
closeOnSelect={!isMultiple}
139132
onBlur={_onBlur}
140-
onValueChange={isMultiple ? _onMultiChange : _onChange}
133+
onValueChange={isMultiple ? _onMultiChange : _onSingleChange}
141134
onFocus={_onFocus}
142135
autoFocus={autofocus}
143136
value={formValue}

0 commit comments

Comments
 (0)