Skip to content

Commit

Permalink
feat/570: Enhancements to menu item classes (#818)
Browse files Browse the repository at this point in the history
Co-authored-by: Nícholas André <[email protected]>
  • Loading branch information
Sidsector9 and nicholasio authored Aug 27, 2024
1 parent d9dcec0 commit fc7e426
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .changeset/shiny-onions-camp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@headstartwp/core": patch
---

Added - Support for custom menu item CSS classes.
Added - `menu-item-has-children` CSS class for menu item with children.
17 changes: 15 additions & 2 deletions packages/core/src/react/components/Menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,23 @@ export const MenuItems = ({
backendUrl: settings.sourceUrl || '',
});
const shouldLink = item.children.length === 0 || topLevelItemsClickable;
const className = `menu-item-depth-${depth}`;
let classNames = [`menu-item-depth-${depth}`];

if (item.children.length) {
classNames = [...classNames, 'menu-item-has-children'];
}

if (item.classes.length) {
classNames = [...classNames, ...item.classes];
}

return (
<ItemWrapper key={item.ID} className={className} depth={depth} item={item}>
<ItemWrapper
key={item.ID}
className={classNames.join(' ')}
depth={depth}
item={item}
>
{shouldLink ? (
<LinkWrapper href={link} depth={depth}>
{item.title}
Expand Down

0 comments on commit fc7e426

Please sign in to comment.