question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Menu item grouping and alignment

See original GitHub issue
  • I have searched the issues of this repository and believe that this is not a duplicate.

Someone else has requested something similar [1] but the response to that request was hijacked by text alignment (which is not what this is about) and then sadly closed for inactivity…

[1] https://github.com/ant-design/ant-design/issues/6111

What problem does this feature solve?

The ability to group menu items in a Menu with mode=horizontal so that these item groups can be aligned left (default) or right. It’s common for applications to have an Account or Logout option in the top right corner of a main navigation where access to application features might live on the left in the top navigation. There is currently no mechanism to a) divide the top level nav into multiple item groups and b) align these item groups either left or right.

What does the proposed API look like?

Using the Top Side 2 demo as an example (https://github.com/ant-design/ant-design/blob/master/components/layout/demo/top-side-2.md).

The Menu in the Header would have the ability to group the menu items and then align each group accordingly:

<Header className="header">
  <div className="logo" />
  <Menu
    theme="dark"
    mode="horizontal"
    defaultSelectedKeys={['11']}
    style={{ lineHeight: '64px' }}
  >
    <Menu.Group> <!-- "align=left" is implied -->
      <Menu.Item key="10">nav 1</Menu.Item>
      <Menu.Item key="11">nav 2</Menu.Item>
      <Menu.Item key="12">nav 3</Menu.Item>
    </Menu.Group>
    <Menu.Group align="right">
      <Menu.Item key="20">Account</Menu.Item>
      <Menu.Item key="21">Logout</Menu.Item>
    </Menu.Group>
  </Menu>
</Header>

I guess for completness it would also be possible to have align=center to display the group of items in the centre of the menu. Obviously, this proposal only makes sense for Menu’s with mode=horizontal.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:87
  • Comments:31

github_iconTop GitHub Comments

11reactions
Sirri69commented, Jun 14, 2021

+1 We need this. There are many workarounds but won’t it make sense if it was built into the library ? 😐

10reactions
vjprcommented, Apr 15, 2020

Here is an example of centered and right-aligned menu items as mentioned by blackfry and adapted from https://stackoverflow.com/questions/56206061/how-to-center-menu-item-in-navbar-like-example.

const centerStyle = {
  position: 'relative',
  display: 'flex',
  justifyContent: 'center',
}
const rightStyle = {position: 'absolute', top: 0, right: 0}

return (
  <div>
  <Menu selectable={false} mode='horizontal' style={centerStyle}>
    <MenuItem>Centered</MenuItem>
  </Menu>
  <Menu selectable={false} mode='horizontal' style={rightStyle}>
    <MenuItem>Right</MenuItem>
  </Menu>
  </div>
)
Read more comments on GitHub >

github_iconTop Results From Across the Web

Menu Item Alignment Report - Oracle Help Center
The Menu Item Alignment Major Group Masters report lists the menu items that have been aligned under a master item, as described in...
Read more >
Word: Aligning, Ordering, and Grouping Objects - GCF Global
To align two or more objects: · Hold the Shift (or Ctrl) key and click the objects you want to align. In our...
Read more >
Aligning Menu Group to Menu Item - Stack Overflow
best way for styling is to use chrome dev tool included in it or firebug with firefox to tell which exact styles are...
Read more >
Need to align the service portal header menu items...
Hi All , I need to align all the SP header menu items to left instead from right . All menu items needs...
Read more >
Arrange, group, and distribute components - Looker Studio Help
Use the Arrange menu to control the layout of the components in your report. ... or more components, then select the desired alignment...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found