| 66 | * @see Menu |
| 67 | */ |
| 68 | export default class Dropdown extends Component { |
| 69 | searchRef = createRef() |
| 70 | sizerRef = createRef() |
| 71 | ref = createRef() |
| 72 | |
| 73 | getInitialAutoControlledState() { |
| 74 | return { focus: false, searchQuery: '' } |
| 75 | } |
| 76 | |
| 77 | static getAutoControlledStateFromProps(nextProps, computedState, prevState) { |
| 78 | // These values are stored only for a comparison on next getAutoControlledStateFromProps() |
| 79 | const derivedState = { __options: nextProps.options, __value: computedState.value } |
| 80 | |
| 81 | // The selected index is only dependent: |
| 82 | const shouldComputeSelectedIndex = |
| 83 | // On value change |
| 84 | !shallowEqual(prevState.__value, computedState.value) || |
| 85 | // On option keys/values, we only check those properties to avoid recursive performance impacts. |
| 86 | // https://github.com/Semantic-Org/Semantic-UI-React/issues/3000 |
| 87 | !_.isEqual(getKeyAndValues(nextProps.options), getKeyAndValues(prevState.__options)) |
| 88 | |
| 89 | if (shouldComputeSelectedIndex) { |
| 90 | derivedState.selectedIndex = getSelectedIndex({ |
| 91 | additionLabel: nextProps.additionLabel, |
| 92 | additionPosition: nextProps.additionPosition, |
| 93 | allowAdditions: nextProps.allowAdditions, |
| 94 | deburr: nextProps.deburr, |
| 95 | multiple: nextProps.multiple, |
| 96 | search: nextProps.search, |
| 97 | selectedIndex: computedState.selectedIndex, |
| 98 | |
| 99 | value: computedState.value, |
| 100 | options: nextProps.options, |
| 101 | searchQuery: computedState.searchQuery, |
| 102 | }) |
| 103 | } |
| 104 | |
| 105 | return derivedState |
| 106 | } |
| 107 | |
| 108 | componentDidMount() { |
| 109 | debug('componentDidMount()') |
| 110 | const { open } = this.state |
| 111 | |
| 112 | if (open) { |
| 113 | this.open(null, false) |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | shouldComponentUpdate(nextProps, nextState) { |
| 118 | return !shallowEqual(nextProps, this.props) || !shallowEqual(nextState, this.state) |
| 119 | } |
| 120 | |
| 121 | componentDidUpdate(prevProps, prevState) { |
| 122 | // eslint-disable-line complexity |
| 123 | debug('componentDidUpdate()') |
| 124 | debug('to state:', objectDiff(prevState, this.state)) |
| 125 |
nothing calls this directly
no test coverage detected
searching dependent graphs…