Skip to content

Commit f2682fd

Browse files
committed
feat(NavigationMenu): add tooltip and popover props
Resolves #4186
1 parent 0634a75 commit f2682fd

File tree

9 files changed

+392
-236
lines changed

9 files changed

+392
-236
lines changed

docs/content/3.components/input-menu.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,7 @@ props:
612612
---
613613
::
614614

615-
### With icons in items
615+
### With icon in items
616616

617617
You can use the `icon` property to display an [Icon](/components/icon) inside the items.
618618

docs/content/3.components/navigation-menu.md

Lines changed: 137 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Use the `items` prop as an array of objects with the following properties:
3232
- `onSelect?(e: Event): void`{lang="ts-type"}
3333
- `children?: NavigationMenuChildItem[]`{lang="ts-type"}
3434
- `class?: any`{lang="ts-type"}
35-
- `ui?: { linkLeadingAvatarSize?: ClassNameValue, linkLeadingAvatar?: ClassNameValue, linkLeadingIcon?: ClassNameValue, linkLabel?: ClassNameValue, linkLabelExternalIcon?: ClassNameValue, linkTrailing?: ClassNameValue, linkTrailingBadgeSize?: ClassNameValue, linkTrailingBadge?: ClassNameValue, linkTrailingIcon?: ClassNameValue, label?: ClassNameValue, link?: ClassNameValue, content?: ClassNameValue, childList?: ClassNameValue, childItem?: ClassNameValue, childLink?: ClassNameValue, childLinkIcon?: ClassNameValue, childLinkWrapper?: ClassNameValue, childLinkLabel?: ClassNameValue, childLinkLabelExternalIcon?: ClassNameValue, childLinkDescription?: ClassNameValue }`{lang="ts-type"}
35+
- `ui?: { linkLeadingAvatarSize?: ClassNameValue, linkLeadingAvatar?: ClassNameValue, linkLeadingIcon?: ClassNameValue, linkLabel?: ClassNameValue, linkLabelExternalIcon?: ClassNameValue, linkTrailing?: ClassNameValue, linkTrailingBadgeSize?: ClassNameValue, linkTrailingBadge?: ClassNameValue, linkTrailingIcon?: ClassNameValue, label?: ClassNameValue, link?: ClassNameValue, content?: ClassNameValue, childList?: ClassNameValue, childLabel?: ClassNameValue, childItem?: ClassNameValue, childLink?: ClassNameValue, childLinkIcon?: ClassNameValue, childLinkWrapper?: ClassNameValue, childLinkLabel?: ClassNameValue, childLinkLabelExternalIcon?: ClassNameValue, childLinkDescription?: ClassNameValue }`{lang="ts-type"}
3636

