Skip to content

Commit

Permalink
Clear combobox bugfix (#3934)
Browse files Browse the repository at this point in the history
* Add failing tests

* Fix clearing (or setting) selected
  • Loading branch information
gdebrauwer authored Jan 21, 2024
1 parent ae16eb3 commit c2e56bc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/ui/src/combobox.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ function handleRoot(el, Alpine) {
// if a user passed the "name" prop...
this.__inputName && renderHiddenInputs(Alpine, this.$el, this.__inputName, this.__value)
})

Alpine.effect(() => ! this.__isMultiple && this.__resetInput())
})
},
__startTyping() {
Expand Down
10 changes: 10 additions & 0 deletions tests/cypress/integration/plugins/ui/combobox.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ test('it works with x-model',
<article x-text="selected?.name"></article>
</div>
<a href="#" x-on:click.prevent="selected = { id: 7, name: 'Caroline Schultz' }">Set selected via code</a>
</div>
`],
({ get }) => {
Expand Down Expand Up @@ -95,6 +97,9 @@ test('it works with x-model',
get('ul').should(notBeVisible())
get('input').should(haveValue('Wade Cooper'))
get('article').should(haveText('Wade Cooper'))
get('a').click()
get('input').should(haveValue('Caroline Schultz'))
get('article').should(haveText('Caroline Schultz'))
},
)

Expand Down Expand Up @@ -1271,6 +1276,7 @@ test('input reset',
</div>
<article>lorem ipsum</article>
<a x-on:click="selected = null">Clear</a>
</div>
`],
({ get }) => {
Expand Down Expand Up @@ -1327,6 +1333,10 @@ test('input reset',
get('input').type('w')
get('article').click()
get('input').should(haveValue('Arlene Mccoy'))

// Test correct state after clearing selected via code
get('a').click()
get('input').should(haveValue(''))
},
)

Expand Down

0 comments on commit c2e56bc

Please sign in to comment.