pacocoursey / cmdk

Fast, unstyled command menu React component.
https://cmdk.paco.me
MIT License
9.17k stars 262 forks source link

Support for middle/cmd clicking an item to open in new tab #156

Open tarngerine opened 1 year ago

tarngerine commented 1 year ago

we have some items that are links, whats the recommended approach to support middle clicking? i could imagine onSelect handler passing the event

joaom00 commented 1 year ago

You can use an anchor tag inside Command.Item

https://codesandbox.io/s/silly-solomon-mthm2w?file=/src/App.tsx

tarngerine commented 1 year ago

@joaom00 thanks for chiming in, but this doesnt support the standard onSelect keyboard behavior (navigate on return)

best way i'm hacking it is to add an anchor tag inside, but also keep onSelect on the CommandItem. however, the anchor tag needs to have its own click handler that e.stopPropagation to prevent double firing (in the case where you have side effects from onSelect, which I do)

joaom00 commented 12 months ago

Ohh I see, yeah I think your approach is the way to go for now. I guess if #138 gets merged you will be able to have the desired behavior. Would be like this:

<Command.Item asChild>
  <a />
</Command.Item>