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.

@change does not work with Combobox (VueJs)

See original GitHub issue

What package within Headless UI are you using?

@headlessui/vue

What version of that package are you using?

v1.5.0

What browser are you using?

Chrome

Reproduction URL

A public GitHub repo that includes a minimal reproduction of the bug. Please do not link to your actual project, what we need instead is a minimal reproduction in a fresh project without any unnecessary code. This means it doesn’t matter if your real project is private/confidential, since we want a link to a separate, isolated reproduction anyways. Unfortunately we can’t provide support without a reproduction, and your issue will be closed with no comment if this is not provided.

Describe your issue

<Combobox
     v-model="selectedPerson"
     @change="window.location.href = selectedPerson.url"
     as="div"
>
          <ComboboxInput  
                    placeholder="Search..."
                    @change="query = $event.target.value"
                    :displayValue="(person) => person.name"
          />
          <ComboboxOptions
                     static
                              >
                    <ComboboxOption
                               v-slot="{ active }"
                               v-for="person in filteredPeople"
                               :disabled="person.unavailable"
                              :key="person.id"
                               :value="person"
                                            >
                    </ComboboxOption>
          </ComboboxOptions>

<Combobox/>

When there are actions like click or enter to the ComboxOption, the value in v-model="selectedPerson" changed,. I used @change to catch all those changes and redirect the window to the respective URL

But it does not seem to be working, nothing happened after clicking or entering

Before clicking or entering image

Afterclicking or entering image

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

4reactions
thecrypticacecommented, Mar 1, 2022

In Vue we use v-model instead of custom props and events. To react to changes without using computed, watch, etc… you need to use the same event used by v-model: update:modelValue.

Which, means the code above should be written as:

<Combobox
  v-model="selectedPerson"
  @update:modelValue="window.location.href = selectedPerson.url"
  as="div"
>
  …
</Combobox>

Link: https://stackblitz.com/edit/vue-sv3ctl

Aside:

  1. @adamwathan apparently console.count() doesn’t work on StackBlitz console.
  2. Should we add a change event just to more closely match the API of the React component? It’s not idiomatic Vue but it might still be a better DX.
2reactions
jameswong3388commented, Mar 3, 2022

@thecrypticace Not sure if there is a way to display activeOption in the ComboboxInput?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Vue.js get selected option on @change - Stack Overflow
Use v-model to bind the value of selected option's value. Here is an example. <select name="LeaveType" @change="onChange($event)" ...
Read more >
Combobox component - Vuetify
The v-combobox component is a v-autocomplete that allows the user to enter values that do not exist within the provided items.
Read more >
Dropdown | Components - BootstrapVue
Dropdowns work with trigger buttons of all sizes, including default and split ... Note: changing the size of the button(s) does not affect...
Read more >
Dropdown is not working in Vue js - MDBootstrap
The only way I've found to fix this so far is having to go into the node_modules/mdbvue/src/index.js and change the lines that say...
Read more >
Vue-Multiselect | Vue Select Library
The basic single select / dropdown doesn't require much configuration. ... Vue-Multiselect supports changing the option list on the fly, thus can be...
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