From f3a9ce92c7dc9d3671757a092250aa4d60820d82 Mon Sep 17 00:00:00 2001 From: melloware Date: Tue, 28 Nov 2023 08:29:50 -0500 Subject: [PATCH] Fix #5425: CascadeSelect fix for StrictMode --- components/lib/cascadeselect/CascadeSelect.js | 1 + components/lib/cascadeselect/CascadeSelectSub.js | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/components/lib/cascadeselect/CascadeSelect.js b/components/lib/cascadeselect/CascadeSelect.js index fbcae4670c..e7291fa3f4 100644 --- a/components/lib/cascadeselect/CascadeSelect.js +++ b/components/lib/cascadeselect/CascadeSelect.js @@ -401,6 +401,7 @@ export const CascadeSelect = React.memo( optionGroupIcon={props.optionGroupIcon} optionLabel={props.optionLabel} optionValue={props.optionValue} + parentActive={props.value != null} level={0} optionGroupLabel={props.optionGroupLabel} optionGroupChildren={props.optionGroupChildren} diff --git a/components/lib/cascadeselect/CascadeSelectSub.js b/components/lib/cascadeselect/CascadeSelectSub.js index 803e691cdf..a80d179390 100644 --- a/components/lib/cascadeselect/CascadeSelectSub.js +++ b/components/lib/cascadeselect/CascadeSelectSub.js @@ -5,7 +5,7 @@ import { AngleRightIcon } from '../icons/angleright'; import { Ripple } from '../ripple/Ripple'; import { DomHandler, IconUtils, ObjectUtils, classNames, mergeProps } from '../utils/Utils'; export const CascadeSelectSub = React.memo((props) => { - const [activeOptionState, setActiveOptionState] = React.useState(null); + const [activeOptionState, setActiveOptionState] = React.useState(props.parentActive); const elementRef = React.useRef(null); const context = React.useContext(PrimeReactContext); const { ptm, cx } = props; @@ -173,7 +173,9 @@ export const CascadeSelectSub = React.memo((props) => { }); useUpdateEffect(() => { - setActiveOptionState(null); + if (!props.parentActive) { + setActiveOptionState(null); + } }, [props.parentActive]); const createSubmenu = (option) => {