Navigation

Tabs

Panels of related content, one visible at a time, following the ARIA tabs pattern with arrow-key navigation.

JxTabs import 'package:jx_cli/ui.dart' New in 0.0.3

Preview

When to use it

  • Settings split in a few sections.
  • Code samples in several languages.
  • Views of the same object (overview, activity, members).

Minimal example

Dart
JxTabs(id: 'settings', [
  JxTab(label: 'Profile', children: [ProfileForm()]),
  JxTab(label: 'Billing', children: [BillingForm()]),
])

Complete example

A full Jaspr component you can paste into a project.

Dart
import 'package:jaspr/jaspr.dart';
import 'package:jx_cli/ui.dart';

/// Tabs need the browser for clicks and arrow keys: make the page part
/// that holds them a client component.
@client
class ProjectTabs extends StatelessComponent {
  const ProjectTabs({super.key});

  @override
  Component build(BuildContext context) {
    return JxTabs(
      id: 'project',
      label: 'Project',
      onChange: (index) => print('Tab $index'),
      [
        const JxTab(label: 'Overview', children: [JxCard(title: 'Status', [JxBadge('Live', tone: JxTone.success)])]),
        const JxTab(label: 'Activity', children: [JxEmptyState(title: 'No activity yet')]),
        const JxTab(label: 'Members', children: [JxAvatar(name: 'Ada Lovelace')]),
        const JxTab(label: 'Archive', disabled: true, children: []),
      ],
    );
  }
}

Properties

Property Type Default Description
tabs List<JxTab> required The tabs, in order.
id String required Prefix of the tab and panel ids; unique on the page.
label String? null Accessible name of the tab list.
initialIndex int 0 Tab selected on first render (clamped).
orientation JxTabsOrientation horizontal vertical puts the list beside the panel from md , with Up and Down keys.
classes String? null Extra JX classes, appended after the component classes.

Related types

Name Role
JxTab(label:, children:, disabled: false) One tab and its panel.
JxTabsOrientation horizontal, vertical.

Events

Callback Type Fires when
onChange ValueChanged<int>? Another tab is selected, by click or keyboard; gives its index.

Customizing

  • Pass classes to add or override utilities: they come last, so classes: 'w:full' wins over the default width.
  • The selected tab is underlined with blue-700 (a right border when vertical), like the other active states.

Responsive

  • The tab list scrolls sideways when the tabs do not fit; they never wrap.
  • Vertical tabs stack above the panel on phones and move beside it from the md breakpoint.

Accessibility

  • role="tablist", tab and tabpanel, linked by aria-controls and aria-labelledby; the selected tab has aria-selected="true".
  • Only the selected tab is in the tab order: Left and Right (Up and Down when vertical) move and select, Home and End jump to the ends, disabled tabs are skipped.
  • Vertical lists carry aria-orientation="vertical".
  • Panels are focusable, so keyboard users reach content without interactive elements.

Limitations

  • Needs to run in the browser (a @client component): rendered on the server alone, it shows the first panel and does not switch.
  • Selection follows focus (no manual activation mode).