Skip to content

Commit 6fd4002

Browse files
zarichniukdanez
authored andcommitted
fix(tabs): Correctly handle children of type string (#211)
1 parent cd3ac28 commit 6fd4002

File tree

3 files changed

+80
-4
lines changed

3 files changed

+80
-4
lines changed

src/components/__tests__/Tabs-test.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ describe('<Tabs />', () => {
485485
assertTabSelected(wrapper, 2);
486486
});
487487

488-
it('should allow for higher order components', () => {
488+
test('should allow for higher order components', () => {
489489
expectToMatchSnapshot(
490490
<Tabs>
491491
<TabListWrapper>
@@ -497,4 +497,22 @@ describe('<Tabs />', () => {
497497
</Tabs>,
498498
);
499499
});
500+
501+
test('should allow string children', () => {
502+
expectToMatchSnapshot(
503+
<Tabs>
504+
Foo
505+
<TabList>
506+
Foo
507+
<Tab>Foo</Tab>
508+
Foo
509+
<Tab>Bar</Tab>
510+
Foo
511+
</TabList>
512+
<TabPanel>Bar</TabPanel>
513+
<TabPanel>Foo</TabPanel>
514+
Foo
515+
</Tabs>,
516+
);
517+
});
500518
});

src/components/__tests__/__snapshots__/Tabs-test.js.snap

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,64 @@ exports[`<Tabs /> should allow for higher order components 1`] = `
694694
</div>
695695
`;
696696

697+
exports[`<Tabs /> should allow string children 1`] = `
698+
<div
699+
className="react-tabs"
700+
data-tabs={true}
701+
onClick={[Function]}
702+
onKeyDown={[Function]}
703+
>
704+
Foo
705+
<ul
706+
className="react-tabs__tab-list"
707+
role="tablist"
708+
>
709+
Foo
710+
<li
711+
aria-controls="react-tabs-1"
712+
aria-disabled="false"
713+
aria-selected="true"
714+
className="react-tabs__tab react-tabs__tab--selected"
715+
id="react-tabs-0"
716+
role="tab"
717+
tabIndex="0"
718+
>
719+
Foo
720+
</li>
721+
Foo
722+
<li
723+
aria-controls="react-tabs-3"
724+
aria-disabled="false"
725+
aria-selected="false"
726+
className="react-tabs__tab"
727+
id="react-tabs-2"
728+
role="tab"
729+
tabIndex={null}
730+
>
731+
Bar
732+
</li>
733+
Foo
734+
</ul>
735+
<div
736+
aria-labelledby="react-tabs-0"
737+
className="react-tabs__tab-panel react-tabs__tab-panel--selected"
738+
id="react-tabs-1"
739+
role="tabpanel"
740+
style={Object {}}
741+
>
742+
Bar
743+
</div>
744+
<div
745+
aria-labelledby="react-tabs-2"
746+
className="react-tabs__tab-panel"
747+
id="react-tabs-3"
748+
role="tabpanel"
749+
style={Object {}}
750+
/>
751+
Foo
752+
</div>
753+
`;
754+
697755
exports[`<Tabs /> should not add known props to dom 1`] = `
698756
<div
699757
className="react-tabs"

src/helpers/elementTypes.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
export function isTab(el) {
2-
return el.type.tabsRole === 'Tab';
2+
return el.type && el.type.tabsRole === 'Tab';
33
}
44

55
export function isTabPanel(el) {
6-
return el.type.tabsRole === 'TabPanel';
6+
return el.type && el.type.tabsRole === 'TabPanel';
77
}
88

99
export function isTabList(el) {
10-
return el.type.tabsRole === 'TabList';
10+
return el.type && el.type.tabsRole === 'TabList';
1111
}

0 commit comments

Comments
 (0)