Skip to content
This repository was archived by the owner on Mar 4, 2020. It is now read-only.

Commit 161ab7d

Browse files
committed
addressed comments
1 parent d541131 commit 161ab7d

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

packages/react/src/components/Dropdown/Dropdown.tsx

+13-12
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)