@@ -367,6 +367,17 @@ export default class Select extends Component<Props, State> {
367
367
'react-select-' + ( this . props . instanceId || ++ instanceId ) ;
368
368
369
369
const selectValue = cleanValue ( value ) ;
370
+
371
+ this . buildMenuOptions = memoizeOne (
372
+ this . buildMenuOptions ,
373
+ ( newArgs : any , lastArgs : any ) => {
374
+ const [ newProps , newSelectValue ] = ( newArgs : [ Props , OptionsType ] ) ;
375
+ const [ lastProps , lastSelectValue ] = ( lastArgs : [ Props , OptionsType ] ) ;
376
+
377
+ return isEqual ( newSelectValue , lastSelectValue )
378
+ && isEqual ( newProps . inputValue , lastProps . inputValue )
379
+ && isEqual ( newProps . options , lastProps . options ) ;
380
+ } ) . bind ( this ) ;
370
381
const menuOptions = props . menuIsOpen
371
382
? this . buildMenuOptions ( props , selectValue )
372
383
: { render : [ ] , focusable : [ ] } ;
@@ -434,8 +445,8 @@ export default class Select extends Component<Props, State> {
434
445
this . scrollToFocusedOptionOnUpdate
435
446
) {
436
447
scrollIntoView ( this . menuListRef , this . focusedOptionRef ) ;
448
+ this . scrollToFocusedOptionOnUpdate = false ;
437
449
}
438
- this . scrollToFocusedOptionOnUpdate = false ;
439
450
}
440
451
componentWillUnmount ( ) {
441
452
this . stopListeningComposition ( ) ;
@@ -483,7 +494,8 @@ export default class Select extends Component<Props, State> {
483
494
blur = this . blurInput ;
484
495
485
496
openMenu ( focusOption : 'first' | 'last' ) {
486
- const { menuOptions , selectValue , isFocused } = this . state ;
497
+ const { selectValue , isFocused } = this . state ;
498
+ const menuOptions = this . buildMenuOptions ( this . props , selectValue ) ;
487
499
const { isMulti } = this . props ;
488
500
let openAtIndex =
489
501
focusOption === 'first' ? 0 : menuOptions . focusable . length - 1 ;
@@ -499,13 +511,14 @@ export default class Select extends Component<Props, State> {
499
511
this . scrollToFocusedOptionOnUpdate = ! ( isFocused && this . menuListRef ) ;
500
512
this . inputIsHiddenAfterUpdate = false ;
501
513
502
- this . onMenuOpen ( ) ;
503
514
this . setState ( {
515
+ menuOptions,
504
516
focusedValue : null ,
505
517
focusedOption : menuOptions . focusable [ openAtIndex ] ,
518
+ } , ( ) => {
519
+ this . onMenuOpen ( ) ;
520
+ this . announceAriaLiveContext ( { event : 'menu' } ) ;
506
521
} ) ;
507
-
508
- this . announceAriaLiveContext ( { event : 'menu' } ) ;
509
522
}
510
523
focusValue ( direction : 'previous' | 'next' ) {
511
524
const { isMulti , isSearchable } = this . props ;
@@ -1278,7 +1291,7 @@ export default class Select extends Component<Props, State> {
1278
1291
// Menu Options
1279
1292
// ==============================
1280
1293
1281
- buildMenuOptions ( props : Props , selectValue : OptionsType ) : MenuOptions {
1294
+ buildMenuOptions = ( props : Props , selectValue : OptionsType ) : MenuOptions => {
1282
1295
const { inputValue = '' , options } = props ;
1283
1296
1284
1297
const toOption = ( option , id ) => {
0 commit comments