# Build a Spring-Animated Navigation Indicator

`LiquidTabBar` can add a stretching selection capsule to a strip of ordinary links. Use native links for page navigation, `aria-current` to mark the active destination, and let the spring handle the decoration.

## Add the selection indicator

Give each participating link an `href` and set `aria-current="page"` on the link matching the rendered route. Lay out the links with flexbox and keep them inside the navigation element you pass to the controller.

```ts
import { LiquidTabBar } from 'quick-liquid';

export function attachIndicator(nav: HTMLElement) {
  const links = [...nav.querySelectorAll<HTMLAnchorElement>('a[href]')];
  if (links.length === 0) return;

  const indicator = new LiquidTabBar(nav, links, {
    glass: true,
    spring: 'snappy',
    hoverFollower: false,
  });

  function selectRoute(animate: boolean) {
    const index = links.findIndex((link) => link.getAttribute('aria-current') === 'page');
    if (index < 0) return;
    if (animate) indicator.select(index);
    else indicator.selectImmediate(index);
  }

  selectRoute(false);
  return { selectRoute, destroy: () => indicator.destroy() };
}
```

If the route changes without remounting the nav, update the links' `aria-current` attributes and then call `selectRoute(true)`. An immediate initial selection puts the capsule on the active link before it gets a chance to slide from the first item. After changing the actual items, rebuild the controller or supply the new elements with `updateItems`.

## Test it on links that differ in width

Try the shortest and longest labels back to back. The motion is easiest to judge when the indicator has to change both position and width. Then tab through the strip and confirm the keyboard focus ring remains easy to distinguish from the selected route. For an inline control that switches content within the current view, try [the React segmented control](/blog/liquid-segmented-control-react/).
