لوحة أوامر

Command

لوحة أوامر في React مبنية على cmdk ببحث تقريبي ومجموعات واختصارات وCommandDialog يربط Cmd+K وCtrl+K. تعمل مضمّنة أو منبثقة.

يعرض Command الإجراءات خلف حقل بحث، وينفذ كل CommandItem حدث onSelect. أما CommandDialog فهو اللوحة نفسها داخل نافذة ويتكفل باختصار ⌘K.

متى تستخدمه

استخدم Command ليقفز المستخدمون المتمرّسون إلى الصفحات والإجراءات بالكتابة: فتح طلب برقمه، أو تبديل خدمة، أو تنفيذ إجراء إداري. ثبّت CommandDialog مرّة واحدة للوحة عامة، أو استخدم Command مضمّنًا لقائمة إجراءات قابلة للبحث.

للبحث في المحتوى لا الأوامر، استخدم SearchBox.

أمثلة

لوحة مضمّنة

حوار ⌘K

اضغط ⌘K (أو Ctrl+K) في أي مكان.

اختصار مخصّص

الخصائص

الخصائص التي يعرّفها Command. سمات العنصر الأصلي تمرّ كما هي.

<Command>

الخاصيةالنوعالافتراضيالوصف
childrenReactNode
asChildboolean
labelstringAccessible label for this command menu. Not shown visibly.
shouldFilterbooleanOptionally set to false to turn off the automatic filtering and sorting. If false, you must conditionally render valid items based on the search query yourself.
filterCommandFilterCustom filter function for whether each command menu item should matches the given search query. It should return a number between 0 and 1, with 1 being the best match and 0 being hidden entirely. By default, uses the command-score library.
defaultValuestring | (readonly string[] & string)Optional default item value when it is initially rendered.
valuestringOptional controlled state of the selected command menu item.
onValueChange(value: string) => voidEvent handler called when the selected item of the menu changes.
loopbooleanOptionally set to true to turn on looping around when using the arrow keys.
disablePointerSelectionbooleanOptionally set to true to disable selection via pointer events.
vimBindingsbooleanSet to false to disable ctrl+n/j/p/k shortcuts. Defaults to true.

<CommandInput>

الخاصيةالنوعالافتراضيالوصف
asChildboolean
valuestringOptional controlled state for the value of the search input.
onValueChange(search: string) => voidEvent handler called when the search value changes.

<CommandList>

الخاصيةالنوعالافتراضيالوصف
childrenReactNode
asChildboolean
labelstringAccessible label for this List of suggestions. Not shown visibly.

<CommandEmpty>

الخاصيةالنوعالافتراضيالوصف
childrenReactNode
asChildboolean

<CommandGroup>

الخاصيةالنوعالافتراضيالوصف
childrenReactNode
asChildboolean
headingReactNodeOptional heading to render for this group.
valuestringIf no heading is provided, you must provide a value that is unique for this group.
forceMountbooleanWhether this group is forcibly rendered regardless of filtering.

<CommandSeparator>

الخاصيةالنوعالافتراضيالوصف
asChildboolean
alwaysRenderbooleanWhether this separator should always be rendered. Useful if you disable automatic filtering.

<CommandItem>

الخاصيةالنوعالافتراضيالوصف
valueإلزاميstringStable value for filtering + the onSelect payload. Required: cmdk would otherwise derive it from the rendered text, so a label / translation / icon change would silently change what onSelect receives.
startIconreact.ReactNodeLeading icon - mirrors Menubar / DropdownMenu item icons.
shortcutreact.ReactNodeRight-aligned keyboard hint, e.g. "⌘P" - mirrors Menubar / DropdownMenu.
onSelect(value: string) => voidFires when the item is chosen (click / Enter). Receives the item's value (cmdk defaults it to the text content when value is omitted). Action-oriented: items run a command and don't track selection. Inside CommandDialog the consumer closes the dialog here, e.g. onSelect={() => { setOpen(false); run(); }}.
childrenReactNode
asChildboolean
disabledbooleanWhether this item is currently disabled.
keywordsstring[]Optional keywords to match against when filtering.
forceMountbooleanWhether this item is forcibly rendered regardless of filtering.

<CommandDialog>

الخاصيةالنوعالافتراضيالوصف
openbooleanControlled open state.
defaultOpenbooleanInitial open state when uncontrolled.
onOpenChange(open: boolean) => void
shortcutstring | falseKey for the built-in document shortcut (with Cmd on macOS / Ctrl elsewhere). Defaults to 'k' (⌘K / Ctrl+K). Pass false to bind no listener and wire your own. The modifier is fixed; only the key is configurable.
labelreact.ReactNodeAccessible name → visually-hidden DialogTitle. Defaults to "Command palette".
descriptionreact.ReactNodeOptional visually-hidden DialogDescription.
classNamestring
childrenإلزاميreact.ReactNodeCommandInput + CommandList + groups / items.
shouldFilterbooleanOptionally set to false to turn off the automatic filtering and sorting. If false, you must conditionally render valid items based on the search query yourself.
filterCommandFilterCustom filter function for whether each command menu item should matches the given search query. It should return a number between 0 and 1, with 1 being the best match and 0 being hidden entirely. By default, uses the command-score library.
loopbooleanOptionally set to true to turn on looping around when using the arrow keys.

إمكانية الوصول

الحقل role="combobox" مرتبط بـ role="listbox" للنتائج، فتتحرّك مفاتيح الأسهم بين المطابقات، ويشغّل Enter العنصر المظلّل، ويغلق Escape. أعطِ الحقل aria-label.

يحصر نمط الحوار التركيز ويعيده عند الإغلاق. الاختصارات المعروضة بجانب العناصر تلميحات؛ وكل عنصر يعمل بالفأرة ولوحة المفاتيح أيضًا.