2018-05-14 15:47:42 +00:00
|
|
|
/** @format */
|
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { Component } from '@wordpress/element';
|
2018-07-23 20:14:40 +00:00
|
|
|
import { ENTER, SPACE } from '@wordpress/keycodes';
|
2018-05-14 15:47:42 +00:00
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
|
|
|
|
class MenuItem extends Component {
|
|
|
|
constructor() {
|
|
|
|
super( ...arguments );
|
|
|
|
this.onClick = this.onClick.bind( this );
|
|
|
|
this.onKeyDown = this.onKeyDown.bind( this );
|
|
|
|
}
|
|
|
|
|
|
|
|
onClick( event ) {
|
|
|
|
const { isClickable, onInvoke } = this.props;
|
|
|
|
if ( isClickable ) {
|
|
|
|
event.preventDefault();
|
|
|
|
onInvoke();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
onKeyDown( event ) {
|
2018-07-23 20:14:40 +00:00
|
|
|
if ( event.keyCode === ENTER || event.keyCode === SPACE ) {
|
2018-05-14 15:47:42 +00:00
|
|
|
event.preventDefault();
|
|
|
|
this.props.onInvoke();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const { children } = this.props;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div
|
|
|
|
role="menuitem"
|
|
|
|
tabIndex="0"
|
|
|
|
onKeyDown={ this.onKeyDown }
|
|
|
|
onClick={ this.onClick }
|
2018-06-01 14:35:18 +00:00
|
|
|
className="woocommerce-ellipsis-menu__item"
|
2018-05-14 15:47:42 +00:00
|
|
|
>
|
|
|
|
{ children }
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
MenuItem.propTypes = {
|
|
|
|
children: PropTypes.node,
|
|
|
|
isClickable: PropTypes.bool,
|
|
|
|
onInvoke: PropTypes.func.isRequired,
|
|
|
|
};
|
|
|
|
|
|
|
|
MenuItem.defaultProps = {
|
|
|
|
isClickable: false,
|
|
|
|
};
|
|
|
|
|
|
|
|
export default MenuItem;
|