File tree Expand file tree Collapse file tree 2 files changed +41
-2
lines changed
packages/react/src/combobox Expand file tree Collapse file tree 2 files changed +41
-2
lines changed Original file line number Diff line number Diff line change @@ -35,6 +35,41 @@ describe('<Combobox.Root />', () => {
3535 combobox : true ,
3636 } ) ;
3737
38+ it ( 'does not focus input when closing via trigger click (input inside popup)' , async ( ) => {
39+ const { user } = await render (
40+ < Combobox . Root items = { [ 'One' , 'Two' , 'Three' ] } >
41+ < Combobox . Trigger data-testid = "trigger" >
42+ < Combobox . Value />
43+ </ Combobox . Trigger >
44+ < Combobox . Portal >
45+ < Combobox . Positioner >
46+ < Combobox . Popup aria-label = "Demo" >
47+ < Combobox . Input data-testid = "input" />
48+ < Combobox . List >
49+ { ( item : string ) => (
50+ < Combobox . Item key = { item } value = { item } >
51+ { item }
52+ </ Combobox . Item >
53+ ) }
54+ </ Combobox . List >
55+ </ Combobox . Popup >
56+ </ Combobox . Positioner >
57+ </ Combobox . Portal >
58+ </ Combobox . Root > ,
59+ ) ;
60+
61+ const trigger = screen . getByTestId ( 'trigger' ) ;
62+ await user . click ( trigger ) ;
63+
64+ expect ( await screen . findByRole ( 'listbox' ) ) . not . to . equal ( null ) ;
65+
66+ const input = await screen . findByRole ( 'combobox' ) ;
67+ expect ( input ) . toHaveFocus ( ) ;
68+
69+ await user . click ( trigger ) ;
70+ expect ( trigger ) . toHaveFocus ( ) ;
71+ } ) ;
72+
3873 describe ( 'selection behavior' , ( ) => {
3974 describe ( 'single' , ( ) => {
4075 it ( 'should auto-close popup after selection when open state is uncontrolled' , async ( ) => {
Original file line number Diff line number Diff line change @@ -139,9 +139,13 @@ export const ComboboxTrigger = React.forwardRef(function ComboboxTrigger(
139139 return ;
140140 }
141141
142- store . state . setOpen ( ! open , createBaseUIEventDetails ( 'trigger-press' , event . nativeEvent ) ) ;
142+ const nextOpen = ! open ;
143+ store . state . setOpen (
144+ nextOpen ,
145+ createBaseUIEventDetails ( 'trigger-press' , event . nativeEvent ) ,
146+ ) ;
143147
144- if ( currentPointerTypeRef . current !== 'touch' ) {
148+ if ( nextOpen && currentPointerTypeRef . current !== 'touch' ) {
145149 store . state . inputRef . current ?. focus ( ) ;
146150 }
147151 } ,
You can’t perform that action at this time.
0 commit comments