Skip to content

Commit

Permalink
fix(tabs): Handle nodes with parentNode set to undefined instead of n…
Browse files Browse the repository at this point in the history
…ull correctly
  • Loading branch information
danez committed Jan 4, 2019
1 parent 856f84a commit 83f8780
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
10 changes: 7 additions & 3 deletions src/components/UncontrolledTabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
};

/**
Expand Down
1 change: 0 additions & 1 deletion src/components/__tests__/Tabs-test.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down

0 comments on commit 83f8780

Please sign in to comment.