Skip to content

Commit

Permalink
nested menu fix
Browse files Browse the repository at this point in the history
  • Loading branch information
chrismcv committed Nov 26, 2015
1 parent 2a2bd56 commit 892e00d
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 13 deletions.
2 changes: 1 addition & 1 deletion docs/src/app/components/pages/components/menus.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ import MenuDivider from 'material-ui/lib/menus/menu-divider';
<MenuItem primaryText="Double" insetChildren={true} />
<MenuItem primaryText="Custom: 1.2" checked={true} rightIcon={<ArrowDropRight />} menuItems={[
<MenuItem primaryText="Show" rightIcon={<ArrowDropRight />} menuItems={[
<MenuItem primaryText="Show" />,
<MenuItem primaryText="Show Level 2" />,
<MenuItem primaryText="Grid lines" checked={true} />,
<MenuItem primaryText="Page breaks" insetChildren={true} />,
<MenuItem primaryText="Rules" checked={true} />,
Expand Down
10 changes: 10 additions & 0 deletions src/menus/menu-item.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ const MenuItem = React.createClass({
componentWillReceiveProps (nextProps, nextContext) {
let newMuiTheme = nextContext.muiTheme ? nextContext.muiTheme : this.state.muiTheme;
this.setState({muiTheme: newMuiTheme});
if (this.state.open && nextProps.focusState === "none") {
this._onRequestClose();
}
},

getDefaultProps() {
Expand All @@ -77,6 +80,12 @@ const MenuItem = React.createClass({
this._applyFocusState();
},

componentWillUnmount() {
if (this.state.open) {
this.setState({open:false});
}
},

render() {
const {
checked,
Expand Down Expand Up @@ -217,6 +226,7 @@ const MenuItem = React.createClass({
},

_onTouchTap(e) {
e.preventDefault();
this.setState({
open:true,
anchorEl:ReactDOM.findDOMNode(this),
Expand Down
6 changes: 4 additions & 2 deletions src/menus/menu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const ThemeManager = require('../styles/theme-manager');
const Menu = React.createClass({

mixins: [
StylePropable,
StylePropable,
Controllable,
],

Expand Down Expand Up @@ -262,7 +262,6 @@ const Menu = React.createClass({
},

_cloneMenuItem(child, childIndex, styles) {

let {
desktop,
selectedMenuItemStyle,
Expand Down Expand Up @@ -394,6 +393,9 @@ const Menu = React.createClass({
let valueLink = this.getValueLink(this.props);
let menuValue = valueLink.value;
let itemValue = item.props.value;
let focusIndex = this.props.children.indexOf(item);

this._setFocusIndex(focusIndex, false);

if (multiple) {
let index = menuValue.indexOf(itemValue);
Expand Down
19 changes: 13 additions & 6 deletions src/popover/popover.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ const Popover = React.createClass({
this.setPlacement();
},

componentWillUnmount() {
if (this.state.open) {
this.props.onRequestClose();
}
},

render() {
return <RenderToLayer
ref="layer"
Expand Down Expand Up @@ -166,8 +172,8 @@ const Popover = React.createClass({
_showInternal(anchorEl) {
this.anchorEl = anchorEl || this.props.anchorEl;
this.setState({open: true});
const popOverShowEvent = new CustomEvent('popOverOnShow', {detail: this});
document.dispatchEvent(popOverShowEvent);
//const popOverShowEvent = new CustomEvent('popOverOnShow', {detail: this});
//document.dispatchEvent(popOverShowEvent);

},

Expand All @@ -179,13 +185,13 @@ const Popover = React.createClass({
open: false,
}, () => {
this._animateClose();
const popOverHideEvent = new CustomEvent('popOverOnHide');
document.dispatchEvent(popOverHideEvent);
//const popOverHideEvent = new CustomEvent('popOverOnHide');
//document.dispatchEvent(popOverHideEvent);
});
},

_animateClose() {
if (!this.refs.layer.getLayer()){
if (!this.refs.layer || !this.refs.layer.getLayer()){
return;
}
let el = this.refs.layer.getLayer().children[0];
Expand Down Expand Up @@ -226,7 +232,8 @@ const Popover = React.createClass({
getAnchorPosition(el) {
if (!el)
el = ReactDOM.findDOMNode(this);

if (!el)
return;
const rect = el.getBoundingClientRect();
const a = {
top: rect.top,
Expand Down
4 changes: 0 additions & 4 deletions src/render-to-layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,12 @@ const RenderToLayer = React.createClass({
Events.on(window, 'focus', this._checkClickAway);
Events.on(document, 'mousedown', this._checkClickAway);
Events.on(document, 'touchend', this._checkClickAway);
Events.on(document, 'popOverOnShow', this._preventClickAway);
Events.on(document, 'popOverOnHide', this._allowClickAway);
},

_unbindClickAway() {
Events.off(window, 'focus', this._checkClickAway);
Events.off(document, 'mousedown', this._checkClickAway);
Events.off(document, 'touchend', this._checkClickAway);
Events.off(document, 'popOverOnShow', this._preventClickAway);
Events.off(document, 'popOverOnHide', this._allowClickAway);
},
});

Expand Down

0 comments on commit 892e00d

Please sign in to comment.