All components

MotionHighlight

Tabs, segmented controls or navigation from data, with one highlight that travels to the selection.

WebReact NativeSelection and paging

Try it

Preparing the example…

Shortest usage

Tabs.jsx
<MotionHighlight
  items={['Overview', 'Activity', 'Settings']}
  value={tab}
  onValueChange={setTab}
  hover
/>;

What it handles for you

  • One highlight moves and resizes between items; style it with highlightClassName.
  • Items come from items, keys from getKey and labels from renderItem.
  • hover makes it follow the pointer and return to the selection.
  • Items can wrap onto several rows and the highlight follows them.
  • Font loading and layout changes are measured again automatically.

Use it for

  • Page tabs.
  • A filter bar.
  • A segmented control in a settings form.

Props

PropTypeDefaultDescription
itemsreadonly T[]—requiredYour data array.
valuekey | null—requiredKey of the highlighted item; null hides the highlight.
onValueChange(key, item) => voidRuns with the key and the item when an item is pressed.
getKey(item) => string | numberitem.idReturns a unique, stable key for an item. Defaults to item.id, or the item itself for strings and numbers.
renderItem(item, { selected, index }) => ReactNodeitem.labelDraws an item; receives whether it is selected.
hoverbooleanfalseFollow the pointer over items and return to value on leave (web).
itemAselement'button'The element for each item.
itemClassNamestringClass for each item element; itemStyle sets its inline style.
highlightClassNamestringClass for the highlight; highlightStyle sets its inline style.
transitionTransitionspringA timing curve { duration, easing } or a spring { tempo: 'spring', spring }. Springs keep their momentum when interrupted.

Other props go to the rendered element, so className, style and event handlers work as usual.

Web and React Native

Each item renders as a button by default (itemAs changes it); pressing it calls onValueChange(key, item).

On React Native items are Pressables; position runs on the native driver and size on a nested view driven by JavaScript.

Used in these examples

Search

Type to search the documentation.