@@ -331,7 +331,7 @@ function DualListBox(props) {
331
331
}
332
332
333
333
if ( direction === 'up' ) {
334
- // If all of the marked options are already as high as they can get, ignore the
334
+ // If all the marked options are already as high as they can get, ignore the
335
335
// re-arrangement request because they will end of swapping their order amongst
336
336
// themselves.
337
337
if ( markedOptions [ markedOptions . length - 1 ] . order > markedOptions . length - 1 ) {
@@ -342,8 +342,8 @@ function DualListBox(props) {
342
342
} ) ;
343
343
}
344
344
} else if ( direction === 'down' ) {
345
- // Similar to the above, if all of the marked options are already as low as they can
346
- // get, ignore the re-arrangement request.
345
+ // Similar to the above, if all the marked options are already as low as they can get,
346
+ // ignore the re-arrangement request.
347
347
if ( markedOptions [ 0 ] . order < selected . length - markedOptions . length ) {
348
348
markedOptions . reverse ( ) . forEach ( ( { order } ) => {
349
349
if ( order < selected . length - 1 ) {
@@ -388,7 +388,7 @@ function DualListBox(props) {
388
388
*
389
389
* @param {Array } options
390
390
*
391
- * @returns {Array }
391
+ * @returns {String[] }
392
392
*/
393
393
function makeOptionsSelectedRecursive ( options ) {
394
394
const { getOptionValue } = props ;
@@ -418,7 +418,7 @@ function DualListBox(props) {
418
418
*
419
419
* @param {Array } options
420
420
*
421
- * @returns {Array }
421
+ * @returns {String[] }
422
422
*/
423
423
function makeOptionsSelected ( options ) {
424
424
const availableOptions = filterAvailable ( options ) ;
@@ -432,24 +432,24 @@ function DualListBox(props) {
432
432
/**
433
433
* Recursively unselect the given options, except for those disabled.
434
434
*
435
- * @param {Array } selectedOptions
435
+ * @param {String[] } previousSelected
436
+ * @param {Array } optionsToRemove
436
437
*
437
- * @returns {Array }
438
+ * @returns {String[] }
438
439
*/
439
- function makeOptionsUnselectedRecursive ( selectedOptions ) {
440
+ function makeOptionsUnselectedRecursive ( previousSelected , optionsToRemove ) {
440
441
const { getOptionValue } = props ;
441
- let newSelected = [ ] ;
442
+ let newSelected = [ ... previousSelected ] ;
442
443
443
- selectedOptions . forEach ( ( option ) => {
444
+ optionsToRemove . forEach ( ( option ) => {
444
445
if ( option . options !== undefined ) {
445
446
// Traverse any parents for leaf options
446
- newSelected = [
447
- ...newSelected ,
448
- ...makeOptionsUnselectedRecursive ( option . options ) ,
449
- ] ;
450
- } else if ( option . disabled ) {
451
- // Preserve any disabled options
452
- newSelected . push ( getOptionValue ( option ) ) ;
447
+ newSelected = makeOptionsUnselectedRecursive ( newSelected , option . options ) ;
448
+ } else if ( ! option . disabled ) {
449
+ // Remove non-disabled options
450
+ newSelected = newSelected . filter ( ( oldValue ) => (
451
+ oldValue !== getOptionValue ( option )
452
+ ) ) ;
453
453
}
454
454
} ) ;
455
455
@@ -464,7 +464,7 @@ function DualListBox(props) {
464
464
* @returns {Array }
465
465
*/
466
466
function makeOptionsUnselected ( options ) {
467
- return makeOptionsUnselectedRecursive ( filterSelected ( options , true ) ) ;
467
+ return makeOptionsUnselectedRecursive ( selected , filterSelected ( options ) ) ;
468
468
}
469
469
470
470
/**
@@ -560,7 +560,7 @@ function DualListBox(props) {
560
560
}
561
561
562
562
onChange ( newSelected , marked , isToSelected ? 'available' : 'selected' , isRearrangement ) ;
563
- } , [ selected ] ) ;
563
+ } , [ selected , filter ] ) ;
564
564
565
565
/**
566
566
* @param {Object } event
0 commit comments