Skip to content

Commit

Permalink
WIP: ComboBox show all items on open (DH-18088)
Browse files Browse the repository at this point in the history
  • Loading branch information
bmingles committed Jan 2, 2025
1 parent ca5f6cd commit 5269b19
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"@react-spectrum/theme-default": "^3.5.1",
"@react-spectrum/toast": "^3.0.0-beta.16",
"@react-spectrum/utils": "^3.11.5",
"@react-types/combobox": "3.13.1",
"@react-types/radio": "^3.8.1",
"@react-types/shared": "^3.22.1",
"@react-types/textfield": "^3.9.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/spectrum/comboBox/ComboBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type { NormalizedItem } from '../utils';
import { type PickerPropsT, usePickerProps } from '../picker';

export type ComboBoxProps = PickerPropsT<SpectrumComboBoxProps<NormalizedItem>>;

export { type MenuTriggerAction } from '@react-types/combobox';
export { SpectrumComboBox };

export const ComboBox = React.forwardRef(function ComboBox(
Expand Down
32 changes: 31 additions & 1 deletion packages/jsapi-components/src/spectrum/ComboBox.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import {
ComboBoxNormalized,
type MenuTriggerAction,
type NormalizedItem,
type SpectrumComboBoxProps,
} from '@deephaven/components';
import { useCallback } from 'react';
import { useCallback, useRef } from 'react';
import { type PickerWithTableProps } from './PickerProps';
import { usePickerProps } from './utils';

Expand All @@ -18,19 +19,48 @@ export function ComboBox(props: ComboBoxProps): JSX.Element {
...pickerProps
} = usePickerProps<ComboBoxProps>(props);

const menuTriggerActionRef = useRef<MenuTriggerAction>();

const onInputChange = useCallback(
(value: string) => {
onInputChangeInternal?.(value);

onSearchTextChange(value);

// const searchText = menuTriggerActionRef.current === 'input' ? value : '';

console.log('[TESTING]', menuTriggerActionRef.current, value);

Check warning on line 32 in packages/jsapi-components/src/spectrum/ComboBox.tsx

View workflow job for this annotation

GitHub Actions / unit

Unexpected console statement

// We want the ComboBox to show all items whenever it is initially opened,
// so keep search text set to empty string while it is closed. This is
// mostly to handle the intial state, since `onInputChange` gets called
// before the user has interacted.
// onSearchTextChange(isOpenRef.current ? value : '');
},
[onInputChangeInternal, onSearchTextChange]
);

const onOpenChange = useCallback(
(isOpen: boolean, menuTrigger?: MenuTriggerAction) => {
console.log('[TESTING] onOpenChange', isOpen, menuTrigger);

Check warning on line 45 in packages/jsapi-components/src/spectrum/ComboBox.tsx

View workflow job for this annotation

GitHub Actions / unit

Unexpected console statement
menuTriggerActionRef.current = isOpen ? menuTrigger : undefined;

pickerProps.onOpenChange?.(isOpen);

// Clear filtering on close so that all items show on next open
if (!isOpen) {
onSearchTextChange('');
}
},
[onSearchTextChange, pickerProps]
);

return (
<ComboBoxNormalized
// eslint-disable-next-line react/jsx-props-no-spreading
{...pickerProps}
onInputChange={onInputChange}
onOpenChange={onOpenChange}
/>
);
}
Expand Down

0 comments on commit 5269b19

Please sign in to comment.