Skip to content

Commit

Permalink
feat(Tabs): support passing custom attributes to Tab (#5879)
Browse files Browse the repository at this point in the history
* feat(Tabs): Added possibility of passing custom attributes to Tab component

* wording change
  • Loading branch information
golota60 committed Feb 16, 2022
1 parent d2c5242 commit 6afa734
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/Tab.tsx
Expand Up @@ -8,6 +8,7 @@ export interface TabProps extends Omit<TabPaneProps, 'title'> {
title: React.ReactNode;
disabled?: boolean;
tabClassName?: string;
tabAttrs?: Record<string, any>;
}

/* eslint-disable react/no-unused-prop-types */
Expand All @@ -28,6 +29,11 @@ const propTypes = {
* Class to pass to the underlying nav link.
*/
tabClassName: PropTypes.string,

/**
* Object containing attributes to pass to underlying nav link.
*/
tabAttrs: PropTypes.object,
};

const Tab: React.FC<TabProps> = () => {
Expand Down
4 changes: 3 additions & 1 deletion src/Tabs.tsx
Expand Up @@ -102,7 +102,7 @@ function getDefaultActiveKey(children) {
}

function renderTab(child) {
const { title, eventKey, disabled, tabClassName, id } = child.props;
const { title, eventKey, disabled, tabClassName, tabAttrs, id } = child.props;
if (title == null) {
return null;
}
Expand All @@ -116,6 +116,7 @@ function renderTab(child) {
disabled={disabled}
id={id}
className={tabClassName}
{...tabAttrs}
>
{title}
</NavLink>
Expand Down Expand Up @@ -157,6 +158,7 @@ const Tabs = (props: TabsProps) => {
delete childProps.title;
delete childProps.disabled;
delete childProps.tabClassName;
delete childProps.tabAttrs;

return <TabPane {...childProps} />;
})}
Expand Down

0 comments on commit 6afa734

Please sign in to comment.