: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
this.timeoutIds.push(id);
this.setItemCount = count => {
this.unsetItemCount = () => {
this.setHighlightedIndex = function (highlightedIndex, otherStateToSet) {
if (highlightedIndex === void 0) {
highlightedIndex = _this.props.defaultHighlightedIndex;
if (otherStateToSet === void 0) {
otherStateToSet = pickState(otherStateToSet);
this.clearSelection = cb => {
highlightedIndex: this.props.defaultHighlightedIndex,
isOpen: this.props.defaultIsOpen
this.selectItem = (item, otherStateToSet, cb) => {
otherStateToSet = pickState(otherStateToSet);
isOpen: this.props.defaultIsOpen,
highlightedIndex: this.props.defaultHighlightedIndex,
inputValue: this.props.itemToString(item),
this.selectItemAtIndex = (itemIndex, otherStateToSet, cb) => {
const item = this.items[itemIndex];
this.selectItem(item, otherStateToSet, cb);
this.selectHighlightedItem = (otherStateToSet, cb) => {
return this.selectItemAtIndex(this.getState().highlightedIndex, otherStateToSet, cb);
this.internalSetState = (stateToSet, cb) => {
let isItemSelected, onChangeArg;
const onStateChangeArg = {};
const isStateToSetFunction = typeof stateToSet === 'function'; // we want to call `onInputValueChange` before the `setState` call
// so someone controlling the `inputValue` state gets notified of
// the input change as soon as possible. This avoids issues with
// preserving the cursor position.
// See https://github.com/downshift-js/downshift/issues/217 for more info.
if (!isStateToSetFunction && stateToSet.hasOwnProperty('inputValue')) {
this.props.onInputValueChange(stateToSet.inputValue, { ...this.getStateAndHelpers(),
return this.setState(state => {
state = this.getState(state);
let newStateToSet = isStateToSetFunction ? stateToSet(state) : stateToSet; // Your own function that could modify the state that will be set.
newStateToSet = this.props.stateReducer(state, newStateToSet); // checks if an item is selected, regardless of if it's different from
// what was selected before
// used to determine if onSelect and onChange callbacks should be called
isItemSelected = newStateToSet.hasOwnProperty('selectedItem'); // this keeps track of the object we want to call with setState
const nextState = {}; // this is just used to tell whether the state changed
// and we're trying to update that state. OR if the selection has changed and we're
// trying to update the selection
if (isItemSelected && newStateToSet.selectedItem !== state.selectedItem) {
onChangeArg = newStateToSet.selectedItem;
newStateToSet.type = newStateToSet.type || unknown;
Object.keys(newStateToSet).forEach(key => {
// onStateChangeArg should only have the state that is
if (state[key] !== newStateToSet[key]) {
onStateChangeArg[key] = newStateToSet[key];
} // the type is useful for the onStateChangeArg
// but we don't actually want to set it in internal state.
// this is an undocumented feature for now... Not all internalSetState
// calls support it and I'm not certain we want them to yet.
// But it enables users controlling the isOpen state to know when
// the isOpen state changes due to mouseup events which is quite handy.
newStateToSet[key]; // if it's coming from props, then we don't care to set it internally
if (!isControlledProp(this.props, key)) {
nextState[key] = newStateToSet[key];
}); // if stateToSet is a function, then we weren't able to call onInputValueChange
// earlier, so we'll call it now that we know what the inputValue state will be.
if (isStateToSetFunction && newStateToSet.hasOwnProperty('inputValue')) {
this.props.onInputValueChange(newStateToSet.inputValue, { ...this.getStateAndHelpers(),
// call the provided callback if it's a function
cbToCb(cb)(); // only call the onStateChange and onChange callbacks if
// we have relevant information to pass them.
const hasMoreStateThanType = Object.keys(onStateChangeArg).length > 1;
if (hasMoreStateThanType) {
this.props.onStateChange(onStateChangeArg, this.getStateAndHelpers());
this.props.onSelect(stateToSet.selectedItem, this.getStateAndHelpers());
if (onChangeArg !== undefined) {
this.props.onChange(onChangeArg, this.getStateAndHelpers());
} // this is currently undocumented and therefore subject to change
// We'll try to not break it, but just be warned.
this.props.onUserAction(onStateChangeArg, this.getStateAndHelpers());
this.rootRef = node => this._rootNode = node;
this.getRootProps = function (_temp, _temp2) {
} = _temp === void 0 ? {} : _temp;
} = _temp2 === void 0 ? {} : _temp2;
// this is used in the render to know whether the user has called getRootProps.
// It uses that to know whether to apply the props automatically
_this.getRootProps.called = true;
_this.getRootProps.refKey = refKey;
_this.getRootProps.suppressRefError = suppressRefError;
[refKey]: handleRefs(ref, _this.rootRef),
'aria-haspopup': 'listbox',
'aria-owns': isOpen ? _this.menuId : null,
'aria-labelledby': _this.labelId,
if (this.getState().isOpen) {
const amount = event.shiftKey ? 5 : 1;
this.moveHighlightedIndex(amount, {
const itemCount = this.getItemCount();
const nextHighlightedIndex = getNextWrappingIndex(1, highlightedIndex, itemCount, index => this.getItemNodeFromIndex(index));
this.setHighlightedIndex(nextHighlightedIndex, {
if (this.getState().isOpen) {
const amount = event.shiftKey ? -5 : -1;
this.moveHighlightedIndex(amount, {
const itemCount = this.getItemCount();
const nextHighlightedIndex = getNextWrappingIndex(-1, highlightedIndex, itemCount, index => this.getItemNodeFromIndex(index));
this.setHighlightedIndex(nextHighlightedIndex, {
if (event.which === 229) {
if (isOpen && highlightedIndex != null) {
const item = this.items[highlightedIndex];
const itemNode = this.getItemNodeFromIndex(highlightedIndex);
if (item == null || itemNode && itemNode.hasAttribute('disabled')) {
this.selectHighlightedItem({
...(!this.state.isOpen && {
this.buttonKeyDownHandlers = { ...this.keyDownHandlers,
this.inputKeyDownHandlers = { ...this.keyDownHandlers,
const itemCount = this.getItemCount();
if (itemCount <= 0 || !isOpen) {
} // get next non-disabled starting downwards from 0 if that's disabled.
const newHighlightedIndex = getNextNonDisabledIndex(1, 0, itemCount, index => this.getItemNodeFromIndex(index), false);
this.setHighlightedIndex(newHighlightedIndex, {
const itemCount = this.getItemCount();
if (itemCount <= 0 || !isOpen) {
} // get next non-disabled starting upwards from last index if that's disabled.
const newHighlightedIndex = getNextNonDisabledIndex(-1, itemCount - 1, itemCount, index => this.getItemNodeFromIndex(index), false);
this.setHighlightedIndex(newHighlightedIndex, {
this.getToggleButtonProps = function (_temp3) {
} = _temp3 === void 0 ? {} : _temp3;
const enabledEventHandlers = {
onClick: callAllEventHandlers(onClick, _this.buttonHandleClick),
onKeyDown: callAllEventHandlers(onKeyDown, _this.buttonHandleKeyDown),
onKeyUp: callAllEventHandlers(onKeyUp, _this.buttonHandleKeyUp),
onBlur: callAllEventHandlers(onBlur, _this.buttonHandleBlur)
const eventHandlers = rest.disabled ? {} : enabledEventHandlers;
'aria-label': isOpen ? 'close menu' : 'open menu',
this.buttonHandleKeyUp = event => {
// Prevent click event from emitting in Firefox
this.buttonHandleKeyDown = event => {
const key = normalizeArrowKey(event);
if (this.buttonKeyDownHandlers[key]) {
this.buttonKeyDownHandlers[key].call(this, event);
this.buttonHandleClick = event => {
event.preventDefault(); // handle odd case for Safari and Firefox which
// don't give the button the focus properly.
/* istanbul ignore if (can't reasonably test this) */
if (this.props.environment.document.activeElement === this.props.environment.document.body) {
} // to simplify testing components that use downshift, we'll not wrap this in a setTimeout
// if the NODE_ENV is test. With the proper build system, this should be dead code eliminated
// when building for production and should therefore have no impact on production code.
// Ensure that toggle of menu occurs after the potential blur event in iOS
this.internalSetTimeout(() => this.toggleMenu({
this.buttonHandleBlur = event => {
const blurTarget = event.target; // Save blur target for comparison with activeElement later
// Need setTimeout, so that when the user presses Tab, the activeElement is the next focused element, not body element
this.internalSetTimeout(() => {
if (!this.isMouseDown && (this.props.environment.document.activeElement == null || this.props.environment.document.activeElement.id !== this.inputId) && this.props.environment.document.activeElement !== blurTarget // Do nothing if we refocus the same element again (to solve issue in Safari on iOS)
this.getLabelProps = props => {
this.getInputProps = function (_temp4) {
} = _temp4 === void 0 ? {} : _temp4;
/* istanbul ignore next (preact) */
onChangeKey = 'onChange';
[onChangeKey]: callAllEventHandlers(onChange, onInput, _this.inputHandleChange),
onKeyDown: callAllEventHandlers(onKeyDown, _this.inputHandleKeyDown),
onBlur: callAllEventHandlers(onBlur, _this.inputHandleBlur)
'aria-autocomplete': 'list',
'aria-activedescendant': isOpen && typeof highlightedIndex === 'number' && highlightedIndex >= 0 ? _this.getItemId(highlightedIndex) : null,
'aria-controls': isOpen ? _this.menuId : null,
'aria-labelledby': _this.labelId,
// https://developer.mozilla.org/en-US/docs/Web/Security/Securing_your_site/Turning_off_form_autocompletion
// revert back since autocomplete="nope" is ignored on latest Chrome and Opera
this.inputHandleKeyDown = event => {
const key = normalizeArrowKey(event);
if (key && this.inputKeyDownHandlers[key]) {
this.inputKeyDownHandlers[key].call(this, event);
this.inputHandleChange = event => {
inputValue: event.target.value,
highlightedIndex: this.props.defaultHighlightedIndex
this.inputHandleBlur = () => {
// Need setTimeout, so that when the user presses Tab, the activeElement is the next focused element, not the body element
this.internalSetTimeout(() => {
const downshiftButtonIsActive = this.props.environment.document && !!this.props.environment.document.activeElement && !!this.props.environment.document.activeElement.dataset && this.props.environment.document.activeElement.dataset.toggle && this._rootNode && this._rootNode.contains(this.props.environment.document.activeElement);
if (!this.isMouseDown && !downshiftButtonIsActive) {