diff --git a/react/src/Sidebar/SidebarList.tsx b/react/src/Sidebar/SidebarList.tsx index fdcda78d..0cf794a0 100644 --- a/react/src/Sidebar/SidebarList.tsx +++ b/react/src/Sidebar/SidebarList.tsx @@ -1,9 +1,10 @@ -import { type PropsWithChildren, useCallback, useMemo } from 'react' +import { FC, type PropsWithChildren, useCallback, useMemo } from 'react' import { Box, chakra, Collapse, forwardRef, + HTMLChakraProps, Icon, useDisclosure, type UseDisclosureReturn, @@ -54,6 +55,37 @@ export interface SidebarListProps extends BaseSidebarItemProps { onClick?: () => void } +type SectionWrapperProps = HTMLChakraProps<'button'> & + HTMLChakraProps<'div'> & { onlyCaretToggle: boolean } + +const SectionWrapper: FC = ({ + children, + onlyCaretToggle, + ...props +}) => { + if (onlyCaretToggle) return {children} + + return ( + + {children} + + ) +} +const ToggleChevronWrapper: FC = ({ + children, + onlyCaretToggle, + ...props +}) => { + if (onlyCaretToggle) + return ( + + {children} + + ) + + return {children} +} + export const SidebarList = forwardRef< PropsWithChildren, 'li' @@ -104,16 +136,6 @@ export const SidebarList = forwardRef< return merge({}, mergedStyles, { cursor: 'pointer' }) }, [onlyCaretToggle, styles.item, styles.parent]) - const SectionWrapper = useMemo(() => { - if (onlyCaretToggle) return chakra.div - return chakra.button - }, [onlyCaretToggle]) - - const ToggleChevronWrapper = useMemo(() => { - if (onlyCaretToggle) return chakra.button - return chakra.div - }, [onlyCaretToggle]) - return ( @@ -122,6 +144,7 @@ export const SidebarList = forwardRef< data-expanded={dataAttr(isOpen)} data-active={dataAttr(dataActive)} onClick={handleExpandSection} + onlyCaretToggle={onlyCaretToggle} > {icon ? ( @@ -129,12 +152,14 @@ export const SidebarList = forwardRef< ) : null} {label} +