nuxt / ui

A UI Library for Modern Web Apps, powered by Vue & Tailwind CSS.
https://ui.nuxt.com
MIT License
3.99k stars 504 forks source link

Command palette close button event propagation stop missing #1981

Closed chris-si closed 1 month ago

chris-si commented 3 months ago

Environment

Version

v2.17.0

Reproduction

https://stackblitz.com/edit/nuxt-starter-avai3t?file=components%2FMyCommandPalette.vue

Description

Hi,

I have a problem with the close button of the command palette. When nullable = false and autoselect = true are set and the close button is being clicked, the auto selected command gets triggered together with the close button event.

The reproduction shows the described behavior, that if the close button gets clicked, a command event will also be triggered.

My guess is that a .stop on the @click event in line 24 of CommandPalette.vue might mitigate this behavior if I'm not mistaken.

Additional context

No response

Logs

No response

benjamincanac commented 3 months ago

Duplicate #1708. The SelectMenu and CommandPalette both use Headless UI Combobox component underneath.

benjamincanac commented 3 months ago

The only workaround I can provide at the moment is to set the multiple prop alongside model-value="[]":

<template>
  <div>
    <UButton label="Open" @click="isOpen = true" />

    <UModal v-model="isOpen">
      <UCommandPalette
        :model-value="[]"
        multiple
        :close-button="{
          icon: 'i-heroicons-x-mark-20-solid',
          color: 'gray',
          variant: 'link',
          padded: false,
        }"
        :groups="[{ key: 'people', commands: people }]"
        @update:model-value="onCommandSelect"
        @close="() => (isOpen = false)"
      />
    </UModal>
  </div>
</template>