|
5 | 5 | ReactElement, |
6 | 6 | RefObject, |
7 | 7 | useMemo, |
8 | | - useState, |
9 | 8 | } from 'react'; |
10 | 9 | import { |
11 | 10 | useButton, |
@@ -140,21 +139,22 @@ export const ComboBox = forwardRef(function ComboBox<T extends object>( |
140 | 139 | props: CubeComboBoxProps<T>, |
141 | 140 | ref: ForwardedRef<HTMLDivElement>, |
142 | 141 | ) { |
143 | | - const [, rerender] = useState({}); |
144 | | - |
145 | 142 | props = useProviderProps(props); |
146 | 143 | props = useFormProps(props); |
147 | 144 | props = useFieldProps(props, { |
148 | | - valuePropsMapper: ({ value, onChange }) => ({ |
149 | | - inputValue: value != null ? value : '', |
150 | | - onInputChange: (val) => { |
151 | | - // It triggers on the blur event and passes an empty string if no changes we made |
152 | | - // So we do a fallback to the real input value |
153 | | - onChange(val || props.inputValue || '', !props.allowsCustomValue); |
154 | | - rerender({}); |
155 | | - }, |
156 | | - onSelectionChange: onChange, |
157 | | - }), |
| 145 | + valuePropsMapper: ({ value, onChange }) => { |
| 146 | + return { |
| 147 | + selectedKey: value ?? null, |
| 148 | + onSelectionChange(val: string) { |
| 149 | + if (val != null) { |
| 150 | + onChange(val); |
| 151 | + } |
| 152 | + }, |
| 153 | + onBlur(evt) { |
| 154 | + evt?.stopPropagation(); |
| 155 | + }, |
| 156 | + }; |
| 157 | + }, |
158 | 158 | }); |
159 | 159 |
|
160 | 160 | let { |
@@ -197,6 +197,8 @@ export const ComboBox = forwardRef(function ComboBox<T extends object>( |
197 | 197 | filter, |
198 | 198 | styles, |
199 | 199 | labelSuffix, |
| 200 | + selectedKey, |
| 201 | + defaultSelectedKey, |
200 | 202 | ...otherProps |
201 | 203 | } = props; |
202 | 204 |
|
@@ -270,7 +272,7 @@ export const ComboBox = forwardRef(function ComboBox<T extends object>( |
270 | 272 | if (state.isOpen) { |
271 | 273 | updatePosition(); |
272 | 274 | } |
273 | | - }, [updatePosition, state.isOpen, state.collection.size]); |
| 275 | + }, [state.isOpen, state.collection.size]); |
274 | 276 |
|
275 | 277 | let isInvalid = validationState === 'invalid'; |
276 | 278 |
|
|
0 commit comments