File tree Expand file tree Collapse file tree
packages/react/src/components/ComboBox Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -202,6 +202,30 @@ describe('ComboBox', () => {
202202 } ) ;
203203 } ) ;
204204
205+ it ( 'should call `onChange` when a highlighted item is committed on Tab' , async ( ) => {
206+ const user = userEvent . setup ( ) ;
207+
208+ render (
209+ < >
210+ < ComboBox { ...mockProps } />
211+ < button type = "button" > Next focus target</ button >
212+ </ >
213+ ) ;
214+
215+ await user . click ( findInputNode ( ) ) ;
216+ await user . type ( findInputNode ( ) , 'Item' ) ;
217+ await user . keyboard ( '[ArrowDown]' ) ;
218+ await user . keyboard ( '[Tab]' ) ;
219+
220+ expect ( mockProps . onChange ) . toHaveBeenCalledTimes ( 1 ) ;
221+ expect ( mockProps . onChange ) . toHaveBeenCalledWith ( {
222+ selectedItem : mockProps . items [ 1 ] ,
223+ } ) ;
224+ expect (
225+ screen . getByRole ( 'button' , { name : 'Next focus target' } )
226+ ) . toHaveFocus ( ) ;
227+ } ) ;
228+
205229 describe ( 'onInputChange' , ( ) => {
206230 let onInputChange ;
207231 beforeEach ( ( ) => {
Original file line number Diff line number Diff line change @@ -895,9 +895,10 @@ const ComboBox = forwardRef(
895895 if (
896896 ( type === ItemClick ||
897897 type === FunctionSelectItem ||
898- type === InputKeyDownEnter ) &&
898+ type === InputKeyDownEnter ||
899+ ( ! allowCustomValue && type === InputBlur ) ) &&
899900 typeof newSelectedItem !== 'undefined' &&
900- ! isEqual ( selectedItemProp , newSelectedItem )
901+ ! isEqual ( currentSelectedItem , newSelectedItem )
901902 ) {
902903 if ( items . some ( ( item ) => isEqual ( item , newSelectedItem ) ) ) {
903904 committedCustomValueRef . current = '' ;
You can’t perform that action at this time.
0 commit comments