in Dataset/JS/ReactSelect/index.tsx [818:855]
componentDidUpdate(prevProps: Props<Option, IsMulti, Group>) {
const { isDisabled, menuIsOpen } = this.props;
const { isFocused } = this.state;
if (
// ensure focus is restored correctly when the control becomes enabled
(isFocused && !isDisabled && prevProps.isDisabled) ||
// ensure focus is on the Input when the menu opens
(isFocused && menuIsOpen && !prevProps.menuIsOpen)
) {
this.focusInput();
}
if (isFocused && isDisabled && !prevProps.isDisabled) {
// ensure select state gets blurred in case Select is programmatically disabled while focused
// eslint-disable-next-line react/no-did-update-set-state
this.setState({ isFocused: false }, this.onMenuClose);
} else if (
!isFocused &&
!isDisabled &&
prevProps.isDisabled &&
this.inputRef === document.activeElement
) {
// ensure select state gets focused in case Select is programatically re-enabled while focused (Firefox)
// eslint-disable-next-line react/no-did-update-set-state
this.setState({ isFocused: true });
}
// scroll the focused option into view if necessary
if (
this.menuListRef &&
this.focusedOptionRef &&
this.scrollToFocusedOptionOnUpdate
) {
scrollIntoView(this.menuListRef, this.focusedOptionRef);
this.scrollToFocusedOptionOnUpdate = false;
}
}