Skip to content

Commit 8ee3cea

Browse files
committed
buildMenuOptions only when menu is opened
1 parent b37edfd commit 8ee3cea

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/Select.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ export default class Select extends Component<Props, State> {
369369
'react-select-' + (this.props.instanceId || ++instanceId);
370370

371371
const selectValue = cleanValue(value);
372-
const menuOptions = this.buildMenuOptions(props, selectValue);
372+
const menuOptions = props.menuIsOpen ? this.buildMenuOptions(props, selectValue) : { render: [], focusable: [] };
373373

374374
this.state.menuOptions = menuOptions;
375375
this.state.selectValue = selectValue;
@@ -388,17 +388,18 @@ export default class Select extends Component<Props, State> {
388388
}
389389
}
390390
componentWillReceiveProps(nextProps: Props) {
391-
const { options, value, inputValue } = this.props;
391+
const { options, value, menuIsOpen, inputValue } = this.props;
392392
// re-cache custom components
393393
this.cacheComponents(nextProps.components);
394394
// rebuild the menu options
395395
if (
396396
nextProps.value !== value ||
397397
nextProps.options !== options ||
398+
nextProps.menuIsOpen !== menuIsOpen ||
398399
nextProps.inputValue !== inputValue
399400
) {
400401
const selectValue = cleanValue(nextProps.value);
401-
const menuOptions = this.buildMenuOptions(nextProps, selectValue);
402+
const menuOptions = nextProps.menuIsOpen ? this.buildMenuOptions(nextProps, selectValue) : { render: [], focusable: [] };
402403
const focusedValue = this.getNextFocusedValue(selectValue);
403404
const focusedOption = this.getNextFocusedOption(menuOptions.focusable);
404405
this.setState({ menuOptions, selectValue, focusedOption, focusedValue });

0 commit comments

Comments
 (0)