From 63e88139c1cc1cde1550b6be538ad3444c5cc86a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=CC=88nther=20Debrauwer?= Date: Mon, 18 Dec 2023 10:48:45 +0100 Subject: [PATCH 1/2] Add failing tests --- tests/cypress/integration/plugins/ui/combobox.spec.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/cypress/integration/plugins/ui/combobox.spec.js b/tests/cypress/integration/plugins/ui/combobox.spec.js index b3225dfba..d581b0fb7 100644 --- a/tests/cypress/integration/plugins/ui/combobox.spec.js +++ b/tests/cypress/integration/plugins/ui/combobox.spec.js @@ -66,6 +66,8 @@ test('it works with x-model',
+ + Set selected via code `], ({ get }) => { @@ -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')) }, ) @@ -1209,6 +1214,7 @@ test('input reset',
lorem ipsum
+ Clear `], ({ get }) => { @@ -1265,6 +1271,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('')) }, ) From 87755db82e959a35a91a2249053a94d962a9fdc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=CC=88nther=20Debrauwer?= Date: Mon, 18 Dec 2023 10:52:37 +0100 Subject: [PATCH 2/2] Fix clearing (or setting) selected --- packages/ui/src/combobox.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/ui/src/combobox.js b/packages/ui/src/combobox.js index 50739fcc8..8f95a66ce 100644 --- a/packages/ui/src/combobox.js +++ b/packages/ui/src/combobox.js @@ -111,6 +111,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() {