diff --git a/packages/compass-connections-navigation/src/base-navigation-item.tsx b/packages/compass-connections-navigation/src/base-navigation-item.tsx index f4dfa113de4..8ad07bb1bb4 100644 --- a/packages/compass-connections-navigation/src/base-navigation-item.tsx +++ b/packages/compass-connections-navigation/src/base-navigation-item.tsx @@ -28,7 +28,7 @@ type NavigationBaseItemProps = { actions: NavigationItemActions; onAction: (action: Actions) => void; }; - onExpand: (toggle: boolean) => void; + toggleExpand: () => void; }; const menuStyles = css({ @@ -98,7 +98,7 @@ export const NavigationBaseItem: React.FC = ({ isExpanded, isFocused, hasDefaultAction, - onExpand, + toggleExpand, children, }) => { const [hoverProps, isHovered] = useHoverState(); @@ -114,12 +114,13 @@ export const NavigationBaseItem: React.FC = ({
{isExpandVisible && ( { - if (isExpandDisabled) return; - evt.stopPropagation(); - onExpand(!isExpanded); + onClick={(event) => { + // Prevent the click from propagating to the `TreeItem`, triggering the default action + event.stopPropagation(); + toggleExpand(); }} isExpanded={isExpanded} + disabled={isExpandDisabled} > )}
diff --git a/packages/compass-connections-navigation/src/navigation-item.tsx b/packages/compass-connections-navigation/src/navigation-item.tsx index a5b3d530070..c8c13015521 100644 --- a/packages/compass-connections-navigation/src/navigation-item.tsx +++ b/packages/compass-connections-navigation/src/navigation-item.tsx @@ -242,6 +242,12 @@ export function NavigationItem({ return actions; }, [item, isDarkMode]); + const toggleExpand = useCallback(() => { + if (item.type !== 'placeholder') { + onItemExpand(item, !item.isExpanded); + } + }, [onItemExpand, item]); + return ( {item.type === 'placeholder' ? ( @@ -262,9 +268,7 @@ export function NavigationItem({ isExpandDisabled={ item.type === 'connection' && item.connectionStatus !== 'connected' } - onExpand={(isExpanded: boolean) => { - onItemExpand(item, isExpanded); - }} + toggleExpand={toggleExpand} actionProps={actionProps} > {!!connectionStaticActions.length && ( diff --git a/packages/compass-connections-navigation/src/tree-item.tsx b/packages/compass-connections-navigation/src/tree-item.tsx index f102bf79f46..9700b543451 100644 --- a/packages/compass-connections-navigation/src/tree-item.tsx +++ b/packages/compass-connections-navigation/src/tree-item.tsx @@ -13,9 +13,6 @@ const expandButton = css({ display: 'flex', transition: 'transform .16s linear', transform: 'rotate(0deg)', - '&:hover': { - cursor: 'pointer', - }, // we're sizing the icon down below but we still want the button to take up // 16px so that the grid lines up minWidth: spacing[400], @@ -24,10 +21,14 @@ const expandButton = css({ justifyContent: 'center', }); -const expanded = css({ +const expandedStyles = css({ transform: 'rotate(90deg)', }); +const enabledStyles = css({ + cursor: 'pointer', +}); + export type VirtualListItemProps = { style?: CSSProperties; }; @@ -35,7 +36,8 @@ export type VirtualListItemProps = { export const ExpandButton: React.FunctionComponent<{ onClick: React.MouseEventHandler; isExpanded: boolean; -}> = ({ onClick, isExpanded }) => { + disabled?: boolean; +}> = ({ onClick, isExpanded, disabled = false }) => { return (