Skip to content

Commit

Permalink
Update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
mirka committed Feb 16, 2024
1 parent 17f4a1c commit 340f185
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions packages/components/src/tabs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Tabs organizes content across different screens, data sets, and interactions. It

#### Uncontrolled Mode

Tabs can be used in an uncontrolled mode, where the component manages its own state. In this mode, the `initialTabId` prop can be used to set the initially selected tab. If this prop is not set, the first tab will be selected by default. In addition, in most cases where the currently active tab becomes disabled or otherwise unavailable, uncontrolled mode will automatically fall back to selecting the first available tab.
Tabs can be used in an uncontrolled mode, where the component manages its own state. In this mode, the `defaultTabId` prop can be used to set the initially selected tab. If this prop is not set, the first tab will be selected by default. In addition, in most cases where the currently active tab becomes disabled or otherwise unavailable, uncontrolled mode will automatically fall back to selecting the first available tab.

```jsx
import { Tabs } from '@wordpress/components';
Expand All @@ -24,25 +24,25 @@ const onSelect = ( tabName ) => {
};

const MyUncontrolledTabs = () => (
<Tabs onSelect={onSelect} initialTab="tab2">
<Tabs.TabList >
<Tabs.Tab id={ 'tab1' } title={ 'Tab 1' }>
<Tabs onSelect={ onSelect } defaultTabId="tab2">
<Tabs.TabList>
<Tabs.Tab tabId="tab1" title="Tab 1">
Tab 1
</Tabs.Tab>
<Tabs.Tab id={ 'tab2' } title={ 'Tab 2' }>
<Tabs.Tab tabId="tab2" title="Tab 2">
Tab 2
</Tabs.Tab>
<Tabs.Tab id={ 'tab3' } title={ 'Tab 3' }>
<Tabs.Tab tabId="tab3" title="Tab 3">
Tab 3
</Tabs.Tab>
</Tabs.TabList>
<Tabs.TabPanel id={ 'tab1' }>
<Tabs.TabPanel tabId="tab1">
<p>Selected tab: Tab 1</p>
</Tabs.TabPanel>
<Tabs.TabPanel id={ 'tab2' }>
<Tabs.TabPanel tabId="tab2">
<p>Selected tab: Tab 2</p>
</Tabs.TabPanel>
<Tabs.TabPanel id={ 'tab3' }>
<Tabs.TabPanel tabId="tab3">
<p>Selected tab: Tab 3</p>
</Tabs.TabPanel>
</Tabs>
Expand All @@ -51,7 +51,7 @@ const MyUncontrolledTabs = () => (

#### Controlled Mode

Tabs can also be used in a controlled mode, where the parent component specifies the `selectedTabId` and the `onSelect` props to control tab selection. In this mode, the `initialTabId` prop will be ignored if it is provided. If the `selectedTabId` is `null`, no tab is selected. In this mode, if the currently selected tab becomes disabled or otherwise unavailable, the component will _not_ fall back to another available tab, leaving the controlling component in charge of implementing the desired logic.
Tabs can also be used in a controlled mode, where the parent component specifies the `selectedTabId` and the `onSelect` props to control tab selection. In this mode, the `defaultTabId` prop will be ignored if it is provided. If the `selectedTabId` is `null`, no tab is selected. In this mode, if the currently selected tab becomes disabled or otherwise unavailable, the component will _not_ fall back to another available tab, leaving the controlling component in charge of implementing the desired logic.

```jsx
import { Tabs } from '@wordpress/components';
Expand All @@ -71,24 +71,24 @@ const MyControlledTabs = () => (
onSelect( selectedId );
} }
>
<Tabs.TabList >
<Tabs.Tab id={ 'tab1' } title={ 'Tab 1' }>
<Tabs.TabList>
<Tabs.Tab tabId="tab1" title="Tab 1">
Tab 1
</Tabs.Tab>
<Tabs.Tab id={ 'tab2' } title={ 'Tab 2' }>
<Tabs.Tab tabId="tab2" title="Tab 2">
Tab 2
</Tabs.Tab>
<Tabs.Tab id={ 'tab3' } title={ 'Tab 3' }>
<Tabs.Tab tabId="tab3" title="Tab 3">
Tab 3
</Tabs.Tab>
</Tabs.TabList>
<Tabs.TabPanel id={ 'tab1' }>
<Tabs.TabPanel tabId="tab1">
<p>Selected tab: Tab 1</p>
</Tabs.TabPanel>
<Tabs.TabPanel id={ 'tab2' }>
<Tabs.TabPanel tabId="tab2">
<p>Selected tab: Tab 2</p>
</Tabs.TabPanel>
<Tabs.TabPanel id={ 'tab3' }>
<Tabs.TabPanel tabId="tab3">
<p>Selected tab: Tab 3</p>
</Tabs.TabPanel>
</Tabs>
Expand Down Expand Up @@ -120,7 +120,7 @@ When `true`, the tab will be selected when receiving focus (automatic tab activa
- Required: No
- Default: `true`

###### `initialTabId`: `string`
###### `defaultTabId`: `string`

The id of the tab to be selected upon mounting of component. If this prop is not set, the first tab will be selected by default. The id provided will be internally prefixed with a unique instance ID to avoid collisions.

Expand Down

0 comments on commit 340f185

Please sign in to comment.