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(components/tab-panel): improve className safety by using 'classnames' #16081

Merged
merged 1 commit into from
Jun 11, 2019
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
12 changes: 6 additions & 6 deletions packages/components/src/tab-panel/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,15 @@ The function called when a tab has been selected. It is passed the `tabName` as

#### tabs

A list of tabs where each tab is defined by an object with the following fields:
An array of objects containing the following properties:

1. name: String. Defines the key for the tab
2. title: String. Defines the translated text for the tab
3. className: String. Defines the class to put on the tab.
- `name`: `(string)` Defines the key for the tab.
- `title`:`(string)` Defines the translated text for the tab.
- `className`:`(string)` Optional. Defines the class to put on the tab.

Other fields may be added to the object and accessed from the child function if desired.
>> **Note:** Other fields may be added to the object and accessed from the child function if desired.

- Type: Array
- Type: `Array`
- Required: Yes

#### activeClass
Expand Down
3 changes: 2 additions & 1 deletion packages/components/src/tab-panel/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/**
* External dependencies
*/
import classnames from 'classnames';
import { partial, noop, find } from 'lodash';

/**
Expand Down Expand Up @@ -74,7 +75,7 @@ class TabPanel extends Component {
className="components-tab-panel__tabs"
>
{ tabs.map( ( tab ) => (
<TabButton className={ `${ tab.className } ${ tab.name === selected ? activeClass : '' }` }
<TabButton className={ classnames( tab.className, { [ activeClass ]: tab.name === selected } ) }
tabId={ instanceId + '-' + tab.name }
aria-controls={ instanceId + '-' + tab.name + '-view' }
selected={ tab.name === selected }
Expand Down