From a3140811d9c80fb1e61e315c838f4209d7a23459 Mon Sep 17 00:00:00 2001 From: axtk Date: Mon, 1 Apr 2024 18:45:07 +0300 Subject: [PATCH] feat(DropdownMenu): add class name for submenu parents (#1465) --- src/components/DropdownMenu/DropdownMenuPopup.tsx | 13 ++++++++++++- src/components/DropdownMenu/README.md | 5 +++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/components/DropdownMenu/DropdownMenuPopup.tsx b/src/components/DropdownMenu/DropdownMenuPopup.tsx index cbb220ea40..f0e38d0720 100644 --- a/src/components/DropdownMenu/DropdownMenuPopup.tsx +++ b/src/components/DropdownMenu/DropdownMenuPopup.tsx @@ -150,6 +150,13 @@ export const DropdownMenuPopup = ({ const isActive = isNavigationActive && activeItemIndex === index; const activate = () => setActiveItemIndex(index); + const isActiveParent = + open && + !isActive && + activeMenuPath.length !== 0 && + stringifyNavigationPath(item.path) === + stringifyNavigationPath(activeMenuPath.slice(0, item.path.length)); + const extraProps = { ...item.extraProps, onMouseEnter: activate, @@ -160,7 +167,11 @@ export const DropdownMenuPopup = ({ key={index} className={cnDropdownMenu( 'menu-item', - {separator: isSeparator(item)}, + { + separator: isSeparator(item), + 'active-parent': isActiveParent, + 'with-submenu': Boolean(item.items?.length), + }, item.className, )} selected={isActive} diff --git a/src/components/DropdownMenu/README.md b/src/components/DropdownMenu/README.md index 223f0b5ea7..9c178322a1 100644 --- a/src/components/DropdownMenu/README.md +++ b/src/components/DropdownMenu/README.md @@ -160,6 +160,11 @@ LANDING_BLOCK--> The `items` property on an individual menu item adds nested subitems to this menu item. +Menu items with submenus obtain the following additional class names to allow for extra styling: + +- the class name `.g-dropdown-menu__menu-item_with-submenu` is added to items with more than 1 nested item; +- the class name `.g-dropdown-menu__menu-item_active-parent` is added to an item whose submenu is currently open. +