From b9cb93eb26b000de6f53ccd490d0628082698b17 Mon Sep 17 00:00:00 2001 From: Vlad Tansky Date: Thu, 15 Feb 2024 09:52:07 +0200 Subject: [PATCH] fix: controlled search change with hidden Command.List --- cmdk/src/index.tsx | 2 +- test/pages/portal.tsx | 64 +++++++++++++++++++++++++------------------ 2 files changed, 38 insertions(+), 28 deletions(-) diff --git a/cmdk/src/index.tsx b/cmdk/src/index.tsx index f8cd64fe..6969c475 100644 --- a/cmdk/src/index.tsx +++ b/cmdk/src/index.tsx @@ -469,7 +469,7 @@ const Command = React.forwardRef((props, forwarded } function getValidItems() { - return Array.from(listInnerRef.current?.querySelectorAll(VALID_ITEM_SELECTOR)) + return Array.from(listInnerRef.current?.querySelectorAll(VALID_ITEM_SELECTOR) ?? []) } /** Setters */ diff --git a/test/pages/portal.tsx b/test/pages/portal.tsx index 4fd2eda4..f4b59ce8 100644 --- a/test/pages/portal.tsx +++ b/test/pages/portal.tsx @@ -4,41 +4,51 @@ import * as Portal from '@radix-ui/react-portal' const Page = () => { const [render, setRender] = React.useState(false) + const [search, setSearch] = React.useState('') + const [open, setOpen] = React.useState(true) React.useEffect(() => setRender(true), []) if (!render) return null return (
+ + - + - - Apple - Banana - Cherry - Dragonfruit - Elderberry - Fig - Grape - Honeydew - Jackfruit - Kiwi - Lemon - Mango - Nectarine - Orange - Papaya - Quince - Raspberry - Strawberry - Tangerine - Ugli - Watermelon - Xigua - Yuzu - Zucchini - + {open && ( + + Apple + Banana + Cherry + Dragonfruit + Elderberry + Fig + Grape + Honeydew + Jackfruit + Kiwi + Lemon + Mango + Nectarine + Orange + Papaya + Quince + Raspberry + Strawberry + Tangerine + Ugli + Watermelon + Xigua + Yuzu + Zucchini + + )}