3737
You can pass any property from the [Link](/components/link#props) component such as `to`, `target`, etc.
3838

@@ -144,7 +144,7 @@ Each item can take a `children` array of objects with the following properties t
144144
Use the `orientation` prop to change the orientation of the NavigationMenu.
145145

146146
::note
147-
When orientation is `vertical`, a [Collapsible](/components/collapsible) component is used to display children. You can control the open state of each item using the `open` and `defaultOpen` properties.
147+
When orientation is `vertical`, an [Accordion](/components/accordion) component is used to display each group. You can control the open state of each item using the `open` and `defaultOpen` properties and change the behavior using the [`collapsible`](/components/accordion#collapsible) and [`type`](/components/accordion#multiple) props.
148148
::
149149

150150
::component-code
@@ -243,7 +243,11 @@ Groups will be spaced when orientation is `horizontal` and separated when orient
243243

244244
### Collapsed
245245

246-
Use the `collapsed` prop to collapse the NavigationMenu, this can be useful in a sidebar for example.
246+
In `vertical` orientation, use the `collapsed` prop to collapse the NavigationMenu, this can be useful in a sidebar for example.
247+
248+
::note
249+
You can use the [`tooltip`](#with-tooltip-in-items) and [`popover`](#with-popover-in-items) props to display more information on the collapsed items.
250+
::
247251

248252
::component-code
249253
---
@@ -256,8 +260,17 @@ external:
256260
- items
257261
externalTypes:
258262
- NavigationMenuItem[][]
263+
items:
264+
tooltip:
265+
- true
266+
- false
267+
popover:
268+
- true
269+
- false
259270
props:
260271
collapsed: true
272+
tooltip: false
273+
popover: false
261274
orientation: 'vertical'
262275
items:
263276
- - label: Links
@@ -282,7 +295,6 @@ props:
282295
description: 'You can customize components by using the `class` / `ui` props or in your app.config.ts.'
283296
- label: Composables
284297
icon: i-lucide-database
285-
open: false
286298
children:
287299
- label: defineShortcuts
288300
icon: i-lucide-file-text
@@ -298,7 +310,6 @@ props:
298310
to: /composables/use-toast
299311
- label: Components
300312
icon: i-lucide-box
301-
open: false
302313
to: /components
303314
active: true
304315
children:
@@ -878,9 +889,11 @@ You can inspect the DOM to see each item's content being rendered.
878889

879890
## Examples
880891

881-
### With tooltips in items :badge{label="New" class="align-text-top"}
892+
### With tooltip in items :badge{label="New" class="align-text-top"}
893+
894+
When orientation is `vertical` and the menu is `collapsed`, you can set the `tooltip` prop to `true` to display a [Tooltip](/components/tooltip) around items with their label but you can also use the `tooltip` property on each item to override the default tooltip.
882895

883-
You can use the `tooltip` property to display a [Tooltip](/components/tooltip) around an item. This can be useful when the menu is collapsed.
896+
You can pass any property from the [Tooltip](/components/tooltip) component globally or on each item.
884897

885898
::component-code
886899
---
@@ -893,47 +906,37 @@ external:
893906
- items
894907
externalTypes:
895908
- NavigationMenuItem[][]
909+
items:
910+
tooltip:
911+
- true
912+
- false
896913
props:
914+
tooltip: true
897915
collapsed: true
898916
orientation: 'vertical'
899917
items:
900918
- - label: Links
901919
type: 'label'
902920
- label: Guide
903921
icon: i-lucide-book-open
904-
tooltip:
905-
text: 'Guide'
906922
children:
907923
- label: Introduction
908924
description: Fully styled and customizable components for Nuxt.
909925
icon: i-lucide-house
910-
tooltip:
911-
text: 'Introduction'
912926
- label: Installation
913927
description: Learn how to install and configure Nuxt UI in your application.
914928
icon: i-lucide-cloud-download
915-
tooltip:
916-
text: 'Installation'
917929
- label: 'Icons'
918930
icon: 'i-lucide-smile'
919931
description: 'You have nothing to do, @nuxt/icon will handle it automatically.'
920-
tooltip:
921-
text: 'Icons'
922932
- label: 'Colors'
923933
icon: 'i-lucide-swatch-book'
924934
description: 'Choose a primary and a neutral color from your Tailwind CSS theme.'
925-
tooltip:
926-
text: 'Colors'
927935
- label: 'Theme'
928936
icon: 'i-lucide-cog'
929937
description: 'You can customize components by using the `class` / `ui` props or in your app.config.ts.'
930-
tooltip:
931-
text: 'Theme'
932938
- label: Composables
933939
icon: i-lucide-database
934-
tooltip:
935-
text: 'Composables'
936-
open: false
937940
children:
938941
- label: defineShortcuts
939942
icon: i-lucide-file-text
@@ -949,11 +952,8 @@ props:
949952
to: /composables/use-toast
950953
- label: Components
951954
icon: i-lucide-box
952-
tooltip:
953-
text: 'Components'
954955
to: /components
955956
active: true
956-
open: false
957957
children:
958958
- label: Link
959959
icon: i-lucide-file-text
@@ -985,17 +985,126 @@ props:
985985
to: https://github.com/nuxt/ui
986986
target: _blank
987987
tooltip:
988-
text: 'GitHub'
988+
text: 'Open on GitHub'
989989
kbds:
990990
- 3.8k
991991
- label: Help
992992
icon: i-lucide-circle-help
993993
disabled: true
994+
---
995+
::
996+
997+
### With popover in items :badge{label="Soon" class="align-text-top"}
998+
999+
When orientation is `vertical` and the menu is `collapsed`, you can set the `popover` prop to `true` to display a [Popover](/components/popover) around items with their children but you can also use the `popover` property on each item to override the default popover.
1000+
1001+
You can pass any property from the [Popover](/components/popover) component globally or on each item.
1002+
1003+
::component-code
1004+
---
1005+
collapse: true
1006+
ignore:
1007+
- items
1008+
- orientation
1009+
- class
1010+
external:
1011+
- items
1012+
externalTypes:
1013+
- NavigationMenuItem[][]
1014+
items:
1015+
popover:
1016+
- true
1017+
- false
1018+
props:
1019+
popover: true
1020+
collapsed: true
1021+
orientation: 'vertical'
1022+
items:
1023+
- - label: Links
1024+
type: 'label'
1025+
- label: Guide
1026+
icon: i-lucide-book-open
1027+
children:
1028+
- label: Introduction
1029+
description: Fully styled and customizable components for Nuxt.
1030+
icon: i-lucide-house
1031+
- label: Installation
1032+
description: Learn how to install and configure Nuxt UI in your application.
1033+
icon: i-lucide-cloud-download
1034+
- label: 'Icons'
1035+
icon: 'i-lucide-smile'
1036+
description: 'You have nothing to do, @nuxt/icon will handle it automatically.'
1037+
- label: 'Colors'
1038+
icon: 'i-lucide-swatch-book'
1039+
description: 'Choose a primary and a neutral color from your Tailwind CSS theme.'
1040+
- label: 'Theme'
1041+
icon: 'i-lucide-cog'
1042+
description: 'You can customize components by using the `class` / `ui` props or in your app.config.ts.'
1043+
- label: Composables
1044+
icon: i-lucide-database
1045+
popover:
1046+
mode: 'click'
1047+
children:
1048+
- label: defineShortcuts
1049+
icon: i-lucide-file-text
1050+
description: Define shortcuts for your application.
1051+
to: /composables/define-shortcuts
1052+
- label: useOverlay
1053+
icon: i-lucide-file-text
1054+
description: Display a modal/slideover within your application.
1055+
to: /composables/use-overlay
1056+
- label: useToast
1057+
icon: i-lucide-file-text
1058+
description: Display a toast within your application.
1059+
to: /composables/use-toast
1060+
- label: Components
1061+
icon: i-lucide-box
1062+
to: /components
1063+
active: true
1064+
children:
1065+
- label: Link
1066+
icon: i-lucide-file-text
1067+
description: Use NuxtLink with superpowers.
1068+
to: /components/link
1069+
- label: Modal
1070+
icon: i-lucide-file-text
1071+
description: Display a modal within your application.
1072+
to: /components/modal
1073+
- label: NavigationMenu
1074+
icon: i-lucide-file-text
1075+
description: Display a list of links.
1076+
to: /components/navigation-menu
1077+
- label: Pagination
1078+
icon: i-lucide-file-text
1079+
description: Display a list of pages.
1080+
to: /components/pagination
1081+
- label: Popover
1082+
icon: i-lucide-file-text
1083+
description: Display a non-modal dialog that floats around a trigger element.
1084+
to: /components/popover
1085+
- label: Progress
1086+
icon: i-lucide-file-text
1087+
description: Show a horizontal bar to indicate task progression.
1088+
to: /components/progress
1089+
- - label: GitHub
1090+
icon: i-simple-icons-github
1091+
badge: 3.8k
1092+
to: https://github.com/nuxt/ui
1093+
target: _blank
9941094
tooltip:
995-
text: 'Help'
1095+
text: 'Open on GitHub'
1096+
kbds:
1097+
- 3.8k
1098+
- label: Help
1099+
icon: i-lucide-circle-help
1100+
disabled: true
9961101
---
9971102
::
9981103

1104+
::tip{to="#with-content-slot"}
1105+
You can use the `#content` slot to customize the content of the popover in the `vertical` orientation.
1106+
::
1107+
9991108
### Control active item
10001109

10011110
You can control the active item by using the `default-value` prop or the `v-model` directive with the index of the item.
@@ -1043,6 +1152,7 @@ Use the `#item-content` slot or the `slot` property (`#{{ item.slot }}-content`)
10431152

10441153
::component-example
10451154
---
1155+
collapse: true
10461156
name: 'navigation-menu-content-slot-example'
10471157
---
10481158
::

docs/content/3.components/select-menu.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -655,7 +655,7 @@ props:
655655
---
656656
::
657657

658-
### With icons in items
658+
### With icon in items
659659

660660
You can use the `icon` property to display an [Icon](/components/icon) inside the items.
661661

docs/content/3.components/select.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,7 @@ props:
607607
---
608608
::
609609

610-
### With icons in items
610+
### With icon in items
611611

612612
You can use the `icon` property to display an [Icon](/components/icon) inside the items.
613613

playground/app/pages/components/navigation-menu.vue

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<script setup lang="ts">
2+
import type { NavigationMenuItem } from '@nuxt/ui'
23
import theme from '#build/ui/navigation-menu'
34
45
const colors = Object.keys(theme.variants.color)
@@ -13,6 +14,9 @@ const orientation = ref('horizontal' as const)
1314
const contentOrientation = ref('horizontal' as const)
1415
const highlight = ref(true)
1516
const collapsed = ref(false)
17+
const tooltip = ref(false)
18+
const popover = ref(false)
19+
const arrow = ref(false)
1620
1721
const items = [
1822
[{
@@ -22,9 +26,6 @@ const items = [
2226
label: 'Documentation',
2327
icon: 'i-lucide-book-open',
2428
badge: 10,
25-
tooltip: {
26-
text: 'Documentation'
27-
},
2829
children: [{
2930
label: 'Introduction',
3031
description: 'Fully styled and customizable components for Nuxt.',
@@ -48,9 +49,6 @@ const items = [
4849
to: '/components/navigation-menu',
4950
active: true,
5051
defaultOpen: true,
51-
tooltip: {
52-
text: 'Components'
53-
},
5452
children: [{
5553
label: 'Link',
5654
icon: 'i-lucide-link',
@@ -87,19 +85,13 @@ const items = [
8785
label: 'GitHub',
8886
icon: 'i-simple-icons-github',
8987
to: 'https://github.com/nuxt/ui',
90-
target: '_blank',
91-
tooltip: {
92-
text: 'GitHub'
93-
}
88+
target: '_blank'
9489
}, {
9590
label: 'Help',
9691
icon: 'i-lucide-circle-help',
97-
disabled: true,
98-
tooltip: {
99-
text: 'Help'
100-
}
92+
disabled: true
10193
}]
102-
]
94+
] satisfies NavigationMenuItem[][]
10395
</script>
10496

10597
<template>
@@ -112,10 +104,15 @@ const items = [
112104
<USwitch v-model="collapsed" label="Collapsed" />
113105
<USwitch v-model="highlight" label="Highlight" />
114106
<USelect v-model="highlightColor" :items="colors" placeholder="Highlight color" />
107+
<USwitch v-model="tooltip" label="Tooltip" />
108+
<USwitch v-model="popover" label="Popover" />
109+
<USwitch v-model="arrow" label="Arrow" />
115110
</div>
116111

117112
<UNavigationMenu
118-
arrow
113+
:arrow="arrow"
114+
:tooltip="tooltip"
115+
:popover="popover"
119116
:collapsed="collapsed"
120117
:items="items"
121118
:color="color"

0 commit comments

Comments
 (0)