Skip to content

Commit 83f8780

Browse files
committed
fix(tabs): Handle nodes with parentNode set to undefined instead of null correctly
1 parent 856f84a commit 83f8780

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
"build:esm": "babel src/ --out-dir esm/ --ignore **/__tests__,**/__mocks__",
1313
"build:umd": "rollup -c",
1414
"build": "npm-run-all clean:* --parallel build:*",
15-
"format": "eslint src --fix",
16-
"lint": "eslint src",
15+
"format": "eslint src --fix --report-unused-disable-directives",
16+
"lint": "eslint src --report-unused-disable-directives",
1717
"precommit": "lint-staged",
1818
"prebump": "run-s lint test",
1919
"prepublish": "yarn run build",

src/components/UncontrolledTabs.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,18 @@ import { getPanelsCount, getTabsCount } from '../helpers/count';
77
import { deepMap } from '../helpers/childrenDeepMap';
88
import { isTabList, isTabPanel, isTab } from '../helpers/elementTypes';
99

10+
function isNode(node) {
11+
return node && 'getAttribute' in node;
12+
}
13+
1014
// Determine if a node from event.target is a Tab element
1115
function isTabNode(node) {
12-
return 'getAttribute' in node && node.getAttribute('role') === 'tab';
16+
return isNode(node) && node.getAttribute('role') === 'tab';
1317
}
1418

1519
// Determine if a tab node is disabled
1620
function isTabDisabled(node) {
17-
return node.getAttribute('aria-disabled') === 'true';
21+
return isNode(node) && node.getAttribute('aria-disabled') === 'true';
1822
}
1923

2024
let canUseActiveElement;
@@ -298,7 +302,7 @@ export default class UncontrolledTabs extends Component {
298302
this.setSelected(index, e);
299303
return;
300304
}
301-
} while ((node = node.parentNode) !== null);
305+
} while ((node = node.parentNode) != null);
302306
};
303307

304308
/**

src/components/__tests__/Tabs-test.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
/* eslint-env jest */
2-
/* eslint-disable react/no-multi-comp */
32
import React from 'react';
43
import Enzyme, { shallow, mount } from 'enzyme';
54
import Adapter from 'enzyme-adapter-react-16';

0 commit comments

Comments
 (0)