Skip to content

Commit

Permalink
Merge pull request #1156 from Syncano/icon-menu_closeOnItemTouchTap
Browse files Browse the repository at this point in the history
[Icon Menu] adding closeOnItemTouchTap
  • Loading branch information
hai-cea committed Jul 13, 2015
2 parents 733cc5a + 47ca11e commit 872fb69
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
6 changes: 6 additions & 0 deletions docs/src/app/components/pages/components/icon-menus.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,12 @@ class IconMenus extends React.Component {
type: 'number',
header: 'default: 200',
desc: 'Sets the delay in milliseconds before closing the menu when an item is clicked.'
},
{
name: 'closeOnItemTouchTap',
type: 'bool',
header: 'optional',
desc: 'If false, menu will not be closed after tap (default: true).'
}
]
},
Expand Down
17 changes: 11 additions & 6 deletions src/menus/icon-menu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ let IconMenu = React.createClass({
onTouchTap: React.PropTypes.func,
menuStyle: React.PropTypes.object,
touchTapCloseDelay: React.PropTypes.number,
closeOnItemTouchTap: React.PropTypes.bool,
},

getDefaultProps() {
Expand All @@ -46,6 +47,7 @@ let IconMenu = React.createClass({
onMouseUp: () => {},
onTouchTap: () => {},
touchTapCloseDelay: 200,
closeOnItemTouchTap: true,
};
},

Expand Down Expand Up @@ -160,14 +162,17 @@ let IconMenu = React.createClass({
},

_handleItemTouchTap(e, child) {
let isKeyboard = Events.isKeyboard(e);

this._timeout = setTimeout(() => {
this.close(isKeyboard);
}, this.props.touchTapCloseDelay);
if (this.props.closeOnItemTouchTap) {
let isKeyboard = Events.isKeyboard(e);

if (isKeyboard) {
this.refs[this.state.iconButtonRef].setKeyboardFocus();
this._timeout = setTimeout(() => {
this.close(isKeyboard);
}, this.props.touchTapCloseDelay);

if (isKeyboard) {
this.refs[this.state.iconButtonRef].setKeyboardFocus();
}
}

this.props.onItemTouchTap(e, child);
Expand Down

0 comments on commit 872fb69

Please sign in to comment.