Skip to main content

React animation example

React Animated Tabs: Sliding Indicator and Content

Tabs should show where you went, not just where you are. The indicator here stretches toward the new tab before its trailing edge catches up, like a caterpillar, and the content slides in from the side you moved toward. Going right slides left, going back slides right.

  • 4.4 KB file
  • 5 live inputs
  • React runtime
Live, try it

How this sliding tabs works

  • The indicator's left and right edges are separate springs with different stiffness, which gives the stretch.
  • Content direction comes from the sign of the index change.
  • The active tab is an input and "change" fires with the tab label.

Add it to your React app

Install exodeui, download the file below, and paste this. The code updates as you customize. Other runtimes are in the other tabs.

import { ExodeUICanvas } from 'exodeui';

// react-animated-tabs.bexode goes in /public (download it below)
export function ReactAnimatedTabs() {
  return (
    <ExodeUICanvas
      src="/react-animated-tabs.bexode"
      fit="Layout"
      autoPlay
      interactive
      onTrigger={(name) => {
        // fires: 'change'
      }}
      style={{ width: '100%', height: 460 }}
    />
  );
}

Inputs

InputTypeDefaultRange
activeNumber00 – 3
tabsTextOverview,Activity,Files,Settings—
accentText#14b8a6hex colour
inkText#f0fdfahex colour
bgText#071211hex colour

Events: change

More React animations

The same idea in other frameworks: Vue slide and fade route transition