From fe785296409e7a41d148b6cc8ac02aadc6d8b596 Mon Sep 17 00:00:00 2001 From: Benjamin Canac Date: Tue, 3 Sep 2024 16:42:28 +0200 Subject: [PATCH] docs(context-menu): add missing `Extract shortcuts` section --- docs/content/3.components/context-menu.md | 70 +++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/docs/content/3.components/context-menu.md b/docs/content/3.components/context-menu.md index 7ce108dd..7f33e423 100644 --- a/docs/content/3.components/context-menu.md +++ b/docs/content/3.components/context-menu.md @@ -195,6 +195,76 @@ class: 'justify-center' You can also use the `#item`, `#item-leading`, `#item-label` and `#item-trailing` slots to customize all items. :: +### Extract shortcuts + +When you have some items with `kbds` property (displaying some [Kbd](/components/kbd)), you can easily make them work with the [defineShortcuts](/composables/define-shortcuts) composable. + +Inside the `defineShortcuts` composable, there is an `extractShortcuts` utility that will extract the shortcuts recursively from the items and return an object that you can pass to `defineShortcuts`. It will automatically call the `select` function of the item when the shortcut is pressed. + +```vue + +``` + +::note +In this example, :kbd{value="meta"} :kbd{value="S"}, :kbd{value="shift"} :kbd{value="meta"} :kbd{value="D"}, :kbd{value="option"} :kbd{value="meta"} :kbd{value="U"}, :kbd{value="option"} :kbd{value="meta"} :kbd{value="I"}, :kbd{value="option"} :kbd{value="meta"} :kbd{value="C"} and :kbd{value="option"} :kbd{value="meta"} :kbd{value="J"} would trigger the `select` function of the corresponding item. +:: + ## API ### Props