Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MenuOption's disabled Property Does Not Prevent Clicking When <router-link /> or <a /> is Used #6815

Open
5 tasks done
XiaoSong-CPE opened this issue Mar 22, 2025 · 2 comments
Labels
untriaged need to sort

Comments

@XiaoSong-CPE
Copy link

XiaoSong-CPE commented Mar 22, 2025

Describe the bug

When the disabled property is applied to a menu option rendered with RouterLink (as demonstrated in the documentation here), the appearance of the menu option changes correctly but it remains clickable.

This behaviour appears to be inconsistent. If RouterLink is not involved, both the icon and label require onClick to function, and the margin area cannot be clicked. It seems that n-menu is treating RouterLink differently, which we believe constitutes a bug and should be addressed.

Steps to reproduce

  1. Use the code from the documentation (link) to render the menu.
  2. Set the disabled attribute to true for the menu options.

(by the way, the sandbox link in that part of documentation doesn't work because the routes are unset)

Link to minimal reproduction

https://codesandbox.io/p/sandbox/focused-grothendieck-hynjrq

System Info

System:
    OS: Windows 11 10.0.26100
    CPU: (12) x64 12th Gen Intel(R) Core(TM) i5-12450H
    Memory: 3.23 GB / 15.73 GB
  Binaries:
    Node: 22.13.1 - C:\Program Files\nodejs\node.EXE
    npm: 10.9.2 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Chromium (131.0.2903.112)
    Internet Explorer: 11.0.26100.1882
  npmPackages:
    naive-ui: ^2.41.0 => 2.41.0
    vue: ^3.4.30 => 3.5.13

Used Package Manager

npm

Validations

@XiaoSong-CPE XiaoSong-CPE added the untriaged need to sort label Mar 22, 2025
@XiaoSong-CPE
Copy link
Author

XiaoSong-CPE commented Mar 22, 2025

The <a /> behaves the same as <router-link />.

@XiaoSong-CPE XiaoSong-CPE changed the title n-menu's disabled Attribute Does Not Prevent Clicking When RouterLink is Used MenuOption's disabled Property Does Not Prevent Clicking When <router-link /> or <a /> is Used Mar 22, 2025
@blackawn
Copy link

blackawn commented Mar 23, 2025

In my opinion, the effective a tag in the browser should be optimistic
So when you set this menu item to disabled, you can convert it to a basic tag.

menu.label = () =>
  disabled
    ? meta?.label
    : h(
        RouterLink,
        {
          to: { name },
        },
        { default: () => meta?.label },
      )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
untriaged need to sort
Projects
None yet
Development

No branches or pull requests

2 participants