Skip to content

Commit 82d124f

Browse files
tmccoy14Shrinks99claude
authored
feat(ui): added onValueChange to tabs component (#61)
Co-authored-by: Henry Wilkinson <henry@wilkinson.graphics> Co-authored-by: Claude <claude@users.noreply.github.com>
1 parent b1eefe9 commit 82d124f

File tree

3 files changed

+26
-15
lines changed

3 files changed

+26
-15
lines changed

packages/demo/src/content/components/tabs.mdx

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -173,20 +173,21 @@ Combine icons with the filled background variant for a more prominent tab design
173173

174174
---
175175

176-
| Prop | Type | Default | Description |
177-
| -------------------- | --------------------------- | --------------- | ----------------------------------------------------------------------------------------------------------------------------------------- |
178-
| `id` | `string` | **Required** | A unique identifier for the tabs instance. Used internally for the animated indicator's layoutId. |
179-
| `items` | `Array<TabItem>` | **Required** | An array of tab items. See TabItem structure below. |
180-
| `className` | `string` || Additional CSS classes to apply to the tabs container. |
181-
| `tabsListBackground` | `"transparent" \| "filled"` | `"transparent"` | The background style for the tabs list. `"transparent"` shows tabs with a transparent background, `"filled"` applies a filled background. |
176+
| Name | Description | Type | Default | Required |
177+
| -------------------- | ------------------------------------------------------------------------ | ------------------------- | ------------- | -------- |
178+
| `id` | Unique identifier for the tabs instance, used for the animated indicator | `string` | - ||
179+
| `items` | Array of tab items (see TabItem structure below) | `Array<TabItem>` | - ||
180+
| `defaultValue` | The value of the tab that should be active by default | `string` | First item ||
181+
| `tabsListBackground` | Background style for the tabs list | `transparent`, `filled` | `transparent` ||
182+
| `onValueChange` | Callback fired when the active tab changes | `(value: string) => void` | - ||
182183

183184
### TabItem Structure
184185

185186
Each item in the `items` array should have the following structure:
186187

187-
| Property | Type | Required | Description |
188-
| --------- | ------------------------------ | -------- | --------------------------------------------------------------------------------------------------------------- |
189-
| `label` | `string` | Yes | The text label displayed on the tab trigger. |
190-
| `value` | `string` | Yes | A unique value that identifies this tab. Used for state management and content matching. |
191-
| `icon` | `React.ReactElement \| string` | No | Optional icon to display alongside the label. Can be a string (icon name from Lucide React) or a React element. |
192-
| `content` | `React.ReactNode` | Yes | The content to display when this tab is active. Can be any valid React node. |
188+
| Name | Description | Type | Default | Required |
189+
| --------- | ------------------------------------------------------------ | ------------------------------ | ------- | -------- |
190+
| `label` | Text label displayed on the tab trigger | `string` | - | |
191+
| `value` | Unique value that identifies this tab | `string` | - | |
192+
| `icon` | Icon to display alongside the label (Lucide name or element) | `React.ReactElement`, `string` | - | |
193+
| `content` | Content to display when this tab is active | `React.ReactNode` | - | |

packages/ui/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "@eqtylab/equality",
33
"description": "EQTYLab's component and token-based design system",
44
"homepage": "https://equality.eqtylab.io/",
5-
"version": "1.0.0",
5+
"version": "1.0.1",
66
"license": "Apache-2.0",
77
"keywords": [
88
"component library",

packages/ui/src/components/tabs/tabs.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,25 @@ interface TabsProps {
2121
}[];
2222
className?: string;
2323
tabsListBackground?: 'transparent' | 'filled';
24+
defaultValue?: string;
25+
onValueChange?: (value: string) => void;
2426
}
2527

26-
const Tabs = ({ id, items, className, tabsListBackground = 'transparent' }: TabsProps) => {
27-
const [activeTab, setActiveTab] = useState(items[0].value);
28+
const Tabs = ({
29+
id,
30+
items,
31+
className,
32+
tabsListBackground = 'transparent',
33+
defaultValue,
34+
onValueChange,
35+
}: TabsProps) => {
36+
const [activeTab, setActiveTab] = useState(defaultValue ?? items[0].value);
2837

2938
const isFilled = tabsListBackground === 'filled';
3039

3140
const handleValueChange = (newTab: string) => {
3241
setActiveTab(newTab);
42+
onValueChange?.(newTab);
3343
};
3444

3545
const renderIcon = (icon?: React.ReactElement | string) => {

0 commit comments

Comments
 (0)