@@ -593,7 +593,7 @@ class Dropdown extends AutoControlledComponent<Extendable<DropdownProps>, Dropdo
593593 }
594594
595595 private handleSearchQueryChange = ( searchQuery : string ) => {
596- this . setStateAndInvokeHandler ( { searchQuery } , 'onSearchQueryChange' )
596+ this . trySetStateAndInvokeHandler ( 'onSearchQueryChange' , null , { searchQuery } )
597597 }
598598
599599 private handleDownshiftStateChanges = (
@@ -614,7 +614,7 @@ class Dropdown extends AutoControlledComponent<Extendable<DropdownProps>, Dropdo
614614
615615 private handleStateChange = ( changes : StateChangeOptions < ShorthandValue > ) => {
616616 if ( changes . isOpen !== undefined && changes . isOpen !== this . state . open ) {
617- this . setStateAndInvokeHandler ( { open : changes . isOpen } , 'onOpenChange' )
617+ this . trySetStateAndInvokeHandler ( 'onOpenChange' , null , { open : changes . isOpen } )
618618 }
619619
620620 if ( changes . isOpen && ! this . props . search ) {
@@ -857,13 +857,10 @@ class Dropdown extends AutoControlledComponent<Extendable<DropdownProps>, Dropdo
857857 private handleSelectedChange = ( item : ShorthandValue ) => {
858858 const { items, multiple, getA11ySelectionMessage } = this . props
859859
860- this . setStateAndInvokeHandler (
861- {
862- value : multiple ? [ ...( this . state . value as ShorthandCollection ) , item ] : item ,
863- searchQuery : this . getSelectedItemAsString ( item ) ,
864- } ,
865- 'onSelectedChange' ,
866- )
860+ this . trySetStateAndInvokeHandler ( 'onSelectedChange' , null , {
861+ value : multiple ? [ ...( this . state . value as ShorthandCollection ) , item ] : item ,
862+ searchQuery : this . getSelectedItemAsString ( item ) ,
863+ } )
867864
868865 if ( ! multiple ) {
869866 this . setState ( { defaultHighlightedIndex : items . indexOf ( item ) } )
@@ -958,17 +955,21 @@ class Dropdown extends AutoControlledComponent<Extendable<DropdownProps>, Dropdo
958955 this . setA11yStatus ( getA11ySelectionMessage . onRemove ( poppedItem ) )
959956 }
960957
961- this . setStateAndInvokeHandler ( { value } , 'onSelectedChange' )
958+ this . trySetStateAndInvokeHandler ( 'onSelectedChange' , null , { value } )
962959 }
963960
964961 /**
965962 * Calls trySetState (for autoControlledProps) and invokes event handler exposed to user.
966963 * We don't have the event object for most events coming from Downshift se we send an empty event
967964 * because we want to keep the event handling interface
968965 */
969- private setStateAndInvokeHandler = ( newState : Partial < DropdownState > , eventName : string ) => {
966+ private trySetStateAndInvokeHandler = (
967+ handlerName : keyof DropdownProps ,
968+ event : React . SyntheticEvent < HTMLElement > ,
969+ newState : Partial < DropdownState > ,
970+ ) => {
970971 this . trySetState ( newState )
971- _ . invoke ( this . props , eventName , { } , { ...this . props , ...newState } )
972+ _ . invoke ( this . props , handlerName , event , { ...this . props , ...newState } )
972973 }
973974
974975 private tryFocusTriggerButton = ( ) => {
0 commit comments