Skip to content

Commit

Permalink
Update logic for detecting changes in Combobox items
Browse files Browse the repository at this point in the history
  • Loading branch information
ketsappi committed Mar 16, 2021
1 parent 0695f56 commit 576e769
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/core/Form/Combobox/Combobox/Combobox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ interface ComboboxState<T extends ComboboxData> {
currentSelection: string | null;
selectedKeys: SelectedItemKeys;
selectedItems: T[];
initialItems: T[];
}

function getSelectedKeys<T>(items: (T & ComboboxData)[]): SelectedItemKeys {
Expand Down Expand Up @@ -112,16 +113,18 @@ class BaseCombobox<T> extends Component<ComboboxProps<T & ComboboxData>> {
currentSelection: null,
selectedKeys: getSelectedKeys(this.props.defaultSelectedItems || []),
selectedItems: this.props.defaultSelectedItems || [],
initialItems: this.props.items,
};

static getDerivedStateFromProps<U>(
nextProps: ComboboxProps<U & ComboboxData>,
prevState: ComboboxState<U & ComboboxData>,
) {
const { items: propItems } = nextProps;
if (prevState.filteredItems !== propItems) {
if (propItems !== prevState.initialItems) {
return {
filteredItems: propItems,
initialItems: propItems,
};
}
return null;
Expand Down

0 comments on commit 576e769

Please sign in to comment.