in src/select/select.tsx [443:535]
filterValue: getValueForFilter(selected, type, filterValue),
});
}
if (prevMultiple !== multiple && !dequal(prevMultiple, multiple)) {
nextState.selected = multiple ? [] : null;
}
if (multiple && !nextState.selected) {
nextState.selected = prevState.selected;
}
const {selected} = {...prevState, ...nextState};
if (selected && Array.isArray(selected)) {
nextState.multipleMap = buildMultipleMap(selected);
const {filteredData, addButton} = getListItems(nextProps, nextState, filterValue, data);
Object.assign(nextState, {shownData: filteredData, addButton});
}
const isSelectionEmpty =
nextProps.selected === null ||
nextProps.selected === undefined ||
(Array.isArray(nextProps.selected) && nextProps.selected.length === 0);
if (isSelectionEmpty) {
nextState.lastInteractedKey = null;
}
return nextState;
}
state: SelectState<T> = {
data: [],
shownData: [],
selected: this.props.multiple ? [] : null,
lastInteractedKey: null,
filterValue: (this.props.filter && typeof this.props.filter === 'object' && this.props.filter.value) || '',
shortcutsEnabled: false,
popupShortcuts: false,
showPopup: this.props.showPopup,
prevData: [],
prevSelected: null,
prevMultiple: this.props.multiple,
multipleMap: {},
addButton: null,
};
componentDidUpdate(prevProps: SelectProps<T>, prevState: SelectState<T>) {
const {showPopup, selected} = this.state;
const {onClose, onOpen, onChange, multiple} = this.props;
if (prevState.showPopup && !showPopup) {
(onClose as (s: typeof selected) => void)(selected);
} else if (!prevState.showPopup && showPopup) {
onOpen();
}
if (multiple !== prevProps.multiple && !dequal(multiple, prevProps.multiple)) {
(onChange as (s: typeof selected) => void)(selected);
}
}
static contextType = ControlsHeightContext;
declare context: React.ContextType<typeof ControlsHeightContext>;
static Type = Type;
static Size = Size;
id = getUID('select-');
shortcutsScope = this.id;
listId = `${this.id}:list`;
private _focusHandler = (e: React.FocusEvent<HTMLInputElement>) => {
this.props.onFocus(e);
this.setState({
shortcutsEnabled: true,
focused: true,
});
};
isClickingSelect = false;
mouseDownHandler = () => {
this.isClickingSelect = true;
};
mouseUpHandler = () => {
this.isClickingSelect = false;
};
private _blurHandler = () => {
this.props.onBlur();
if (this._popup && this._popup.isVisible() && !this._popup.isClickingPopup && !this.isClickingSelect) {
window.setTimeout(() => {