• Stars
    star
    121
  • Rank 293,924 (Top 6 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 9 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A fully accessible, extravagantly flexible, React-powered Tab Panel component

react-aria-tabpanel Build Status


SEEKING CO-MAINTAINERS! Continued development of this project is going to require the work of one or more dedicated co-maintainers (or forkers). If you're interested, please comment in this issue.


A React component that helps you build accessible tabs, by providing keyboard interactions and ARIA attributes described in the WAI-ARIA Tab Panel Design Pattern.

Please check out the demo.

Project Goal

A React component that provides a style- and markup-agnostic foundation for fully accessible tab panels. You provide the inner elements: this module gives you "smart" wrapper components that will handle keyboard interactions and ARIA attributes.

If you think that this component could be even more accessible, please file an issue.

If you like this kind of module (accessible, flexible, unstyled, with framework-agnostic low-level modules) you should also check out these projects:

Installation

npm install react-aria-tabpanel

Dependencies:

The modular approach of this library means you're much better off building it into your code with a module bundling system like browserify or webpack.

But if you need a UMD version (which will include focus-group, but of course not React), you can get it via npmcdm at https://unpkg.com/react-aria-tabpanel@[version-of-choice]/umd/ariaTabPanel.js. If you don't know about unpkg, read about it here.

Usage

var AriaTabPanel = require('react-aria-tabpanel');

// Now use AriaTabPanel.Wrapper, AriaTabPanel.TabList,
// AriaTabPanel.Tab, and AriaTabPanel.TabPanel ...

Examples

Have a look at the code in demo/js/ for varied examples.

API

The AriaTabPanel object exposes four components: Wrapper, TabList, Tab, and TabPanel. Each of these is documented below.

TabList, Tab, and TabPanel must always be wrapped in a Wrapper.

Wrapper

A simple component to group a TabList/Tab/TabPanel set, coordinating their interactions. It should wrap your entire tab panel widget.

All TabList, Tab, and TabPanel components must be nested within a Wrapper component.

Each wrapper should contain only one TabList, multiple Tabs, and multiple TabPanels.

props

All props are optional.

onChange { Function }: A callback to run when the user changes tabs (i.e. clicks a tab or navigates to another with the arrow keys). It will be passed the the newly activated tab's ID.

By default, the tabs maintain state internally. Use this prop to make the tabs "stateless," and take control yourself. You can run any arbitrary code when the user performs an action that indicates a tab change (e.g. change your route and update a store, etc.).

Stateless tabs may make sense if you want to manage the tab's state in a Redux store, for example.

letterNavigation { Boolean }: If true, the tabs can be navigated not only by arrow keys, but also by letters. This library uses focus-group, so you can read about how letter-key navigation in that module's "String Searching" docs.

activeTabId { String }: Directly tell the tabs which one is active. By default, the first tab provided will be the initially active tab, and from then on the active tab state is managed internally. This prop, then, can be used two ways:

  • to give the tabs an initial active tab other than the first, or
  • if you have seized control of the state (via an onChange function), to continuously tell the tabs which one is active.

tag { String }: The HTML tag for this element. Default: 'div'.

Any additional props (e.g. id, className, data-whatever) are passed directly to the HTML element.

TabList

Wrap the Tabs with a TabList.

A TabList's children should be React elements.

props

All props are optional.

tag { String }: The HTML tag for this element. Default: 'div'.

role { String }: The role attribute for the element. Default: 'tablist'. The parameter is useful when you have want the same interaction as tabs but want screen readers to describe the content differently.

Any additional props (e.g. id, className, data-whatever) are passed directly to the HTML element, unless TabList needs them itself.

Tab

The active tabs is focusable. Inactive tabs are not.

You can switch from one tab to another by clicking with the mouse or using the arrow keys.

A Tab's children may be any of the following:

  • A string
  • A React element
  • A function accepting the following tab-state object:
    {
      isActive: Boolean // self-explanatory
    }

props

All props are optional except id.

id { String } Required. The id attribute for this element and the identifier that ties this Tab to its TabPanel (so there should be a TabPanel component with a matching tabId).

active { Boolean }: If you are controlling the state yourself (with an onChange function on your Wrapper), use this prop to tell the Tab whether it is active or not.

letterNavigationText { String }: If you are using letter-key navigation (having turned it on via the prop on Wrapper), you can use this prop to specify this Tabs's searchable text. By default, the element's textContent is used โ€” which is usually what you want.

tag { String }: The HTML tag for this element. Default: 'div'.

role { String }: The role attribute for the element. Default: 'tab'. The parameter is useful when you have want the same interaction as tabs but want screen readers to describe the content differently.

Any additional props (e.g. className, data-whatever) are passed directly to the HTML element, unless Tab needs them itself.

TabPanel

The content area for your tabs. The active tab panel is visible; the inactive tab panels are not.

A TabPanels's children may be any of the following:

  • A string
  • A React element
  • A function accepting the following panel-state object:
    {
      isActive: Boolean // self-explanatory
    }

props

All props are optional except tabId.

tabId { String }: Required. The id of the Tab that corresponds to this TabPanel.

active { Boolean }: If you are controlling the state yourself (with an onChange function on your Wrapper), use this prop to tell the TabPanel whether it is active or not.

tag { String }: The HTML tag for this element. Default: 'div'.

role { String }: The role attribute for the element. Default: 'tabpanel'. The parameter is useful when you have want the same interaction as tabs but want screen readers to describe the content differently.

Any additional props (e.g. className, data-whatever) are passed directly to the HTML element, unless TabPanel needs them itself.

Contributing & Development

Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.

Lint with npm run lint.

Test with npm run test-dev, which will give you a URL to open in your browser. Look at the console log for TAP output.

Tests

The demo serves for integration testing. If you'd like to help write decent automated tests, please file a PR.

More Repositories

1

scalable-css-reading-list

Collected dispatches from The Quest for Scalable CSS
1,534
star
2

react-aria-modal

A fully accessible React modal built according WAI-ARIA Authoring Practices
JavaScript
1,036
star
3

react-aria-menubutton

A fully accessible, easily themeable, React-powered menu button
JavaScript
456
star
4

no-scroll

Disable scrolling on an element that would otherwise scroll
HTML
245
star
5

list-selectors

List the selectors used in your CSS. Use as a standalone function, CLI, or PostCSS plugin.
JavaScript
97
star
6

react-displace

A higher order component that displaces your component into a remote region of the DOM
JavaScript
51
star
7

jquery.cssAnimateAuto

A jQuery plugin that uses CSS transitions to animate an element's height or width to auto.
JavaScript
50
star
8

focus-group

Create a group of nodes with special focusing powers
JavaScript
45
star
9

postcss-simple-extend

A PostCSS plugin for extending placeholder selectors
JavaScript
34
star
10

stylelint-checkstyle-formatter

Output Checkstyle XML reports of stylelint results
JavaScript
16
star
11

stylelint-statement-max-nesting-depth

A stylelint custom rule to limit nesting depth
JavaScript
14
star
12

teeny-tap

Listen for both clicks and click-like touches (not scrolls or drags)
JavaScript
13
star
13

postcss-log-warnings

Log PostCSS warnings in the console
JavaScript
13
star
14

grunt-spritesmith-hd

An adaptation of grunt-spritesmith to produce hd-ready sprites
JavaScript
10
star
15

locate-chrome

Locate the Google Chrome browser on your system
JavaScript
10
star
16

gifs

Some gifs
8
star
17

jquery.animateAuto

A jQuery plugin for using jQuery animation to animate an element's height or width between something and `auto`.
JavaScript
7
star
18

style-search

Search CSS(-like) strings
JavaScript
7
star
19

babel-plugin-transform-syntax-highlight

Perform syntax highlighting of string and template literals during Babel compilation, rather than at runtime
JavaScript
5
star
20

remark-preset-davidtheclark

My remark preset, for keeping Markdown documentation tidy.
JavaScript
4
star
21

react-rootless-state

A React state container that lives outside the component tree
JavaScript
4
star
22

js-automation-examples

JavaScript
3
star
23

postcss-simple-mixin

A PostCSS plugin that can clone declarations from abstract definitions into any rule sets that follow
JavaScript
3
star
24

turborepo-jest-test

TypeScript
2
star
25

babel-plugin-transform-markdown-in-jsx

Transform Markdown inside JSX to DOM elements at compile time
JavaScript
2
star
26

unfinishedToggler

A simple style-agnostic jQuery-based plugin for toggling groups of elements on and off.
JavaScript
1
star
27

gentlereader

The Gentle Reader
JavaScript
1
star
28

locate-safari

Find Safari on your system
JavaScript
1
star
29

locate-firefox

Find Firefox on your system
JavaScript
1
star
30

eslint-config-davidtheclark-node

My ESLint config for Node (v4+)
JavaScript
1
star
31

locate-ie

Approximates the current location of Internet Explorer on your system
JavaScript
1
star
32

stylelint-html

Experiment
1
star