File tree Expand file tree Collapse file tree 2 files changed +26
-1
lines changed
Expand file tree Collapse file tree 2 files changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -561,5 +561,28 @@ describe('<Combobox />', () => {
561561
562562 assert . deepStrictEqual ( value , [ ] ) ;
563563 } ) ;
564+
565+ it ( 'should remove invalid option from value' , ( ) => {
566+ let value = [ 1 , 2 , 999 ] ;
567+ const mockOnChange = ( v ) => {
568+ value = v ;
569+ } ;
570+ render ( < Combobox options = { OPTIONS } value = { value } onChange = { mockOnChange } multi /> ) ;
571+
572+ const removeOptionButtonOne = screen . getByRole ( 'button' , {
573+ name : / r e m o v e o p t i o n : 1 / i,
574+ } ) ;
575+ within ( removeOptionButtonOne ) . getByText ( / r 2 - d 2 / i) ;
576+
577+ const removeOptionButtonTwo = screen . getByRole ( 'button' , {
578+ name : / r e m o v e o p t i o n : 2 / i,
579+ } ) ;
580+ within ( removeOptionButtonTwo ) . getByText ( / b b 8 / i) ;
581+
582+ const removeOptionButtonInvalid = screen . queryByRole ( 'button' , {
583+ name : / r e m o v e o p t i o n : 9 9 9 / i,
584+ } ) ;
585+ expect ( removeOptionButtonInvalid ) . not . toBeInTheDocument ( ) ;
586+ } ) ;
564587 } ) ;
565588} ) ;
Original file line number Diff line number Diff line change @@ -95,7 +95,9 @@ function Combobox<T>({
9595 const selected = useMemo < Option < T > | Option < T > [ ] > (
9696 ( ) =>
9797 multi
98- ? ( value || [ ] ) . map ( ( v : T ) => options . find ( ( option ) => equal ( option . value , v ) ) )
98+ ? ( value || [ ] )
99+ . map ( ( v : T ) => options . find ( ( option ) => equal ( option . value , v ) ) )
100+ . filter ( ( option : Option < T > ) => option !== undefined )
99101 : options . find ( ( option ) => equal ( option . value , value ) ) ,
100102 [ value , options , multi ]
101103 ) ;
You can’t perform that action at this time.
0 commit comments