MCPcopy
hub / github.com/JedWatson/react-select / componentDidUpdate

Method componentDidUpdate

packages/react-select/src/Select.tsx:824–861  ·  view source on GitHub ↗
(prevProps: Props<Option, IsMulti, Group>)

Source from the content-addressed store, hash-verified

822 }
823 }
824 componentDidUpdate(prevProps: Props<Option, IsMulti, Group>) {
825 const { isDisabled, menuIsOpen } = this.props;
826 const { isFocused } = this.state;
827
828 if (
829 // ensure focus is restored correctly when the control becomes enabled
830 (isFocused && !isDisabled && prevProps.isDisabled) ||
831 // ensure focus is on the Input when the menu opens
832 (isFocused && menuIsOpen && !prevProps.menuIsOpen)
833 ) {
834 this.focusInput();
835 }
836
837 if (isFocused && isDisabled && !prevProps.isDisabled) {
838 // ensure select state gets blurred in case Select is programmatically disabled while focused
839 // eslint-disable-next-line react/no-did-update-set-state
840 this.setState({ isFocused: false }, this.onMenuClose);
841 } else if (
842 !isFocused &&
843 !isDisabled &&
844 prevProps.isDisabled &&
845 this.inputRef === document.activeElement
846 ) {
847 // ensure select state gets focused in case Select is programatically re-enabled while focused (Firefox)
848 // eslint-disable-next-line react/no-did-update-set-state
849 this.setState({ isFocused: true });
850 }
851
852 // scroll the focused option into view if necessary
853 if (
854 this.menuListRef &&
855 this.focusedOptionRef &&
856 this.scrollToFocusedOptionOnUpdate
857 ) {
858 scrollIntoView(this.menuListRef, this.focusedOptionRef);
859 this.scrollToFocusedOptionOnUpdate = false;
860 }
861 }
862 componentWillUnmount() {
863 this.stopListeningComposition();
864 this.stopListeningToTouch();

Callers

nothing calls this directly

Calls 2

focusInputMethod · 0.95
scrollIntoViewFunction · 0.90

Tested by

no test coverage detected