Skip to content

Commit

Permalink
fix(ListItem): remove componentWillMount method
Browse files Browse the repository at this point in the history
  • Loading branch information
bfbiggs authored and pauljeter committed Aug 27, 2019
1 parent bd544fd commit a5faefd
Showing 1 changed file with 27 additions and 25 deletions.
52 changes: 27 additions & 25 deletions react/src/lib/ListItem/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,9 @@ import ListContext from '../ListContext';
import mapContextToProps from 'react-context-toolbox/mapContextToProps';

class ListItem extends React.Component {
componentWillMount() {
if (!this.props.children) return;
const checkAllChildren = this.getChildrenElements(['ListItemSection', 'EventOverlay']);
const checkSectionChildren = this.getChildrenElements(['ListItemSection']);

if (!checkAllChildren) {
return;
} else if (checkSectionChildren.length > 3) {
throw new Error(
`Only 3 ListItemSection components can be used as children. You've used ${
checkSectionChildren.length
}`
);
}
}

componentDidMount() {
const anchorCount = this.checkElements('A');
const { focus, refName, focusOnLoad } = this.props;

if (anchorCount.count > 1) {
throw new Error(
'Only 1 primary child anchor tag may be used with ListItem component'
);
} else if (anchorCount.count === 1 && anchorCount.children > 1) {
throw new Error('Anchor tag can not have sibling');
}
this.verifyStructure();

focusOnLoad && focus
&& this[refName]
Expand Down Expand Up @@ -107,6 +83,32 @@ class ListItem extends React.Component {
parentKeyDown && parentKeyDown(e, { value, label, eventKey });
}

verifyStructure() {
if (!this.props.children) return;

const anchorCount = this.checkElements('A');
const checkAllChildren = this.getChildrenElements(['ListItemSection', 'EventOverlay']);
const checkSectionChildren = this.getChildrenElements(['ListItemSection']);

if (anchorCount.count > 1) {
throw new Error(
'Only 1 primary child anchor tag may be used with ListItem component'
);
} else if (anchorCount.count === 1 && anchorCount.children > 1) {
throw new Error('Anchor tag can not have sibling');
}

if (!checkAllChildren) {
return;
} else if (checkSectionChildren.length > 3) {
throw new Error(
`Only 3 ListItemSection components can be used as children. You've used ${
checkSectionChildren.length
}`
);
}
}

render() {
const {
active,
Expand Down

0 comments on commit a5faefd

Please sign in to comment.