Skip to content

Commit 22e1374

Browse files
committed
fix(CNavGroup): improve open group handling
1 parent d34c873 commit 22e1374

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

packages/coreui-react/src/components/nav/CNavGroup.tsx

+9-2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ export interface CNavGroupProps {
3636
idx?: string
3737
}
3838

39+
const isInVisibleGroup = (el1: string, el2: string) => {
40+
const array1 = el1.toString().split('.')
41+
const array2 = el2.toString().split('.')
42+
43+
return array2.every((item, index) => item === array1[index])
44+
}
45+
3946
export const CNavGroup = forwardRef<HTMLLIElement, CNavGroupProps>(
4047
({ children, className, compact, idx, toggler, visible, ...rest }, ref) => {
4148
const [height, setHeight] = useState<number | string>()
@@ -45,12 +52,12 @@ export const CNavGroup = forwardRef<HTMLLIElement, CNavGroupProps>(
4552

4653
const [_visible, setVisible] = useState(
4754
Boolean(
48-
visible || (idx && visibleGroup && visibleGroup.toString().startsWith(idx.toString())),
55+
visible || (idx && visibleGroup && isInVisibleGroup(visibleGroup, idx)),
4956
),
5057
)
5158

5259
useEffect(() => {
53-
setVisible(Boolean(idx && visibleGroup && visibleGroup.toString().startsWith(idx.toString())))
60+
setVisible(Boolean(idx && visibleGroup && isInVisibleGroup(visibleGroup, idx)))
5461
}, [visibleGroup])
5562

5663
const handleTogglerOnCLick = (event: React.MouseEvent<HTMLElement>) => {

0 commit comments

Comments
 (0)