Skip to content

Commit

Permalink
Merge branch 'master' into feat/expandable-tile-label
Browse files Browse the repository at this point in the history
  • Loading branch information
kodiakhq[bot] authored Jan 19, 2021
2 parents 1bbea05 + da821e3 commit 09f8443
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 20 deletions.
11 changes: 7 additions & 4 deletions packages/react/src/components/Tab/Tab.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ import React from 'react';
import classNames from 'classnames';
import { settings } from 'carbon-components';
import deprecate from '../../prop-types/deprecate';
import setupGetInstanceId from '../../tools/setupGetInstanceId';

const { prefix } = settings;

const getInstanceId = setupGetInstanceId();
export default class Tab extends React.Component {
static propTypes = {
/**
Expand Down Expand Up @@ -105,9 +106,11 @@ export default class Tab extends React.Component {
onKeyDown: () => {},
};

tabId = this.props.id || `tab-${getInstanceId()}`;

render() {
const {
id,
id, // eslint-disable-line no-unused-vars
className,
handleTabClick,
handleTabKeyDown,
Expand Down Expand Up @@ -143,8 +146,8 @@ export default class Tab extends React.Component {
const buttonProps = {
['aria-selected']: selected,
['aria-disabled']: disabled,
['aria-controls']: `${id}__panel`,
id,
['aria-controls']: `${this.tabId}__panel`,
id: this.tabId,
// TODO: remove scrollable in next major release
// className: `${prefix}--tabs__nav-link`,
className: `${prefix}--tabs--scrollable__nav-link`,
Expand Down
22 changes: 7 additions & 15 deletions packages/react/src/components/Tabs/Tabs-story.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,23 +122,22 @@ export default {
export const Default = () => (
<div className={props.tabs().light ? 'tabs-story-wrapper--light' : null}>
<Tabs {...props.tabs()}>
<Tab id="tab-1" {...props.tab()} label="Tab label 1">
<Tab {...props.tab()} label="Tab label 1">
<div className="some-content">
<p>Content for first tab goes here.</p>
</div>
</Tab>
<Tab id="tab-2" {...props.tab()} label="Tab label 2">
<Tab {...props.tab()} label="Tab label 2">
<div className="some-content">
<p>Content for second tab goes here.</p>
</div>
</Tab>
<Tab id="tab-3" {...props.tab()} label="Tab label 3" disabled>
<Tab {...props.tab()} label="Tab label 3" disabled>
<div className="some-content">
<p>Content for third tab goes here.</p>
</div>
</Tab>
<Tab
id="tab-4"
{...props.tab()}
label="Tab label 4 shows truncation"
title="Tab label 4 shows truncation"
Expand All @@ -153,10 +152,7 @@ export const Default = () => (
<CodeSnippetExample />
</div>
</Tab>
<Tab
id="tab-5"
{...props.tab()}
label={<CustomLabel text="Custom Label" />}>
<Tab {...props.tab()} label={<CustomLabel text="Custom Label" />}>
<div className="some-content">
<p>Content for fifth tab goes here.</p>
</div>
Expand All @@ -180,18 +176,17 @@ export const Container = () => (
props.tabs().light ? 'container-tabs-story-wrapper--light' : null
}>
<Tabs type="container" {...props.tabs()}>
<Tab id="tab-1" {...props.tab()} label="Tab label 1">
<Tab {...props.tab()} label="Tab label 1">
<div className="some-content">
<p>Content for first tab goes here.</p>
</div>
</Tab>
<Tab id="tab-2" {...props.tab()} label="Tab label 2">
<Tab {...props.tab()} label="Tab label 2">
<div className="some-content">
<p>Content for second tab goes here.</p>
</div>
</Tab>
<Tab
id="tab-3"
{...props.tab()}
label="Tab label 3 renders content only when selected"
title="Tab label 3 renders content only when selected"
Expand All @@ -206,10 +201,7 @@ export const Container = () => (
<CodeSnippetExample />
</div>
</Tab>
<Tab
id="tab-4"
{...props.tab()}
label={<CustomLabel text="Custom Label" />}>
<Tab {...props.tab()} label={<CustomLabel text="Custom Label" />}>
<div className="some-content">
<p>Content for fourth tab goes here.</p>
<TextInput light id="sample-input" labelText="Text Input Label" />
Expand Down
3 changes: 2 additions & 1 deletion packages/react/src/components/Tabs/Tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,8 @@ export default class Tabs extends React.Component {
tab?.tabAnchor?.offsetParent.getBoundingClientRect().right;
const rightOverflowNavButtonHidden =
tablistScrollLeft + tablistClientWidth === tablistScrollWidth;
tab?.tabAnchor?.scrollIntoView({ block: 'nearest', inline: 'nearest' });
this.props.scrollIntoView &&
tab?.tabAnchor?.scrollIntoView({ block: 'nearest', inline: 'nearest' });

// account for overflow buttons in scroll position on mount
if (!leftOverflowNavButtonHidden && !rightOverflowNavButtonHidden) {
Expand Down

0 comments on commit 09f8443

Please sign in to comment.