TreeSelectControl: Handle ROOT selection with individuallySelectParent (#40422)

* Handle selecting ROOT and includeParent

* changelog
This commit is contained in:
Paul Sealock 2023-09-27 16:14:13 +13:00 committed by GitHub
parent b6674ef0c1
commit 7b9abcc79a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 3 deletions

View File

@ -0,0 +1,5 @@
Significance: patch
Type: fix
Comment: Fixes and earlier unreleaed change, not changelog required

View File

@ -235,8 +235,8 @@ const TreeSelectControl = ( {
*/
get() {
if (
( includeParent || individuallySelectParent ) &&
this.value !== ROOT_VALUE
( includeParent && this.value !== ROOT_VALUE ) ||
individuallySelectParent
) {
return cache.selectedValues.includes( this.value );
}
@ -434,7 +434,16 @@ const TreeSelectControl = ( {
: option.leaves
.filter( ( opt ) => opt.checked !== checked )
.map( ( opt ) => opt.value );
if ( includeParent && option.value !== ROOT_VALUE ) {
/**
* If includeParent is true, we need to add the parent value to the array of
* changed values. However, if for some reason includeParent AND individuallySelectParent
* are both set to true, we want to avoid duplicating the parent value in the array.
*/
if (
includeParent &&
! individuallySelectParent &&
option.value !== ROOT_VALUE
) {
changedValues.push( option.value );
}
if ( checked ) {