Fix MenuItem onclick called without event
In all other cases the event listener receives the event. I need to receive the event to stop its propagation.old
parent
afde8b1aa2
commit
53f4a5ed75
|
@ -121,10 +121,11 @@ const factory = (MenuItem) => {
|
|||
}
|
||||
};
|
||||
|
||||
handleSelect = (item) => {
|
||||
handleSelect = (item, event) => {
|
||||
const { value, onClick } = item.props;
|
||||
if (onClick) event.persist();
|
||||
this.setState({ active: false, rippled: this.props.ripple }, () => {
|
||||
if (onClick) onClick();
|
||||
if (onClick) onClick(event);
|
||||
if (this.props.onSelect) this.props.onSelect(value);
|
||||
});
|
||||
};
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
import expect from 'expect';
|
||||
import React from 'react';
|
||||
import ReactDOM from 'react-dom';
|
||||
import ReactTestUtils from 'react-addons-test-utils';
|
||||
import Menu from '../Menu';
|
||||
import MenuItem, {MenuItem as RawMenuItem} from '../MenuItem';
|
||||
|
||||
describe('MenuItem', function () {
|
||||
describe('#onClick', function () {
|
||||
it('passes to listener the event', function () {
|
||||
let listenerCalled = false;
|
||||
const handleClick = function (event) {
|
||||
listenerCalled = true;
|
||||
expect(event).toExist();
|
||||
expect(event.target).toExist();
|
||||
};
|
||||
|
||||
const tree = ReactTestUtils.renderIntoDocument(
|
||||
<Menu>
|
||||
<MenuItem key="1" onClick={handleClick}/>
|
||||
</Menu>);
|
||||
|
||||
const menuItem = ReactTestUtils.findRenderedComponentWithType(tree, RawMenuItem);
|
||||
ReactTestUtils.Simulate.click(ReactDOM.findDOMNode(menuItem));
|
||||
|
||||
expect(listenerCalled).toBe(true);
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue