Skip to content

Commit 77e0089

Browse files
committed
fix: wrong height when nested groups
1 parent 7c665f4 commit 77e0089

File tree

1 file changed

+5
-11
lines changed

1 file changed

+5
-11
lines changed

src/components/nav/CNavGroup.tsx

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
1-
import React, {
2-
CSSProperties,
3-
forwardRef,
4-
ReactNode,
5-
useContext,
6-
useRef,
7-
useState,
8-
} from 'react'
1+
import React, { CSSProperties, forwardRef, ReactNode, useContext, useRef, useState } from 'react'
92
import PropTypes from 'prop-types'
103
import classNames from 'classnames'
114
import { Transition } from 'react-transition-group'
@@ -37,7 +30,7 @@ export interface CNavGroupProps {
3730

3831
export const CNavGroup = forwardRef<HTMLLIElement, CNavGroupProps>(
3932
({ children, toggler, className, icon, idx, visible, ...rest }, ref) => {
40-
const [height, setHeight] = useState<number>()
33+
const [height, setHeight] = useState<number | string>()
4134
const navItemsRef = useRef<HTMLUListElement>(null)
4235

4336
const style: CSSProperties = {
@@ -49,15 +42,16 @@ export const CNavGroup = forwardRef<HTMLLIElement, CNavGroupProps>(
4942
}
5043

5144
const onEntered = () => {
52-
// setHeight(0)
45+
setHeight('auto')
5346
}
5447

5548
const onExit = () => {
5649
navItemsRef && navItemsRef.current && setHeight(navItemsRef.current.scrollHeight)
5750
}
5851

5952
const onExiting = () => {
60-
// @ts-expect-error
53+
// @ts-expect-error reflow is necessary to get correct height of the element
54+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
6155
const reflow = navItemsRef && navItemsRef.current && navItemsRef.current.offsetHeight
6256
setHeight(0)
6357
}

0 commit comments

Comments
 (0)