Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/esm-only.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'react-tabs': major
---

`react-tabs` now ships a single native ES module build. Import components from `react-tabs` and stylesheets from `react-tabs/style/`. Replace deep imports from `react-tabs/lib/` or `react-tabs/esm/` with imports from the package root.

If your CommonJS app uses `require('react-tabs')`, use a Node version with synchronous ESM support, such as Node 22.12 or newer, or load the package with dynamic `import()`.
5 changes: 5 additions & 0 deletions .changeset/hidden-inactive-panels.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'react-tabs': major
---

Inactive tab panels now use the HTML `hidden` attribute, so they stay hidden without a stylesheet. `forceRender` and `forceRenderTabPanel` still keep their contents mounted. See the [migration guide](https://github.com/reactjs/react-tabs/blob/main/MIGRATION.md#account-for-hidden-panels-in-exit-animations) for custom styles and exit animations.
5 changes: 5 additions & 0 deletions .changeset/keep-disabled-tab-selection.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'react-tabs': patch
---

Keep the current selection and skip `onSelect` when Home or End is pressed and all tabs are disabled.
24 changes: 24 additions & 0 deletions .changeset/keyed-tabs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
'react-tabs': major
---

Tabs and panels now pair by a shared `itemKey` instead of their positions. The key can be a string or a finite number. Give each item a stable key so selection survives reorder, insertion, and removal of another tab. Keyboard navigation still follows the tab list's rendered order.

For uncontrolled tabs, replace `defaultIndex` with `defaultKey`. An explicit initial key is required, even if you previously relied on the first tab being selected automatically.

```tsx
<Tabs defaultKey={0}>
<TabList>
<Tab itemKey={0}>Overview</Tab>
<Tab itemKey={1}>Billing</Tab>
</TabList>
<TabPanel itemKey={0}>Overview content</TabPanel>
<TabPanel itemKey={1}>Billing content</TabPanel>
</Tabs>
```

For controlled tabs, replace `selectedIndex={index}` with `selectedKey={key}`. Keep `onSelect`, but update handlers to receive keys instead of positions. For example, use `<Tabs selectedKey={selectedKey} onSelect={setSelectedKey}>` and give the matching tab and panel the same key. TypeScript state can use the exported `TabKey` type.

If an uncontrolled selection disappears, the group selects the first enabled tab with a matching panel and calls `onSelect` with an undefined event. Controlled callers choose their own replacement. Returning `false` still cancels mouse and keyboard selections.

`TabsProps` is now a union. If your TypeScript wrapper used `interface CustomProps extends TabsProps`, use `type CustomProps = TabsProps & { … }` instead.
7 changes: 7 additions & 0 deletions .changeset/numeric-tab-index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'react-tabs': major
---

`Tab` now uses React's numeric `tabIndex` type. Replace string values such as `<Tab tabIndex="0">Overview</Tab>` with numbers such as `<Tab tabIndex={0}>Overview</Tab>`.

When `tabIndex` is omitted, the selected tab still gets `0`. If there is no selection, the first enabled tab with a matching panel gets `0` so keyboard users can enter the group.
5 changes: 5 additions & 0 deletions .changeset/react-server-components.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'react-tabs': patch
---

Mark the `react-tabs` entry point with `'use client'` so React Server Components can import it directly. Put event handlers such as `onSelect` in a Client Component.
5 changes: 5 additions & 0 deletions .changeset/restore-tab-focus.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'react-tabs': patch
---

Restore keyboard focus to the replacement when a focused tab is removed and selection changes. `defaultFocus` now waits for a selected tab to become available, including when an invalid default key falls back to the first enabled tab.
5 changes: 5 additions & 0 deletions .changeset/skip-unrelated-tab-events.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'react-tabs': patch
---

Skip tab collection scans for clicks and key presses outside the group's tabs, and for keys that the group doesn't handle. Consumer event handlers still receive these events.
5 changes: 5 additions & 0 deletions .changeset/skip-unused-tab-diagnostics.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'react-tabs': patch
---

Skip collecting developer warnings when scanning tabs for interactions, focus, or production rendering.
5 changes: 5 additions & 0 deletions .changeset/skip-unused-tab-fallback.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'react-tabs': patch
---

Avoid an extra render when the first enabled tab changes and the current selection still has a matching tab and panel.
7 changes: 7 additions & 0 deletions .changeset/standard-keyboard-events.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'react-tabs': patch
---

Use the standard `KeyboardEvent.key` value for tab navigation and activation, including when a key has been remapped.

This removes the fallback for legacy browsers that only report `keyCode`. Every browser version listed in the README’s compatibility table already supports `KeyboardEvent.key`, so the documented browser support stays the same. [Browser compatibility for `KeyboardEvent.key`](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key#browser_compatibility)
5 changes: 5 additions & 0 deletions .changeset/tab-panel-class-defaults.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'react-tabs': patch
---

Apply the default `TabPanel` classes when `className` or `selectedClassName` is explicitly `undefined`.
5 changes: 5 additions & 0 deletions .changeset/tabs-event-handlers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'react-tabs': patch
---

`Tabs` now calls the provided `onClick` and `onKeyDown` handlers before its own handlers. Calling `event.preventDefault()` skips the built-in tab handling for that event.
39 changes: 39 additions & 0 deletions .changeset/tabs-item-context.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
'react-tabs': major
---

Tab and panel state comes from React context. Custom wrappers render the built-in component and forward `itemKey`. Remove the old `tabsRole` assignment and use ordinary React component types in place of `ReactTabsFunctionComponent`.

If your wrapper reads `selected` to apply a CSS class, move that class to the built-in `selectedClassName` prop.

**Before**

```jsx
import { Tab } from 'react-tabs';

function CustomTab({ selected, ...props }) {
return (
<Tab
{...props}
className={selected ? 'custom-tab is-active' : 'custom-tab'}
/>
);
}

CustomTab.tabsRole = 'Tab';
```

**After**

```tsx
import { Tab } from 'react-tabs';
import type { TabProps } from 'react-tabs';

function CustomTab(props: TabProps) {
return (
<Tab {...props} className="custom-tab" selectedClassName="is-active" />
);
}
```

The built-in `Tab` applies `is-active` when selected. If your custom UI needs the selection in JavaScript, control `<Tabs>` with `selectedKey` and `onSelect`.
7 changes: 7 additions & 0 deletions .changeset/tabs-rendered-direction.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'react-tabs': major
---

Left and right arrow navigation now follows the tab group's rendered direction, including the HTML `dir` attribute and inherited direction.

If your group needs to stay left-to-right on an RTL page, set `dir="ltr"` on `Tabs` and make sure any CSS `direction` rule agrees.
7 changes: 7 additions & 0 deletions .changeset/typed-tabs-callbacks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'react-tabs': major
---

Build `react-tabs` with TypeScript and generate its declarations from source.

The callback types now match their runtime values. For user interactions, `onSelect` receives a React mouse or keyboard event. Use `event.nativeEvent` for the underlying DOM event. Automatic recovery in an uncontrolled group reports an undefined event. `domRef` receives the root `HTMLDivElement` or `null`, so typed callbacks must handle `null` on unmount.
5 changes: 5 additions & 0 deletions .changeset/v7-migration-guide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'react-tabs': major
---

Upgrading from v6? See the [v6 to v7 migration guide](https://github.com/reactjs/react-tabs/blob/main/MIGRATION.md#v6-to-v7) for the breaking changes and migration examples.
13 changes: 12 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,15 @@ jobs:
run: pnpm install --frozen-lockfile

- name: Lint
run: pnpm lint
run: pnpm run lint

- name: Type check
run: pnpm run typecheck

- name: Build library
run: pnpm run build

- name: Check native Node entry points
run: |
node --input-type=module -e "import { Tabs } from 'react-tabs'; if (typeof Tabs !== 'function') process.exit(1)"
node --input-type=commonjs -e "if (typeof require('react-tabs').Tabs !== 'function') process.exit(1)"
216 changes: 216 additions & 0 deletions MIGRATION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
# Migration guide

## v6 to v7

### Match each tab and panel with `itemKey`

**What changed**

v6 matched tabs and panels by render order. v7 matches them by an explicit `itemKey`, so panels can render in a different order from their tabs.

**How to migrate**

Give each `<Tab>` and its `<TabPanel>` the same `itemKey`. Use a unique key per pair within the group. Old indexes work as numeric keys for a fixed list. For a dynamic list, use a stable item ID so the key stays with the item through reordering or removal.

```tsx
import { Tab, TabList, TabPanel, Tabs } from 'react-tabs';

function AccountTabs() {
return (
<Tabs defaultKey={0}>
<TabList>
<Tab itemKey={0}>Overview</Tab>
<Tab itemKey={1}>Billing</Tab>
</TabList>
<TabPanel itemKey={0}>Account overview</TabPanel>
<TabPanel itemKey={1}>Billing settings</TabPanel>
</Tabs>
);
}
```

Keys can be nonempty strings or finite numbers. Match the type on both sides, since `1` and `'1'` are different keys. Keep the panel element mounted even if its contents load on demand.

### Account for hidden panels in exit animations

**What changed**

In v6, CSS controlled whether an inactive panel was visible. Inactive panels now get the HTML `hidden` attribute as soon as selection changes, even with `forceRender` or `forceRenderTabPanel`. The default stylesheet no longer sets panel visibility.

**How to migrate**

Check custom panel styles that set `display` so they respect `[hidden]`. For example, apply `display: grid` only to `.my-panel:not([hidden])`.

If you animate an outgoing panel, keep `forceRender` or `forceRenderTabPanel` enabled for its contents and override `display` on that panel's `[hidden]` element only while its exit animation runs. Mark the outgoing panel `inert` during that interval to keep it out of keyboard navigation and the accessibility tree. Remove the display override when the animation ends.

### Replace `defaultIndex` with `defaultKey`

**What changed**

In v6, uncontrolled tabs used `defaultIndex` and selected the first tab when it was omitted. In v7, they require an explicit `defaultKey`.

**How to migrate**

Set `defaultKey` to the `itemKey` of the tab you want to open first. Add it even if you previously omitted `defaultIndex`.

```diff
- <Tabs defaultIndex={1}>
+ <Tabs defaultKey={1}>
```

### Replace `selectedIndex` with `selectedKey`

**What changed**

In v6, `selectedIndex` identified the controlled selection by position. In v7, `selectedKey` identifies it by `itemKey`.

**How to migrate**

Store the active `itemKey` in state, pass it as `selectedKey`, and update it in `onSelect`. If you remove the selected tab, set a replacement key yourself. The group shows no selection while the key is missing.

```diff
- <Tabs selectedIndex={activeIndex} onSelect={setActiveIndex}>
+ <Tabs selectedKey={activeKey} onSelect={setActiveKey}>
```

### Use keys in `onSelect`

**What changed**

The first two `onSelect` arguments changed from the next and previous numeric indexes to the next and previous `itemKey` values.

**How to migrate**

Update handlers that use the arguments as array indexes. For example, replace `tabs[nextIndex]` with `tabs.find((tab) => tab.id === nextKey)` if you use each item's `id` as its `itemKey`. Import `TabKey` from `react-tabs` for explicit TypeScript annotations.

### Use `nativeEvent` when you need a DOM event

**What changed**

v6 declared the `onSelect` event as a DOM `Event`. v7 types user interactions as the React mouse or keyboard events the callback receives at runtime.

**How to migrate**

Let TypeScript infer the event type in your handler. If a helper expects a DOM `Event`, guard against `undefined` and pass `event.nativeEvent`.

### Handle automatic selection when a tab is removed

**What changed**

In v6, removing a tab could shift the selection to another item at the same index. In v7, removing another tab preserves the selected key. If you remove the selected tab from an uncontrolled group, v7 selects the first enabled tab with a matching panel and calls `onSelect` with `undefined` as the event.

**How to migrate**

Check that the event exists before reading it in `onSelect`. Returning `false` still cancels mouse and keyboard selections. The callback reports an automatic replacement after it has already been selected.

### Match horizontal arrow navigation to the tab group's direction

**What changed**

In v6, left and right arrow keys used the `direction` prop and defaulted to LTR, even when the tab group displayed right-to-left. In v7, the keys follow the group's rendered direction, which can come from HTML or CSS. A group that inherits RTL from the page now also uses RTL arrow navigation.

**How to migrate**

If horizontal navigation should follow the page, let the group inherit its direction. If the group should stay left-to-right on an RTL page, set `dir="ltr"` on `<Tabs>` and make sure any CSS `direction` rule on the group also uses `ltr`.

### Pass a number for the HTML `tabindex` attribute

**What changed**

`Tab`'s `tabIndex` prop changed from a string in v6 to a number in v7. It sets the HTML `tabindex` attribute, which controls keyboard tab order.

**How to migrate**

Replace string values with numbers. Keep the same numeric value to preserve the tab order.

```diff
- tabIndex="0"
+ tabIndex={0}
```

### Handle `null` in `domRef`

**What changed**

v6 typed the `domRef` argument as an optional `HTMLElement`. v7 types it as `HTMLDivElement | null`, including the `null` React passes on unmount.

**How to migrate**

Check for `null` before using the element. If you annotate the callback parameter, use `HTMLDivElement | null`.

### Remove `tabsRole` assignments

**What changed**

v6 used the `tabsRole` static property to recognize custom wrappers. v7 removed it.

**How to migrate**

Delete assignments such as `CustomTab.tabsRole = 'Tab'`. Render the built-in component inside your wrapper and forward the props it needs, including `itemKey` for tabs and panels.

### Replace `ReactTabsFunctionComponent`

**What changed**

v7 removed the `ReactTabsFunctionComponent` type, which v6 used to describe components with a `tabsRole` static.

**How to migrate**

Remove the type import and annotate your wrapper's props with the type of the component it renders.

```tsx
import { Tab } from 'react-tabs';
import type { TabProps } from 'react-tabs';

function CustomTab(props: TabProps) {
return <Tab {...props} />;
}
```

### Replace reads of private wrapper props

**What changed**

v6 passed private props such as `selected`, `focus`, and `tabRef` to custom wrappers. In v7, the built-in components get their state from context.

**How to migrate**

Remove reads of those private props. Use `selectedClassName` for styling and let the built-in `Tab` handle focus. If custom logic needs to know which tab is active, read the key from your controlled `Tabs` state.

### Use a type intersection to extend `TabsProps`

**What changed**

`TabsProps` changed from an interface to a union of controlled and uncontrolled props.

**How to migrate**

Replace `interface TrackedTabsProps extends TabsProps` with a type alias that uses `&` to add your own props.

```tsx
import type { TabsProps } from 'react-tabs';

type TrackedTabsProps = TabsProps & { analyticsName: string };
```

### Switch to the ESM package entry point

**What changed**

v6 shipped a CommonJS build and an ESM build for bundlers. v7 ships a single native ES module build and declares its public entry points with `exports`.

**How to migrate**

Import components from `react-tabs`. If you used a deep import from `react-tabs/lib/` or `react-tabs/esm/`, switch to the package root. The documented stylesheet paths, such as `react-tabs/style/react-tabs.css`, still work.

If your CommonJS app calls `require('react-tabs')`, use a Node version with synchronous ESM support, such as Node 22.12 or newer. On older versions, load the package with dynamic `import('react-tabs')`.

### Import types from the package root

**What changed**

v6 shipped an `index.d.ts` at the package root. v7 generates its declarations alongside the ESM build and points TypeScript to them through the package metadata.

**How to migrate**

If you imported `react-tabs/index.d.ts` directly, change the import to `import type { TabsProps } from 'react-tabs'`.
Loading
Loading