Components: TreeSelectControl - Make sure individuallySelectParent value is preserved (#40301)

* make sure individually selected parent value is preserved

* Add changefile(s) from automation for the following project(s): @woocommerce/components

---------

Co-authored-by: github-actions <github-actions@github.com>
This commit is contained in:
Paul Sealock 2023-09-22 10:20:08 +12:00 committed by GitHub
parent bdbd590819
commit fb557cf21f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 2 deletions

View File

@ -0,0 +1,4 @@
Significance: patch
Type: fix
TreeSelectControl Component - Make sure individuallySelectParent prop is respected

View File

@ -234,7 +234,10 @@ const TreeSelectControl = ( {
* @return {boolean} True if checked, false otherwise.
*/
get() {
if ( includeParent && this.value !== ROOT_VALUE ) {
if (
( includeParent || individuallySelectParent ) &&
this.value !== ROOT_VALUE
) {
return cache.selectedValues.includes( this.value );
}
if ( this.hasChildren ) {
@ -427,7 +430,7 @@ const TreeSelectControl = ( {
const handleParentChange = ( checked, option ) => {
let newValue;
const changedValues = individuallySelectParent
? []
? [ option.value ]
: option.leaves
.filter( ( opt ) => opt.checked !== checked )
.map( ( opt ) => opt.value );

View File

@ -96,6 +96,7 @@ Base.args = {
selectAllLabel: 'All countries',
includeParent: false,
alwaysShowPlaceholder: false,
individuallySelectParent: false,
};
Base.argTypes = {