Skip to content

Commit f192470

Browse files
committed
feat(ComboBox): new component * 5
1 parent d41bea4 commit f192470

File tree

1 file changed

+36
-14
lines changed

1 file changed

+36
-14
lines changed

src/components/fields/ComboBox/ComboBox.tsx

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -726,7 +726,10 @@ export const ComboBox = forwardRef(function ComboBox<T extends object>(
726726
);
727727

728728
// Input focus handler
729-
const handleInputFocus = useEvent(() => {
729+
const handleInputFocus = useEvent((e: React.FocusEvent<HTMLInputElement>) => {
730+
// Call focus props handler if it exists
731+
focusProps.onFocus?.(e as any);
732+
730733
if (popoverTrigger === 'focus' && !isPopoverOpen) {
731734
setIsPopoverOpen(true);
732735
}
@@ -747,14 +750,23 @@ export const ComboBox = forwardRef(function ComboBox<T extends object>(
747750
const listState = listStateRef.current;
748751
if (!listState) return;
749752

750-
const { selectionManager, collection } = listState;
753+
const { selectionManager, collection, disabledKeys } = listState;
751754

752-
const visibleKeys: Key[] = [];
753-
for (const node of collection) {
754-
if (node.type === 'item') {
755-
visibleKeys.push(node.key);
755+
// Helper to collect visible item keys (supports sections)
756+
const collectVisibleKeys = (nodes: Iterable<any>, out: Key[]) => {
757+
for (const node of nodes) {
758+
if (node.type === 'item') {
759+
if (!disabledKeys?.has(node.key)) {
760+
out.push(node.key);
761+
}
762+
} else if (node.childNodes) {
763+
collectVisibleKeys(node.childNodes, out);
764+
}
756765
}
757-
}
766+
};
767+
768+
const visibleKeys: Key[] = [];
769+
collectVisibleKeys(collection, visibleKeys);
758770

759771
if (visibleKeys.length === 0) return;
760772

@@ -834,14 +846,23 @@ export const ComboBox = forwardRef(function ComboBox<T extends object>(
834846
const listState = listStateRef.current;
835847
if (!listState) return;
836848

837-
const { selectionManager, collection } = listState;
849+
const { selectionManager, collection, disabledKeys } = listState;
838850

839-
const visibleKeys: Key[] = [];
840-
for (const node of collection) {
841-
if (node.type === 'item') {
842-
visibleKeys.push(node.key);
851+
// Helper to collect visible item keys (supports sections)
852+
const collectVisibleKeys = (nodes: Iterable<any>, out: Key[]) => {
853+
for (const node of nodes) {
854+
if (node.type === 'item') {
855+
if (!disabledKeys?.has(node.key)) {
856+
out.push(node.key);
857+
}
858+
} else if (node.childNodes) {
859+
collectVisibleKeys(node.childNodes, out);
860+
}
843861
}
844-
}
862+
};
863+
864+
const visibleKeys: Key[] = [];
865+
collectVisibleKeys(collection, visibleKeys);
845866

846867
if (visibleKeys.length === 0) return;
847868

@@ -1058,7 +1079,8 @@ export const ComboBox = forwardRef(function ComboBox<T extends object>(
10581079
data-autofocus={autoFocus ? '' : undefined}
10591080
onChange={handleInputChange}
10601081
onFocus={handleInputFocus}
1061-
{...mergeProps(keyboardProps, focusProps)}
1082+
onBlur={focusProps.onBlur}
1083+
{...keyboardProps}
10621084
styles={inputStyles}
10631085
mods={mods}
10641086
data-size={size}

0 commit comments

Comments
 (0)