Skip to content
Permalink
Browse files

fix(tabs): Handle nodes with parentNode set to undefined instead of n…

…ull correctly
  • Loading branch information
danez committed Jan 4, 2019
1 parent 856f84a commit 83f8780d843cdc231e5deb561b456542a2b37a30
Showing with 9 additions and 6 deletions.
  1. +2 −2 package.json
  2. +7 −3 src/components/UncontrolledTabs.js
  3. +0 −1 src/components/__tests__/Tabs-test.js
@@ -12,8 +12,8 @@
"build:esm": "babel src/ --out-dir esm/ --ignore **/__tests__,**/__mocks__",
"build:umd": "rollup -c",
"build": "npm-run-all clean:* --parallel build:*",
"format": "eslint src --fix",
"lint": "eslint src",
"format": "eslint src --fix --report-unused-disable-directives",
"lint": "eslint src --report-unused-disable-directives",
"precommit": "lint-staged",
"prebump": "run-s lint test",
"prepublish": "yarn run build",
@@ -7,14 +7,18 @@ import { getPanelsCount, getTabsCount } from '../helpers/count';
import { deepMap } from '../helpers/childrenDeepMap';
import { isTabList, isTabPanel, isTab } from '../helpers/elementTypes';

function isNode(node) {
return node && 'getAttribute' in node;
}

// Determine if a node from event.target is a Tab element
function isTabNode(node) {
return 'getAttribute' in node && node.getAttribute('role') === 'tab';
return isNode(node) && node.getAttribute('role') === 'tab';
}

// Determine if a tab node is disabled
function isTabDisabled(node) {
return node.getAttribute('aria-disabled') === 'true';
return isNode(node) && node.getAttribute('aria-disabled') === 'true';
}

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

/**
@@ -1,5 +1,4 @@
/* eslint-env jest */
/* eslint-disable react/no-multi-comp */
import React from 'react';
import Enzyme, { shallow, mount } from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';

0 comments on commit 83f8780

Please sign in to comment.
You can’t perform that action at this time.