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.
|
* @return {boolean} True if checked, false otherwise.
|
||||||
*/
|
*/
|
||||||
get() {
|
get() {
|
||||||
if ( includeParent && this.value !== ROOT_VALUE ) {
|
if (
|
||||||
|
( includeParent || individuallySelectParent ) &&
|
||||||
|
this.value !== ROOT_VALUE
|
||||||
|
) {
|
||||||
return cache.selectedValues.includes( this.value );
|
return cache.selectedValues.includes( this.value );
|
||||||
}
|
}
|
||||||
if ( this.hasChildren ) {
|
if ( this.hasChildren ) {
|
||||||
|
@ -427,7 +430,7 @@ const TreeSelectControl = ( {
|
||||||
const handleParentChange = ( checked, option ) => {
|
const handleParentChange = ( checked, option ) => {
|
||||||
let newValue;
|
let newValue;
|
||||||
const changedValues = individuallySelectParent
|
const changedValues = individuallySelectParent
|
||||||
? []
|
? [ option.value ]
|
||||||
: option.leaves
|
: option.leaves
|
||||||
.filter( ( opt ) => opt.checked !== checked )
|
.filter( ( opt ) => opt.checked !== checked )
|
||||||
.map( ( opt ) => opt.value );
|
.map( ( opt ) => opt.value );
|
||||||
|
|
|
@ -96,6 +96,7 @@ Base.args = {
|
||||||
selectAllLabel: 'All countries',
|
selectAllLabel: 'All countries',
|
||||||
includeParent: false,
|
includeParent: false,
|
||||||
alwaysShowPlaceholder: false,
|
alwaysShowPlaceholder: false,
|
||||||
|
individuallySelectParent: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
Base.argTypes = {
|
Base.argTypes = {
|
||||||
|
|
Loading…
Reference in New Issue