tusen-ai / naive-ui

A Vue 3 Component Library. Fairly Complete. Theme Customizable. Uses TypeScript. Fast.
https://www.naiveui.com
MIT License
16.24k stars 1.68k forks source link

NDropdown work with render-option does not allow selecting options #6362

Open manit-highlevel opened 2 months ago

manit-highlevel commented 2 months ago

Describe the bug

When i render a plain div using render-option it

  1. Does not have a pointer cursor to select the dropdown option
  2. Clicking it does not emit select event

Steps to reproduce

Please refer to Demo.vue at this url https://codesandbox.io/p/sandbox/compassionate-aryabhata-tg9zwv

Link to minimal reproduction

https://codesandbox.io/p/sandbox/compassionate-aryabhata-tg9zwv

System Info

System:
    OS: macOS 14.5
    CPU: (12) arm64 Apple M3 Pro
    Memory: 3.56 GB / 36.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.10.0 - ~/.volta/tools/image/node/20.10.0/bin/node
    Yarn: 4.0.2 - ~/.volta/tools/image/yarn/4.0.2/bin/yarn
    npm: 10.2.5 - ~/.volta/tools/image/npm/10.2.5/bin/npm
  Browsers:
    Chrome: 128.0.6613.138
    Safari: 17.5

Used Package Manager

yarn

Validations

jizai1125 commented 1 month ago

If you don't inherit the node parameter when customizing options, you should handle user events yourself. like this:

renderOption: ({
  node,
  option
}: {
  node: VNode
  option: DropdownOption | DropdownGroupOption
}) => {
  return h('div', {
    style: {
      border: '1px solid red',
      margin: '5px',
    },
    onClick: () => {
      console.log('click', option.key)
    }
  }, option.key)
},
ozanerturk commented 6 days ago

You can simulate as below, make sure your label renderer works as expected node.props["onClick"]();