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:
parent
bdbd590819
commit
fb557cf21f
|
@ -0,0 +1,4 @@
|
|||
Significance: patch
|
||||
Type: fix
|
||||
|
||||
TreeSelectControl Component - Make sure individuallySelectParent prop is respected
|
|
@ -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 );
|
||||
|
|
|
@ -96,6 +96,7 @@ Base.args = {
|
|||
selectAllLabel: 'All countries',
|
||||
includeParent: false,
|
||||
alwaysShowPlaceholder: false,
|
||||
individuallySelectParent: false,
|
||||
};
|
||||
|
||||
Base.argTypes = {
|
||||
|
|
Loading…
Reference in New Issue