Skip to content

Commit 517a056

Browse files
committed
fix: Change strategy to detect tabs for compatibility with other libraries
Fixes #424
1 parent 7ff979f commit 517a056

File tree

5 files changed

+81
-24
lines changed

5 files changed

+81
-24
lines changed

src/components/Tab.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ export default class Tab extends Component {
8585
aria-disabled={disabled ? 'true' : 'false'}
8686
aria-controls={panelId}
8787
tabIndex={tabIndex || (selected ? '0' : null)}
88+
data-rttab
8889
>
8990
{children}
9091
</li>

src/components/UncontrolledTabs.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ function isNode(node) {
1313

1414
// Determine if a node from event.target is a Tab element
1515
function isTabNode(node) {
16-
return isNode(node) && node.getAttribute('role') === 'tab';
16+
return isNode(node) && node.getAttribute('data-rttab');
1717
}
1818

1919
// Determine if a tab node is disabled
@@ -347,7 +347,7 @@ export default class UncontrolledTabs extends Component {
347347
let nodeAncestor = node.parentElement;
348348
do {
349349
if (nodeAncestor === this.node) return true;
350-
if (nodeAncestor.getAttribute('data-tabs')) break;
350+
if (nodeAncestor.getAttribute('data-rttabs')) break;
351351

352352
nodeAncestor = nodeAncestor.parentElement;
353353
} while (nodeAncestor);
@@ -383,7 +383,7 @@ export default class UncontrolledTabs extends Component {
383383
this.node = node;
384384
if (domRef) domRef(node);
385385
}}
386-
data-tabs
386+
data-rttabs
387387
>
388388
{this.getChildren()}
389389
</div>

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ exports[`<Tab /> override the tabIndex if it was provided 1`] = `
66
aria-disabled="false"
77
aria-selected="false"
88
className="react-tabs__tab"
9+
data-rttab={true}
910
id={null}
1011
role="tab"
1112
tabIndex="0"
@@ -20,6 +21,7 @@ exports[`<Tab /> should accept className 1`] = `
2021
aria-disabled="false"
2122
aria-selected="false"
2223
className="foobar"
24+
data-rttab={true}
2325
id={null}
2426
role="tab"
2527
tabIndex={null}
@@ -32,6 +34,7 @@ exports[`<Tab /> should allow to be wrapped in higher-order-component 1`] = `
3234
aria-disabled="false"
3335
aria-selected="false"
3436
className="react-tabs__tab"
37+
data-rttab={true}
3538
id={null}
3639
role="tab"
3740
tabIndex={null}
@@ -44,6 +47,7 @@ exports[`<Tab /> should have sane defaults 1`] = `
4447
aria-disabled="false"
4548
aria-selected="false"
4649
className="react-tabs__tab"
50+
data-rttab={true}
4751
id={null}
4852
role="tab"
4953
tabIndex={null}
@@ -56,6 +60,7 @@ exports[`<Tab /> should not allow overriding all default properties 1`] = `
5660
aria-disabled="false"
5761
aria-selected="false"
5862
className="react-tabs__tab"
63+
data-rttab={true}
5964
id={null}
6065
role="tab"
6166
tabIndex={null}
@@ -68,6 +73,7 @@ exports[`<Tab /> should pass through custom properties 1`] = `
6873
aria-disabled="false"
6974
aria-selected="false"
7075
className="react-tabs__tab"
76+
data-rttab={true}
7177
data-tooltip="Tooltip contents"
7278
id={null}
7379
role="tab"
@@ -81,6 +87,7 @@ exports[`<Tab /> should support being disabled 1`] = `
8187
aria-disabled="true"
8288
aria-selected="false"
8389
className="react-tabs__tab react-tabs__tab--disabled"
90+
data-rttab={true}
8491
id={null}
8592
role="tab"
8693
tabIndex={null}
@@ -93,6 +100,7 @@ exports[`<Tab /> should support being disabled with custom class name 1`] = `
93100
aria-disabled="true"
94101
aria-selected="false"
95102
className="react-tabs__tab coolDisabled"
103+
data-rttab={true}
96104
id={null}
97105
role="tab"
98106
tabIndex={null}
@@ -105,6 +113,7 @@ exports[`<Tab /> should support being selected 1`] = `
105113
aria-disabled="false"
106114
aria-selected="true"
107115
className="react-tabs__tab react-tabs__tab--selected"
116+
data-rttab={true}
108117
id="abcd"
109118
role="tab"
110119
tabIndex="0"
@@ -119,6 +128,7 @@ exports[`<Tab /> should support being selected with custom class 1`] = `
119128
aria-disabled="false"
120129
aria-selected="true"
121130
className="react-tabs__tab cool"
131+
data-rttab={true}
122132
id={null}
123133
role="tab"
124134
tabIndex="0"

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ exports[`<TabList /> should accept className 1`] = `
1010
exports[`<TabList /> should allow for higher order components 1`] = `
1111
<div
1212
className="react-tabs"
13-
data-tabs={true}
13+
data-rttabs={true}
1414
onClick={[Function]}
1515
onKeyDown={[Function]}
1616
>
@@ -23,6 +23,7 @@ exports[`<TabList /> should allow for higher order components 1`] = `
2323
aria-disabled="false"
2424
aria-selected="true"
2525
className="react-tabs__tab react-tabs__tab--selected"
26+
data-rttab={true}
2627
id="react-tabs-12"
2728
role="tab"
2829
tabIndex="0"
@@ -34,6 +35,7 @@ exports[`<TabList /> should allow for higher order components 1`] = `
3435
aria-disabled="false"
3536
aria-selected="false"
3637
className="react-tabs__tab"
38+
data-rttab={true}
3739
id="react-tabs-14"
3840
role="tab"
3941
tabIndex={null}
@@ -61,7 +63,7 @@ exports[`<TabList /> should allow for higher order components 1`] = `
6163
exports[`<TabList /> should display the custom classnames for selected and disabled tab 1`] = `
6264
<div
6365
className="react-tabs"
64-
data-tabs={true}
66+
data-rttabs={true}
6567
onClick={[Function]}
6668
onKeyDown={[Function]}
6769
>
@@ -74,6 +76,7 @@ exports[`<TabList /> should display the custom classnames for selected and disab
7476
aria-disabled="false"
7577
aria-selected="true"
7678
className="react-tabs__tab active"
79+
data-rttab={true}
7780
id="react-tabs-8"
7881
role="tab"
7982
tabIndex="0"
@@ -85,6 +88,7 @@ exports[`<TabList /> should display the custom classnames for selected and disab
8588
aria-disabled="true"
8689
aria-selected="false"
8790
className="react-tabs__tab disabled"
91+
data-rttab={true}
8892
id="react-tabs-10"
8993
role="tab"
9094
tabIndex={null}
@@ -112,7 +116,7 @@ exports[`<TabList /> should display the custom classnames for selected and disab
112116
exports[`<TabList /> should display the custom classnames for selected and disabled tab specified on tabs 1`] = `
113117
<div
114118
className="react-tabs"
115-
data-tabs={true}
119+
data-rttabs={true}
116120
onClick={[Function]}
117121
onKeyDown={[Function]}
118122
>
@@ -125,6 +129,7 @@ exports[`<TabList /> should display the custom classnames for selected and disab
125129
aria-disabled="false"
126130
aria-selected="true"
127131
className="react-tabs__tab active"
132+
data-rttab={true}
128133
id="react-tabs-4"
129134
role="tab"
130135
tabIndex="0"
@@ -136,6 +141,7 @@ exports[`<TabList /> should display the custom classnames for selected and disab
136141
aria-disabled="true"
137142
aria-selected="false"
138143
className="react-tabs__tab disabled"
144+
data-rttab={true}
139145
id="react-tabs-6"
140146
role="tab"
141147
tabIndex={null}
@@ -185,7 +191,7 @@ exports[`<TabList /> should pass through custom properties 1`] = `
185191
exports[`<TabList /> should retain the default classnames for active and disabled tab 1`] = `
186192
<div
187193
className="react-tabs"
188-
data-tabs={true}
194+
data-rttabs={true}
189195
onClick={[Function]}
190196
onKeyDown={[Function]}
191197
>
@@ -198,6 +204,7 @@ exports[`<TabList /> should retain the default classnames for active and disable
198204
aria-disabled="false"
199205
aria-selected="true"
200206
className="react-tabs__tab react-tabs__tab--selected"
207+
data-rttab={true}
201208
id="react-tabs-0"
202209
role="tab"
203210
tabIndex="0"
@@ -209,6 +216,7 @@ exports[`<TabList /> should retain the default classnames for active and disable
209216
aria-disabled="true"
210217
aria-selected="false"
211218
className="react-tabs__tab react-tabs__tab--disabled"
219+
data-rttab={true}
212220
id="react-tabs-2"
213221
role="tab"
214222
tabIndex={null}

0 commit comments

Comments
 (0)