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.

Adding ability to make single Menu.Item not selectable within a Menu (for when nested Header)

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

What problem does this feature solve?

I have a situation where I am putting non-menu items into a Header with nested Menu/Items alongside regular navigation. Currently the items will highlight when clicked as-if they are the selected menu item.

I have tried the following.

  1. Instead of using <Menu.Item>, use <li className="ant-menu-item"> This causes console errors.
<Header>
  <Menu theme="dark" mode="horizontal" className={styles.rightNav} selectable={false}>
     <Menu.Item key="accounts">
      <NavbarLink to="/accounts" icon="target" text="Accounts" />
    </Menu.Item>
    <li className="ant-menu-item">
      <SearchInput />
    </li>
  </Menu>
</Header>
Warning: React does not recognize the `inlineIndent` prop on a DOM element. If you intentionally want it to appear in the DOM as a custom attribute, spell it as lowercase `inlineindent` instead. If you accidentally passed it from a parent component, remove it from the DOM element.
    in li (created by Menu)
    in ul (created by DOMWrap)
    in DOMWrap (created by Menu)
    in Menu (created by Menu)
    in Menu (created by Navbar)
    in div (created by Basic)
    in Basic (created by Adapter)
    in Adapter (created by Navbar)
    in Navbar (created by App)
    in div (created by BasicLayout)
    in BasicLayout (created by Adapter)
    in Adapter (created by App)
    in App (created by Routes)
    in Provider (created by Routes)
    in Routes
    in Router (created by BrowserRouter)
    in BrowserRouter
    in IntlProvider
  1. <Menu.Items disabled={true}> - This works, but the downside here is the default styling of disabled menu items need to be overridden.
<Header>
  <Menu theme="dark" mode="horizontal" className={styles.rightNav}>
     <Menu.Item key="accounts">
      <NavbarLink to="/accounts" icon="target" text="Accounts" />
    </Menu.Item>
    <Menu.Item disabled={true}>
      <SearchInput />
    </Menu.Item>
  </Menu>
</Header>
  1. Setting the Menu to selectable={false}. This works as desired for affects the other Menu.Items.
<Header>
  <Menu theme="dark" mode="horizontal" className={styles.rightNav} selectable={false}>
     <Menu.Item key="accounts">
      <NavbarLink to="/accounts" icon="target" text="Accounts" />
    </Menu.Item>
    <Menu.Item>
      <SearchInput />
    </Menu.Item>
  </Menu>
</Header>

What does the proposed API look like?

Possible solutions:

  1. Add a selectable attribute to the Menu.Item - <Menu.Item selectable={false}>
<Header>
  <Menu theme="dark" mode="horizontal" className={styles.rightNav}>
     <Menu.Item key="accounts">
      <NavbarLink to="/accounts" icon="target" text="Accounts" />
    </Menu.Item>
    <Menu.Item  selectable={false}>
      <SearchInput />
    </Menu.Item>
  </Menu>
</Header>

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
lzearcommented, Apr 4, 2021

The CSS property pointer-events set to none makes the component ignore mouse events without altering the style of the cursor.

<Menu>
  <Menu.Item key="/">
    <Link href="/">Clickable</Link>
  </Menu.Item>
  <Menu.Item style={{ pointerEvents: 'none' }}>
    Unclickable
  </Menu.Item>
</Menu>here
0reactions
pinghsu520commented, Jun 13, 2020

^ is there a solution

Read more comments on GitHub >

github_iconTop Results From Across the Web

How make top level menu item not have link, but have sub ...
From your WordPress dashboard, go to "Appearance -> Menus" · In the "Edit Menus" tab, select "Custom Links" · For the URL, Enter...
Read more >
How to Make a Non Clickable Menu Item in Wordpress
1) In your APPEARANCE > MENUS, make sure you go to “Screen Options” (top right hand of your screen). Make sure “CSS Classes”...
Read more >
Header: Create a multi-column nested menu (Mega Navigation)
Add menu items to include in the new 'Store' drop-down menu. Click 'Add menu item', enter the name of the menu item, and...
Read more >
Targeting Menu Elements with Submenus in a Navigation Bar
The common way to address this issue, is to simply add a class to the <li> s that contain <ul> s (sub menus)...
Read more >
How to Add Titles in WordPress Menu Without Linking to a Page
For example, you can have a categories dropdown where you want the title text to be 'categories' for the menu but don't need...
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