Skip to content

Commit d0b9631

Browse files
committed
feat(ComboBox): new component * 7
1 parent 9c4cac6 commit d0b9631

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/components/fields/ComboBox/ComboBox.tsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,6 +1091,26 @@ export const ComboBox = forwardRef(function ComboBox<T extends object>(
10911091
},
10921092
);
10931093

1094+
// Sync input value with selected key in controlled mode
1095+
useEffect(() => {
1096+
// Only sync when input is not controlled to avoid overriding controlled input
1097+
if (isControlledInput) return;
1098+
1099+
if (effectiveSelectedKey != null) {
1100+
const selectedItem = findItemByKey(effectiveSelectedKey);
1101+
const label =
1102+
selectedItem?.props?.textValue ||
1103+
(typeof selectedItem?.props?.children === 'string'
1104+
? selectedItem.props.children
1105+
: '') ||
1106+
String(effectiveSelectedKey);
1107+
1108+
setInternalInputValue(label);
1109+
} else {
1110+
setInternalInputValue('');
1111+
}
1112+
}, [effectiveSelectedKey, findItemByKey, isControlledInput, children]);
1113+
10941114
// Input focus handler
10951115
const handleInputFocus = useEvent((e: React.FocusEvent<HTMLInputElement>) => {
10961116
// Call focus props handler if it exists

0 commit comments

Comments
 (0)