Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/1531 #1545

Merged
merged 2 commits into from
Sep 1, 2023
Merged
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
5 changes: 5 additions & 0 deletions .changeset/big-moose-switch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@nextui-org/tabs": patch
---

Fix #1531 title props filtered, titleValue prop added to pass the title to the HTML element.
11 changes: 6 additions & 5 deletions apps/docs/content/docs/components/tabs.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Tabs organize content into multiple sections and allow users to navigate between

---

<CarbonAd/>
<CarbonAd />

## Import

Expand Down Expand Up @@ -157,10 +157,11 @@ You can customize the `Tabs` component by passing custom Tailwind CSS classes to

### Tab Props

| Attribute | Type | Description | Default |
| ---------- | ----------- | ----------------------- | ------- |
| children\* | `ReactNode` | The content of the tab. | - |
| title | `ReactNode` | The title of the tab. | - |
| Attribute | Type | Description | Default |
| ---------- | ----------- | ------------------------------------------------------------------------------------------ | ------- |
| children\* | `ReactNode` | The content of the tab. | - |
| title | `ReactNode` | The title of the tab. | - |
| titleValue | `string` | A string representation of the item's contents. Use this when the `title` is not readable. | - |

#### Motion Props

Expand Down
7 changes: 6 additions & 1 deletion packages/components/tabs/src/base/tab-item-base.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {BaseItem, ItemProps} from "@nextui-org/aria-utils";
import {ReactNode} from "react";
interface Props<T extends object = {}> extends Omit<ItemProps<"div", T>, "children" | "title"> {
interface Props<T extends object = {}> extends Omit<ItemProps<"button", T>, "children" | "title"> {
/**
* The content of the component.
*/
Expand All @@ -9,6 +9,11 @@ interface Props<T extends object = {}> extends Omit<ItemProps<"div", T>, "childr
* The title of the component.
*/
title?: ReactNode | null;
/**
* A string representation of the item's contents. Use this when the title is not readable.
* This will be used as native `title` attribute.
* */
titleValue?: string;
}

export type TabItemProps<T extends object = {}> = Props<T>;
Expand Down
8 changes: 6 additions & 2 deletions packages/components/tabs/src/tab.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import {forwardRef, HTMLNextUIProps} from "@nextui-org/system";
import type {TabItemProps as BaseTabItemProps} from "./base/tab-item-base";

import {forwardRef} from "@nextui-org/system";
import {useDOMRef, filterDOMProps} from "@nextui-org/react-utils";
import {clsx, dataAttr} from "@nextui-org/shared-utils";
import {chain, mergeProps} from "@react-aria/utils";
Expand All @@ -12,7 +14,7 @@ import {useIsMounted} from "@nextui-org/use-is-mounted";

import {ValuesType} from "./use-tabs";

export interface TabItemProps<T = object> extends HTMLNextUIProps<"button"> {
export interface TabItemProps<T extends object = object> extends BaseTabItemProps<T> {
item: Node<T>;
state: ValuesType["state"];
slots: ValuesType["slots"];
Expand Down Expand Up @@ -106,9 +108,11 @@ const Tab = forwardRef<"button", TabItemProps>((props, ref) => {
: {},
filterDOMProps(otherProps, {
enabled: shouldFilterDOMProps,
omitPropNames: new Set(["title"]),
}),
)}
className={slots.tab?.({class: tabStyles})}
title={otherProps?.titleValue}
type={Component === "button" ? "button" : undefined}
onClick={handleClick}
>
Expand Down
16 changes: 10 additions & 6 deletions packages/components/tabs/stories/tabs.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,16 @@ const WithIconsTemplate = (args: TabsProps) => (
tab: "text-lg",
}}
>
<Tab key="align-left" title={<AlignLeftBoldIcon />} />
<Tab key="align-vertically" title={<AlignVerticallyBoldIcon />} />
<Tab key="align-right" title={<AlignRightBoldIcon />} />
<Tab key="align-top" title={<AlignTopBoldIcon />} />
<Tab key="align-horizontally" title={<AlignHorizontallyBoldIcon />} />
<Tab key="align-bottom" title={<AlignBottomBoldIcon />} />
<Tab key="align-left" title={<AlignLeftBoldIcon />} titleValue="Align left" />
<Tab key="align-vertically" title={<AlignVerticallyBoldIcon />} titleValue="Align vertically" />
<Tab key="align-right" title={<AlignRightBoldIcon />} titleValue="Align right" />
<Tab key="align-top" title={<AlignTopBoldIcon />} titleValue="Align top" />
<Tab
key="align-horizontally"
title={<AlignHorizontallyBoldIcon />}
titleValue="Align horizontally"
/>
<Tab key="align-bottom" title={<AlignBottomBoldIcon />} titleValue="Align bottom" />
</Tabs>
);

Expand Down