@@ -31,12 +31,20 @@ const cls = classes();
3131export const TagPicker = observer ( function TagPicker ( props : TagPickerProps ) : React . ReactElement {
3232 const [ inputContainerId , helperText1 ] = [ useId ( ) , useId ( ) ] ;
3333 const { showCheckboxes, selectedStyle = "boxes" , ariaLabel : inputLabel = "Search" } = props ;
34- const inputRef = useRef < HTMLInputElement > ( null ) ;
34+ const inputContainerRef = useRef < HTMLDivElement > ( null ) ;
3535 const { getSelectedItemProps, getDropdownProps, removeSelectedItem } = useMultipleSelection (
3636 props . useMultipleSelectionProps ( )
3737 ) ;
38- const { inputValue, isOpen, highlightedIndex, getInputProps, getToggleButtonProps, getMenuProps, getItemProps } =
39- useCombobox ( props . useComboboxProps ( ) ) ;
38+ const {
39+ inputValue,
40+ isOpen,
41+ highlightedIndex,
42+ getInputProps,
43+ getToggleButtonProps,
44+ getMenuProps,
45+ getItemProps,
46+ openMenu
47+ } = useCombobox ( props . useComboboxProps ( ) ) ;
4048 const { refs, floatingStyles } = useFloatingMenu ( isOpen ) ;
4149
4250 return (
@@ -54,19 +62,16 @@ export const TagPicker = observer(function TagPicker(props: TagPickerProps): Rea
5462 data-expanded = { isOpen }
5563 data-empty = { props . empty ? true : undefined }
5664 style = { props . style }
65+ onClick = { event => {
66+ if ( ! isOpen && ( event . target === event . currentTarget || event . target === inputContainerRef . current ) ) {
67+ openMenu ( ) ;
68+ }
69+ } }
5770 >
5871 < span id = { helperText1 } className = "sr-only" >
5972 Current filter values:
6073 </ span >
61- < div
62- id = { inputContainerId }
63- className = { cls . inputContainer }
64- onClick = { event => {
65- if ( event . currentTarget === event . target ) {
66- inputRef . current ?. focus ( ) ;
67- }
68- } }
69- >
74+ < div id = { inputContainerId } className = { cls . inputContainer } ref = { inputContainerRef } >
7075 { selectedStyle === "boxes" &&
7176 props . selected . map ( ( item , index ) => (
7277 < div
@@ -93,7 +98,7 @@ export const TagPicker = observer(function TagPicker(props: TagPickerProps): Rea
9398 onBlur : props . onBlur ,
9499 onFocus : props . onFocus ,
95100 placeholder : props . empty ? props . inputPlaceholder : undefined ,
96- ...getDropdownProps ( { preventKeyAction : isOpen , ref : inputRef } ) ,
101+ ...getDropdownProps ( { preventKeyAction : isOpen } ) ,
97102 "aria-describedby" : props . empty ? undefined : `${ helperText1 } ${ inputContainerId } `
98103 } ) }
99104 />
0 commit comments