@@ -31,12 +31,20 @@ const cls = classes();
31
31
export const TagPicker = observer ( function TagPicker ( props : TagPickerProps ) : React . ReactElement {
32
32
const [ inputContainerId , helperText1 ] = [ useId ( ) , useId ( ) ] ;
33
33
const { showCheckboxes, selectedStyle = "boxes" , ariaLabel : inputLabel = "Search" } = props ;
34
- const inputRef = useRef < HTMLInputElement > ( null ) ;
34
+ const inputContainerRef = useRef < HTMLDivElement > ( null ) ;
35
35
const { getSelectedItemProps, getDropdownProps, removeSelectedItem } = useMultipleSelection (
36
36
props . useMultipleSelectionProps ( )
37
37
) ;
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 ( ) ) ;
40
48
const { refs, floatingStyles } = useFloatingMenu ( isOpen ) ;
41
49
42
50
return (
@@ -54,19 +62,16 @@ export const TagPicker = observer(function TagPicker(props: TagPickerProps): Rea
54
62
data-expanded = { isOpen }
55
63
data-empty = { props . empty ? true : undefined }
56
64
style = { props . style }
65
+ onClick = { event => {
66
+ if ( ! isOpen && ( event . target === event . currentTarget || event . target === inputContainerRef . current ) ) {
67
+ openMenu ( ) ;
68
+ }
69
+ } }
57
70
>
58
71
< span id = { helperText1 } className = "sr-only" >
59
72
Current filter values:
60
73
</ 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 } >
70
75
{ selectedStyle === "boxes" &&
71
76
props . selected . map ( ( item , index ) => (
72
77
< div
@@ -93,7 +98,7 @@ export const TagPicker = observer(function TagPicker(props: TagPickerProps): Rea
93
98
onBlur : props . onBlur ,
94
99
onFocus : props . onFocus ,
95
100
placeholder : props . empty ? props . inputPlaceholder : undefined ,
96
- ...getDropdownProps ( { preventKeyAction : isOpen , ref : inputRef } ) ,
101
+ ...getDropdownProps ( { preventKeyAction : isOpen } ) ,
97
102
"aria-describedby" : props . empty ? undefined : `${ helperText1 } ${ inputContainerId } `
98
103
} ) }
99
104
/>
0 commit comments