A sliding indicator that shows the selected item of a row or a column of tabs.
ax-navigation marks the selected one of its ax-navigation-item children with a line. When you pick another item, the line stretches toward it and then shrinks onto it.
This package is no longer developed. It does not run on Surface and stays as it is.
Installation
npm install @ax-design/navigationand import it:
import { register } from '@ax-design/navigation';
register();If you don't use a bundler, load the script instead:
<script src="https://unpkg.com/@ax-design/navigation/build/main.js"></script>
<script>AxNavigation.register();</script>Horizontal
The default is a row of items with the line below the selected one. Click an item to move the line.
The color and the width of the line are custom properties. The width is its thickness.
Try it
<ax-navigation>
<ax-navigation-item>Home</ax-navigation-item>
<ax-navigation-item>Apps</ax-navigation-item>
<ax-navigation-item>Games</ax-navigation-item>
</ax-navigation>ax-navigation {
--navigation-indicator-color: rgb(255, 255, 255);
--navigation-indicator-width: 2px;
}Vertical
Add the vertical attribute and the items stack in a column, with the line on the left.
The speed is the time the line takes to move from one item to another.
Try it
<ax-navigation vertical>
<ax-navigation-item>Home</ax-navigation-item>
<ax-navigation-item>Apps</ax-navigation-item>
<ax-navigation-item>Games</ax-navigation-item>
</ax-navigation>ax-navigation {
--navigation-indicator-speed: 600ms;
}Default item
The first item is selected at the start. Add the default attribute to another item to select that one instead.
Try it
<ax-navigation>
<ax-navigation-item>Home</ax-navigation-item>
<ax-navigation-item default>Apps</ax-navigation-item>
<ax-navigation-item>Games</ax-navigation-item>
</ax-navigation>ax-navigation {
--navigation-indicator-color: rgb(255, 255, 255);
}Switch event
The ax-navigation element fires a switch event when the line goes from one item to another. The detail has the item before (from) and the item after (to). The event does not bubble.
Try it
const navigation = document.querySelector('ax-navigation');
navigation.addEventListener('switch', (event) => {
console.log(event.detail.from.innerText, event.detail.to.innerText);
});Reference
vertical attribute
boolean, default off
On ax-navigation: a column of items with the line on the left. Without it (or with horizontal) the items are in a row.
default attribute
boolean
On ax-navigation-item: the item that is selected at the start. Without it, the first item.
--navigation-indicator-speed property
<time>, default 600ms
How long the line takes to move to another item.
--navigation-indicator-color property
<color>, default black
The color of the line.
--navigation-indicator-width property
<length>, default 2px
The thickness of the line.
switch event
CustomEvent<{ from, to }>
Fired on ax-navigation when the line goes to another item. Does not bubble, is not cancelable. from and to are the items.