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

Commit a9b3b40

Browse files
Better children prop validation and fix integration tests
1 parent bbbbbb1 commit a9b3b40

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
@@ -2883,7 +2883,18 @@
28832883
},
28842884
"children": {
28852885
"type": {
2886-
"name": "node"
2886+
"name": "union",
2887+
"value": [
2888+
{
2889+
"name": "arrayOf",
2890+
"value": {
2891+
"name": "node"
2892+
}
2893+
},
2894+
{
2895+
"name": "node"
2896+
}
2897+
]
28872898
},
28882899
"required": false,
28892900
"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
@@ -560,25 +560,25 @@ def test_tabs_without_value(self):
560560

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

570570

571-
@app.callback(Output('tabs-content-example', 'children'),
572-
[Input('tabs-example', 'value')])
571+
@app.callback(Output('tabs-content', 'children'),
572+
[Input('tabs-without-value', 'value')])
573573
def render_content(tab):
574-
if tab == 'tab-1-example':
574+
if tab == 'tab-1':
575575
return html.H3('Default selected Tab content 1')
576-
elif tab == 'tab-2-example':
576+
elif tab == 'tab-2':
577577
return html.H3('Tab content 2')
578578

579579
self.startServer(app=app)
580580

581-
default_tab_content = self.wait_for_element_by_css_selector('#tabs-content-example')
581+
default_tab_content = self.wait_for_element_by_css_selector('#tabs-content')
582582

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

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)