Skip to content

Commit

Permalink
Make sure the first child of Menu is not a MenuSection
Browse files Browse the repository at this point in the history
If the first child is a section, the DefaultEntry receives that section 
as title element instead of the correct menu title.
  • Loading branch information
swaterkamp committed Mar 13, 2019
1 parent e95396e commit a5180bc
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion gsa/src/web/components/menu/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import Theme from 'web/utils/theme.js';

import Link from 'web/components/link/link.js';

import MenuSection from 'web/components/menu/menusection';

const StyledMenu = styled.li`
flex-grow: 1;
flex-shrink: 1;
Expand Down Expand Up @@ -114,13 +116,23 @@ const MenuList = styled.ul`
}
`;

const getFirstMenuEntry = child => {
// return menu entries without the MenuSection
if (child.type === MenuSection) {
return React.Children.toArray(child.props.children).find(chil => !!chil);
}
return child;
};

const Menu = ({children, title, to, ...props}) => {
let link;
children = React.Children.toArray(children).filter(hasValue);

if (isDefined(to)) {
link = <Link to={to}>{title}</Link>;
} else if (isDefined(children) && children.length > 0) {
const [child] = children;
let [child] = children;
child = getFirstMenuEntry(child);
link = React.cloneElement(child, {title});
}

Expand Down

0 comments on commit a5180bc

Please sign in to comment.