From e179f7b37e788c80a98ed3378b68c2af1d1d66f5 Mon Sep 17 00:00:00 2001 From: Jason Beggs Date: Thu, 21 Sep 2023 17:53:52 -0400 Subject: [PATCH] More fixes --- packages/ui/src/combobox.js | 5 +- .../integration/plugins/ui/combobox.spec.js | 76 +++++++++++++++++++ 2 files changed, 80 insertions(+), 1 deletion(-) diff --git a/packages/ui/src/combobox.js b/packages/ui/src/combobox.js index 9dfed9d5a..e001f95ef 100644 --- a/packages/ui/src/combobox.js +++ b/packages/ui/src/combobox.js @@ -247,7 +247,10 @@ function handleRoot(el, Alpine) { if (typeof by === 'string') { let property = by by = (a, b) => { - if (typeof a !== 'object' || typeof b !== 'object') return Alpine.raw(a) === Alpine.raw(b) + if ((! a || typeof a !== 'object') || (! b || typeof b !== 'object')) { + return Alpine.raw(a) === Alpine.raw(b) + } + return a[property] === b[property]; } diff --git a/tests/cypress/integration/plugins/ui/combobox.spec.js b/tests/cypress/integration/plugins/ui/combobox.spec.js index 497e11487..899604517 100644 --- a/tests/cypress/integration/plugins/ui/combobox.spec.js +++ b/tests/cypress/integration/plugins/ui/combobox.spec.js @@ -781,6 +781,82 @@ test('"by" prop with string value', }, ); +test('"by" prop with string value and "nullable"', + [html` +
+ + + + + + +
+ `], + ({ get }) => { + get('ul').should(notBeVisible()) + get('button').click() + get('ul').should(beVisible()) + get('button').click() + get('ul').should(notBeVisible()) + get('button').click() + get('[option="2"]').click() + get('ul').should(notBeVisible()) + get('input').should(haveValue('Arlene Mccoy')) + get('button').should(haveText('Arlene Mccoy')) + get('button').click() + get('ul').should(contain('Wade Cooper')) + .should(contain('Arlene Mccoy')) + .should(contain('Devon Webb')) + get('[option="3"]').click() + get('ul').should(notBeVisible()) + get('input').should(haveValue('Devon Webb')) + get('button').should(haveText('Devon Webb')) + get('button').click() + get('ul').should(contain('Wade Cooper')) + .should(contain('Arlene Mccoy')) + .should(contain('Devon Webb')) + get('[option="1"]').click() + get('ul').should(notBeVisible()) + get('input').should(haveValue('Wade Cooper')) + get('button').should(haveText('Wade Cooper')) + }, +); + + test('keyboard controls', [html`