Skip to content

Commit 578a61b

Browse files
Joe Woynillowiczeddywashere
authored andcommitted
feat(DropdownItem): Add toggle switch to allow conditional toggle (#346)
* Add toggle switch to DropdownItem to allow conditional toggle on item selected * use lodash.omit to remove toggle * cleaning imports and spacing * if spacing corrected * import order
1 parent 2023036 commit 578a61b

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

src/DropdownItem.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React from 'react';
2+
import omit from 'lodash.omit';
23
import classNames from 'classnames';
34
import { mapToCssModules } from './utils';
45

@@ -12,14 +13,16 @@ const propTypes = {
1213
onClick: PropTypes.func,
1314
className: PropTypes.string,
1415
cssModule: PropTypes.object,
16+
toggle: PropTypes.bool
1517
};
1618

1719
const contextTypes = {
1820
toggle: PropTypes.func
1921
};
2022

2123
const defaultProps = {
22-
tag: 'button'
24+
tag: 'button',
25+
toggle: true
2326
};
2427

2528
class DropdownItem extends React.Component {
@@ -40,7 +43,9 @@ class DropdownItem extends React.Component {
4043
this.props.onClick(e);
4144
}
4245

43-
this.context.toggle();
46+
if (this.props.toggle) {
47+
this.context.toggle();
48+
}
4449
}
4550

4651
getTabIndex() {
@@ -59,7 +64,7 @@ class DropdownItem extends React.Component {
5964
divider,
6065
tag: Tag,
6166
header,
62-
...props } = this.props;
67+
...props } = omit(this.props, ['toggle']);
6368

6469
const classes = mapToCssModules(classNames(
6570
className,

0 commit comments

Comments
 (0)