diff --git a/packages/ui/src/listbox.js b/packages/ui/src/listbox.js index 08eebb972..29fe1717e 100644 --- a/packages/ui/src/listbox.js +++ b/packages/ui/src/listbox.js @@ -226,7 +226,14 @@ function handleRoot(el, Alpine) { if (typeof by === 'string') { let property = by - by = (a, b) => a[property] === b[property] + by = (a, b) => { + // Handle null values + if ((! a || typeof a !== 'object') || (! b || typeof b !== 'object')) { + return Alpine.raw(a) === Alpine.raw(b) + } + + return a[property] === b[property]; + } } return by(a, b) diff --git a/tests/cypress/integration/plugins/ui/listbox.spec.js b/tests/cypress/integration/plugins/ui/listbox.spec.js index f1da78bc7..147f266ee 100644 --- a/tests/cypress/integration/plugins/ui/listbox.spec.js +++ b/tests/cypress/integration/plugins/ui/listbox.spec.js @@ -626,6 +626,62 @@ test('"horizontal" keyboard controls', }, ) +test('"by" prop with string value', + [html` +