Skip to content
This repository was archived by the owner on Jun 3, 2024. It is now read-only.

Commit e7272a9

Browse files
Better children prop validation and fix integration tests
1 parent 4368653 commit e7272a9

File tree

6 files changed

+27
-30
lines changed

6 files changed

+27
-30
lines changed

dash_core_components/Tabs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class Tabs(Component):
1010
children components that will be that tab's content.
1111
1212
Keyword arguments:
13-
- children (a list of or a singular dash component, string or number; optional): Array that holds Tab components
13+
- children (list | a list of or a singular dash component, string or number; optional): Array that holds Tab components
1414
- id (string; optional): The ID of this component, used to identify dash components
1515
in callbacks. The ID needs to be unique across all of the
1616
components in an app.

dash_core_components/dash_core_components.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dash_core_components/metadata.json

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2985,7 +2985,18 @@
29852985
},
29862986
"children": {
29872987
"type": {
2988-
"name": "node"
2988+
"name": "union",
2989+
"value": [
2990+
{
2991+
"name": "arrayOf",
2992+
"value": {
2993+
"name": "node"
2994+
}
2995+
},
2996+
{
2997+
"name": "node"
2998+
}
2999+
]
29893000
},
29903001
"required": false,
29913002
"description": "Array that holds Tab components"

src/components/Tabs.react.js

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -116,15 +116,6 @@ export default class Tabs extends Component {
116116
this.selectHandler = this.selectHandler.bind(this);
117117
this.parseChildrenToArray = this.parseChildrenToArray.bind(this);
118118

119-
this.NoChildrenError = {
120-
name: 'NoChildrenError',
121-
message: 'Tabs did not have any children Tab components!',
122-
};
123-
124-
if (!this.props.children) {
125-
throw this.NoChildrenError;
126-
}
127-
128119
if (!this.props.value) {
129120
// if no value specified on Tabs component, set it to the first child's (which should be a Tab component) value
130121

@@ -230,8 +221,6 @@ export default class Tabs extends Component {
230221
/>
231222
);
232223
});
233-
} else {
234-
throw this.NoChildrenError;
235224
}
236225
if (!selectedTab) {
237226
throw new Error(
@@ -383,7 +372,10 @@ Tabs.propTypes = {
383372
/**
384373
* Array that holds Tab components
385374
*/
386-
children: PropTypes.node,
375+
children: React.PropTypes.oneOfType([
376+
React.PropTypes.arrayOf(React.PropTypes.node),
377+
React.PropTypes.node
378+
]),
387379

388380
/**
389381
* Holds the colors used by the Tabs and Tab components. If you set these, you should specify colors for all properties, so:

test/test_integration.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -561,25 +561,25 @@ def test_tabs_without_value(self):
561561

562562
app.layout = html.Div([
563563
html.H1('Dash Tabs component demo'),
564-
dcc.Tabs(id="tabs-example", children=[
565-
dcc.Tab(label='Tab One', value='tab-1-example'),
566-
dcc.Tab(label='Tab Two', value='tab-2-example'),
564+
dcc.Tabs(id="tabs-without-value", children=[
565+
dcc.Tab(label='Tab One', value='tab-1', children=[html.Div('hi')]),
566+
dcc.Tab(label='Tab Two', value='tab-2', children=[html.Div('hi')]),
567567
]),
568-
html.Div(id='tabs-content-example')
568+
html.Div(id='tabs-content')
569569
])
570570

571571

572-
@app.callback(Output('tabs-content-example', 'children'),
573-
[Input('tabs-example', 'value')])
572+
@app.callback(Output('tabs-content', 'children'),
573+
[Input('tabs-without-value', 'value')])
574574
def render_content(tab):
575-
if tab == 'tab-1-example':
575+
if tab == 'tab-1':
576576
return html.H3('Default selected Tab content 1')
577-
elif tab == 'tab-2-example':
577+
elif tab == 'tab-2':
578578
return html.H3('Tab content 2')
579579

580580
self.startServer(app=app)
581581

582-
default_tab_content = self.wait_for_element_by_css_selector('#tabs-content-example')
582+
default_tab_content = self.wait_for_element_by_css_selector('#tabs-content')
583583

584584
self.assertEqual(default_tab_content.text, 'Default selected Tab content 1')
585585

test/unit/Tabs.test.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,6 @@ import Tab from '../../src/components/Tab.react.js';
33
import React from 'react';
44
import {mount, render} from 'enzyme';
55

6-
test('Tabs are defined', () => {
7-
const tabs = <Tabs />;
8-
9-
expect(tabs).toBeDefined();
10-
});
11-
126
test('Tabs render', () => {
137
const tabs = render(
148
<Tabs>

0 commit comments

Comments
 (0)