From 475db7c173606fbf72b350caa376555f7a2fa4a9 Mon Sep 17 00:00:00 2001 From: Jordan Pittman Date: Fri, 17 Nov 2023 13:00:19 -0500 Subject: [PATCH] Make the empty state interactive --- .../combobox-virtual-with-empty-states.tsx | 35 +++++++++++++++++-- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/packages/playground-react/pages/combobox/combobox-virtual-with-empty-states.tsx b/packages/playground-react/pages/combobox/combobox-virtual-with-empty-states.tsx index bb88c57..e36c75d 100644 --- a/packages/playground-react/pages/combobox/combobox-virtual-with-empty-states.tsx +++ b/packages/playground-react/pages/combobox/combobox-virtual-with-empty-states.tsx @@ -3,6 +3,7 @@ import { useRef, useState } from 'react' import { classNames } from '../../utils/class-names' import { Button } from '../../components/button' +import { flushSync } from 'react-dom' type Option = { name: string @@ -67,6 +68,17 @@ export default function Home() { setQuery('') }} as="div" + + // Don't do this lol — it's not supported + // It's just so we can tab to the "Add" button for the demo + // The combobox doesn't actually support this behavior + onKeyDownCapture={(event: KeyboardEvent) => { + let addButton = document.querySelector('#add_person') + if (event.key === 'Tab' && addButton && filtered.length === 0) { + event.preventDefault() + setTimeout(() => addButton.focus(), 0) + } + }} > Person @@ -100,6 +112,11 @@ export default function Home() {
{ ({ option }: { option: Option }) => { - if (option.empty) { + if (!option || option.empty) { return (
@@ -124,7 +141,19 @@ export default function Home() {
-

No people found

+

No people found

+