Menu item3.0
Installation
npm i @tryg/vue-ui-libraryUsage
Install the component library as a Vue plugin. This globally registers all Anchor components.
import { createApp } from 'vue';
import { ComponentLibrary } from '@tryg/vue-ui-library';
import App from './App.vue';
const app = createApp(App);
app.use(ComponentLibrary);
app.mount('#app');<template>
<anchor-menu-item url="/dashboard">
<span slot="text">Dashboard</span>
</anchor-menu-item>
</template>Import only the components you need for optimal bundle size.
<script setup>
import { AnchorMenuItem } from '@tryg/vue-ui-library';
</script>
<template>
<anchor-menu-item url="/dashboard">
<span slot="text">Dashboard</span>
</anchor-menu-item>
</template>Icon slot
Here's an example of how to use the Menu-Item component with an icon on the left.
<template>
<anchor-menu-item url="/dashboard">
<anchor-icon slot="icon" name="alert-circle" size="medium"></anchor-icon>
<span slot="text">Dashboard</span>
</anchor-menu-item>
</template>Compact
If using the "compact" version of Menu-Item, you should use a "small" size on icon component.
<template>
<anchor-menu-item compact>
<anchor-icon slot="icon" size="small"></anchor-icon>
<span slot="text">Compact size</span>
</anchor-menu-item>
</template>Accessibility
- Renders as a native
<a>element with configurabletabindex(via thetab-indexprop, defaults to0), making it reachable via keyboard Tab navigation. - Keyboard support: Enter and Space activate the menu item when it has focus.
- When used inside a menu container, consider setting
role="menu"on the parent androle="menuitem"on each menu item for proper menu semantics. - When using an icon alongside text, the icon is decorative (
aria-hidden="true") and the text slot provides the accessible name. For icon-only items, add anaria-labelto describe the action.
API
anchor-menu-item
Properties
| Property | Attribute | Description | Type | Default |
|---|---|---|---|---|
box | box | Whether to display the link with a border. | boolean | false |
compact | compact | Whether to display the link in compact mode. | boolean | false |
tabi | tab-index | tabindex is a reserved name so we use tabi which will apply the tabindex attribute Default value should work fine so don't change this unless you have a really good reason to. Set to -1 to disable tabbing. | number | 0 |
url | url | Where should the user go, when clicking on the menu-item. | any | undefined |
uuid | uuid | Give this instance of menu-item a custom ID, or keep the default. | string | uuidv4() |
Events
| Event | Description | Type |
|---|---|---|
clicked | Event dispatched when link-item is clicked {querySelecter}.addEventListener('clicked', ({event}) => {console.log('clicked:', event)}) | CustomEvent<{ url: string; }> |
CSS Custom Properties
| Name | Description |
|---|---|
--background-color | DEPRECATED: kept for backwards compatibility, but will be removed by April 2024 |
--border | DEPRECATED: kept for backwards compatibility, but will be removed by April 2024 |
--border-color | DEPRECATED: kept for backwards compatibility, but will be removed by April 2024 |
--border-size | DEPRECATED: kept for backwards compatibility, but will be removed by April 2024 |
--border-style | DEPRECATED: kept for backwards compatibility, but will be removed by April 2024 |
--font-size | DEPRECATED: kept for backwards compatibility, but will be removed by April 2024 |
--gap | DEPRECATED: kept for backwards compatibility, but will be removed by April 2024 |
--menu-item-background-color | Set the background color of the menu item. |
--menu-item-border | Set the shorthand for the menu item border. |
--menu-item-border-color | Set the color of the menu item border. |
--menu-item-border-size | Set the size of the menu item border. |
--menu-item-border-style | Set the style of the menu item border. |
--menu-item-font-size | Set the font size of the menu item. |
--menu-item-gap | Set the gap property of the menu item. |
--menu-item-line-height | Set the line height of the menu item. |
--menu-item-padding | Set the padding of the menu item. |
--menu-item-radius-bottom-left | Set the bottom-left border radius of the menu item. |
--menu-item-radius-bottom-right | Set the bottom-right border radius of the menu item. |
--menu-item-radius-top-left | Set the top-left border radius of the menu item. |
--menu-item-radius-top-right | Set the top-right border radius of the menu item. |
--menu-item-text-color | Set the text color of the menu item. |
--menu-item-width | Set the width of the menu item. |
--padding | DEPRECATED: kept for backwards compatibility, but will be removed by April 2024 |
--radius-bottom-left | DEPRECATED: kept for backwards compatibility, but will be removed by April 2024 |
--radius-bottom-right | DEPRECATED: kept for backwards compatibility, but will be removed by April 2024 |
--radius-top-left | DEPRECATED: kept for backwards compatibility, but will be removed by April 2024 |
--radius-top-right | DEPRECATED: kept for backwards compatibility, but will be removed by April 2024 |
--text-color | DEPRECATED: kept for backwards compatibility, but will be removed by April 2024 |
--width | DEPRECATED: kept for backwards compatibility, but will be removed by April 2024 |
Dependencies
Depends on
Graph
graph TD;
anchor-menu-item --> anchor-icon
style anchor-menu-item fill:#f9f,stroke:#333,stroke-width:4pxBuilt with StencilJS
Link item
The anchor-link-item component is a custom link component that provides a clickable link with an optional icon and label. It can be used in any web application and supports various props and events for customization and interaction.
Navigation Card
Navigation cards are a core component of Tryg's digital universe. They support a wide range of use cases, from guiding users through content to highlighting key messages.
