Completely updated React, fixed #11, (hopefully)

This commit is contained in:
2018-03-04 19:11:49 -05:00
parent 6e0afd6e2a
commit 34e5f5139a
13674 changed files with 333464 additions and 473223 deletions

View File

@@ -1,24 +1,17 @@
import * as React from 'react';
import { PopoverProps, PopoverClassKey } from '../Popover';
import { TransitionDuration, TransitionHandlers } from '../internal/transition';
import { MenuListProps } from './MenuList';
import { StandardProps } from '..';
import { TransitionHandlerProps, TransitionProps } from '../transitions/transition';
export interface MenuProps extends StandardProps<
PopoverProps & Partial<TransitionHandlers>,
MenuClassKey
> {
export interface MenuProps
extends StandardProps<PopoverProps & Partial<TransitionHandlerProps>, MenuClassKey> {
anchorEl?: HTMLElement;
MenuListProps?: MenuListProps;
onRequestClose?: React.EventHandler<any>;
open?: boolean;
transitionDuration?: TransitionDuration;
MenuListProps?: Partial<MenuListProps>;
transitionDuration?: TransitionProps['timeout'] | 'auto';
}
export type MenuClassKey =
| PopoverClassKey
| 'root'
;
export type MenuClassKey = PopoverClassKey | 'root';
declare const Menu: React.ComponentType<MenuProps>;

View File

@@ -37,6 +37,10 @@ var _react = require('react');
var _react2 = _interopRequireDefault(_react);
var _propTypes = require('prop-types');
var _propTypes2 = _interopRequireDefault(_propTypes);
var _reactDom = require('react-dom');
var _scrollbarSize = require('dom-helpers/util/scrollbarSize');
@@ -57,105 +61,12 @@ var _MenuList2 = _interopRequireDefault(_MenuList);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var babelPluginFlowReactPropTypes_proptype_Node = require('react').babelPluginFlowReactPropTypes_proptype_Node || require('prop-types').any;
// @inheritedComponent Popover
var babelPluginFlowReactPropTypes_proptype_TransitionCallback = require('../internal/transition').babelPluginFlowReactPropTypes_proptype_TransitionCallback || require('prop-types').any;
var babelPluginFlowReactPropTypes_proptype_Props = {
/**
* The DOM element used to set the position of the menu.
*/
anchorEl: typeof HTMLElement === 'function' ? require('prop-types').instanceOf(HTMLElement) : require('prop-types').any,
// match Popover
/**
* Menu contents, normally `MenuItem`s.
*/
children: typeof babelPluginFlowReactPropTypes_proptype_Node === 'function' ? babelPluginFlowReactPropTypes_proptype_Node : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_Node),
/**
* Useful to extend the style applied to components.
*/
classes: require('prop-types').object,
/**
* Properties applied to the `MenuList` element.
*/
MenuListProps: require('prop-types').object,
/**
* Callback fired before the Menu enters.
*/
onEnter: typeof babelPluginFlowReactPropTypes_proptype_TransitionCallback === 'function' ? babelPluginFlowReactPropTypes_proptype_TransitionCallback : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_TransitionCallback),
/**
* Callback fired when the Menu is entering.
*/
onEntering: typeof babelPluginFlowReactPropTypes_proptype_TransitionCallback === 'function' ? babelPluginFlowReactPropTypes_proptype_TransitionCallback : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_TransitionCallback),
/**
* Callback fired when the Menu has entered.
*/
onEntered: typeof babelPluginFlowReactPropTypes_proptype_TransitionCallback === 'function' ? babelPluginFlowReactPropTypes_proptype_TransitionCallback : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_TransitionCallback),
/**
* Callback fired before the Menu exits.
*/
onExit: typeof babelPluginFlowReactPropTypes_proptype_TransitionCallback === 'function' ? babelPluginFlowReactPropTypes_proptype_TransitionCallback : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_TransitionCallback),
/**
* Callback fired when the Menu is exiting.
*/
onExiting: typeof babelPluginFlowReactPropTypes_proptype_TransitionCallback === 'function' ? babelPluginFlowReactPropTypes_proptype_TransitionCallback : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_TransitionCallback),
/**
* Callback fired when the Menu has exited.
*/
onExited: typeof babelPluginFlowReactPropTypes_proptype_TransitionCallback === 'function' ? babelPluginFlowReactPropTypes_proptype_TransitionCallback : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_TransitionCallback),
/**
* Callback fired when the component requests to be closed.
*
* @param {object} event The event source of the callback
*/
onRequestClose: require('prop-types').func,
/**
* If `true`, the menu is visible.
*/
open: require('prop-types').bool,
/**
* @ignore
*/
PaperProps: require('prop-types').object,
/**
* `classes` property applied to the `Popover` element.
*/
PopoverClasses: require('prop-types').object,
/**
* @ignore
*/
theme: require('prop-types').object,
/**
* The length of the transition in `ms`, or 'auto'
*/
transitionDuration: require('prop-types').oneOfType([require('prop-types').number, require('prop-types').shape({
enter: require('prop-types').number,
exit: require('prop-types').number
}), require('prop-types').oneOf(['auto'])])
};
var rtlOrigin = {
var RTL_ORIGIN = {
vertical: 'top',
horizontal: 'right'
};
}; // @inheritedComponent Popover
var ltrOrigin = {
var LTR_ORIGIN = {
vertical: 'top',
horizontal: 'left'
};
@@ -187,27 +98,23 @@ var Menu = function (_React$Component) {
return _ret = (_temp = (_this = (0, _possibleConstructorReturn3.default)(this, (_ref = Menu.__proto__ || (0, _getPrototypeOf2.default)(Menu)).call.apply(_ref, [this].concat(args))), _this), _this.getContentAnchorEl = function () {
if (!_this.menuList || !_this.menuList.selectedItem) {
// $FlowFixMe
return (0, _reactDom.findDOMNode)(_this.menuList).firstChild;
}
return (0, _reactDom.findDOMNode)(_this.menuList.selectedItem);
}, _this.menuList = undefined, _this.focus = function () {
if (_this.menuList && _this.menuList.selectedItem) {
// $FlowFixMe
(0, _reactDom.findDOMNode)(_this.menuList.selectedItem).focus();
return;
}
var menuList = (0, _reactDom.findDOMNode)(_this.menuList);
if (menuList && menuList.firstChild) {
// $FlowFixMe
menuList.firstChild.focus();
}
}, _this.handleEnter = function (element) {
var theme = _this.props.theme;
var menuList = (0, _reactDom.findDOMNode)(_this.menuList);
// Focus so the scroll computation of the Popover works as expected.
@@ -215,12 +122,9 @@ var Menu = function (_React$Component) {
// Let's ignore that piece of logic if users are already overriding the width
// of the menu.
// $FlowFixMe
if (menuList && element.clientHeight < menuList.clientHeight && !menuList.style.width) {
var size = (0, _scrollbarSize2.default)() + 'px';
// $FlowFixMe
menuList.style[theme.direction === 'rtl' ? 'paddingLeft' : 'paddingRight'] = size;
// $FlowFixMe
menuList.style.width = 'calc(100% + ' + size + ')';
}
@@ -231,8 +135,8 @@ var Menu = function (_React$Component) {
if (key === 'tab') {
event.preventDefault();
if (_this.props.onRequestClose) {
_this.props.onRequestClose(event);
if (_this.props.onClose) {
_this.props.onClose(event);
}
}
}, _temp), (0, _possibleConstructorReturn3.default)(_this, _ret);
@@ -245,15 +149,6 @@ var Menu = function (_React$Component) {
this.focus();
}
}
}, {
key: 'componentDidUpdate',
value: function componentDidUpdate(prevProps) {
if (!prevProps.open && this.props.open) {
// Needs to refocus as when a menu is rendered into another Modal,
// the first modal might change the focus to prevent any leak.
this.focus();
}
}
}, {
key: 'render',
value: function render() {
@@ -277,8 +172,8 @@ var Menu = function (_React$Component) {
getContentAnchorEl: this.getContentAnchorEl,
classes: PopoverClasses,
onEnter: this.handleEnter,
anchorOrigin: theme.direction === 'rtl' ? rtlOrigin : ltrOrigin,
transformOrigin: theme.direction === 'rtl' ? rtlOrigin : ltrOrigin,
anchorOrigin: theme.direction === 'rtl' ? RTL_ORIGIN : LTR_ORIGIN,
transformOrigin: theme.direction === 'rtl' ? RTL_ORIGIN : LTR_ORIGIN,
PaperProps: (0, _extends3.default)({}, PaperProps, {
classes: (0, _extends3.default)({}, PaperProps.classes, {
root: classes.paper
@@ -303,8 +198,77 @@ var Menu = function (_React$Component) {
return Menu;
}(_react2.default.Component);
Menu.propTypes = process.env.NODE_ENV !== "production" ? {
/**
* The DOM element used to set the position of the menu.
*/
anchorEl: _propTypes2.default.object,
/**
* Menu contents, normally `MenuItem`s.
*/
children: _propTypes2.default.node,
/**
* Useful to extend the style applied to components.
*/
classes: _propTypes2.default.object.isRequired,
/**
* Properties applied to the `MenuList` element.
*/
MenuListProps: _propTypes2.default.object,
/**
* Callback fired when the component requests to be closed.
*
* @param {object} event The event source of the callback
*/
onClose: _propTypes2.default.func,
/**
* Callback fired before the Menu enters.
*/
onEnter: _propTypes2.default.func,
/**
* Callback fired when the Menu has entered.
*/
onEntered: _propTypes2.default.func,
/**
* Callback fired when the Menu is entering.
*/
onEntering: _propTypes2.default.func,
/**
* Callback fired before the Menu exits.
*/
onExit: _propTypes2.default.func,
/**
* Callback fired when the Menu has exited.
*/
onExited: _propTypes2.default.func,
/**
* Callback fired when the Menu is exiting.
*/
onExiting: _propTypes2.default.func,
/**
* If `true`, the menu is visible.
*/
open: _propTypes2.default.bool.isRequired,
/**
* @ignore
*/
PaperProps: _propTypes2.default.object,
/**
* `classes` property applied to the `Popover` element.
*/
PopoverClasses: _propTypes2.default.object,
/**
* @ignore
*/
theme: _propTypes2.default.object.isRequired,
/**
* The length of the transition in `ms`, or 'auto'
*/
transitionDuration: _propTypes2.default.oneOfType([_propTypes2.default.number, _propTypes2.default.shape({ enter: _propTypes2.default.number, exit: _propTypes2.default.number }), _propTypes2.default.oneOf(['auto'])])
} : {};
Menu.defaultProps = {
open: false,
transitionDuration: 'auto'
};
exports.default = (0, _withStyles2.default)(styles, { withTheme: true, name: 'MuiMenu' })(Menu);
exports.default = (0, _withStyles2.default)(styles, { name: 'MuiMenu', withTheme: true })(Menu);

View File

@@ -1,95 +1,19 @@
// @flow
// @inheritedComponent Popover
import React from 'react';
import type { Node } from 'react';
import PropTypes from 'prop-types';
import { findDOMNode } from 'react-dom';
import getScrollbarSize from 'dom-helpers/util/scrollbarSize';
import withStyles from '../styles/withStyles';
import Popover from '../Popover';
import MenuList from './MenuList';
import type { TransitionCallback } from '../internal/transition';
type ProvidedProps = {
classes: Object,
theme: Object,
};
export type Props = {
/**
* The DOM element used to set the position of the menu.
*/
anchorEl?: ?HTMLElement, // match Popover
/**
* Menu contents, normally `MenuItem`s.
*/
children?: Node,
/**
* Useful to extend the style applied to components.
*/
classes?: Object,
/**
* Properties applied to the `MenuList` element.
*/
MenuListProps?: Object,
/**
* Callback fired before the Menu enters.
*/
onEnter?: TransitionCallback,
/**
* Callback fired when the Menu is entering.
*/
onEntering?: TransitionCallback,
/**
* Callback fired when the Menu has entered.
*/
onEntered?: TransitionCallback,
/**
* Callback fired before the Menu exits.
*/
onExit?: TransitionCallback,
/**
* Callback fired when the Menu is exiting.
*/
onExiting?: TransitionCallback,
/**
* Callback fired when the Menu has exited.
*/
onExited?: TransitionCallback,
/**
* Callback fired when the component requests to be closed.
*
* @param {object} event The event source of the callback
*/
onRequestClose?: Function,
/**
* If `true`, the menu is visible.
*/
open?: boolean,
/**
* @ignore
*/
PaperProps?: Object,
/**
* `classes` property applied to the `Popover` element.
*/
PopoverClasses?: Object,
/**
* @ignore
*/
theme?: Object,
/**
* The length of the transition in `ms`, or 'auto'
*/
transitionDuration?: number | { enter?: number, exit?: number } | 'auto',
};
const rtlOrigin = {
const RTL_ORIGIN = {
vertical: 'top',
horizontal: 'right',
};
const ltrOrigin = {
const LTR_ORIGIN = {
vertical: 'top',
horizontal: 'left',
};
@@ -105,29 +29,15 @@ export const styles = {
},
};
class Menu extends React.Component<ProvidedProps & Props> {
static defaultProps = {
open: false,
transitionDuration: 'auto',
};
class Menu extends React.Component {
componentDidMount() {
if (this.props.open) {
this.focus();
}
}
componentDidUpdate(prevProps) {
if (!prevProps.open && this.props.open) {
// Needs to refocus as when a menu is rendered into another Modal,
// the first modal might change the focus to prevent any leak.
this.focus();
}
}
getContentAnchorEl = () => {
if (!this.menuList || !this.menuList.selectedItem) {
// $FlowFixMe
return findDOMNode(this.menuList).firstChild;
}
@@ -138,21 +48,18 @@ class Menu extends React.Component<ProvidedProps & Props> {
focus = () => {
if (this.menuList && this.menuList.selectedItem) {
// $FlowFixMe
findDOMNode(this.menuList.selectedItem).focus();
return;
}
const menuList = findDOMNode(this.menuList);
if (menuList && menuList.firstChild) {
// $FlowFixMe
menuList.firstChild.focus();
}
};
handleEnter = (element: HTMLElement) => {
handleEnter = element => {
const { theme } = this.props;
const menuList = findDOMNode(this.menuList);
// Focus so the scroll computation of the Popover works as expected.
@@ -160,12 +67,9 @@ class Menu extends React.Component<ProvidedProps & Props> {
// Let's ignore that piece of logic if users are already overriding the width
// of the menu.
// $FlowFixMe
if (menuList && element.clientHeight < menuList.clientHeight && !menuList.style.width) {
const size = `${getScrollbarSize()}px`;
// $FlowFixMe
menuList.style[theme.direction === 'rtl' ? 'paddingLeft' : 'paddingRight'] = size;
// $FlowFixMe
menuList.style.width = `calc(100% + ${size})`;
}
@@ -174,12 +78,12 @@ class Menu extends React.Component<ProvidedProps & Props> {
}
};
handleListKeyDown = (event: SyntheticUIEvent<>, key: string) => {
handleListKeyDown = (event, key) => {
if (key === 'tab') {
event.preventDefault();
if (this.props.onRequestClose) {
this.props.onRequestClose(event);
if (this.props.onClose) {
this.props.onClose(event);
}
}
};
@@ -201,8 +105,8 @@ class Menu extends React.Component<ProvidedProps & Props> {
getContentAnchorEl={this.getContentAnchorEl}
classes={PopoverClasses}
onEnter={this.handleEnter}
anchorOrigin={theme.direction === 'rtl' ? rtlOrigin : ltrOrigin}
transformOrigin={theme.direction === 'rtl' ? rtlOrigin : ltrOrigin}
anchorOrigin={theme.direction === 'rtl' ? RTL_ORIGIN : LTR_ORIGIN}
transformOrigin={theme.direction === 'rtl' ? RTL_ORIGIN : LTR_ORIGIN}
PaperProps={{
...PaperProps,
classes: {
@@ -228,4 +132,81 @@ class Menu extends React.Component<ProvidedProps & Props> {
}
}
export default withStyles(styles, { withTheme: true, name: 'MuiMenu' })(Menu);
Menu.propTypes = {
/**
* The DOM element used to set the position of the menu.
*/
anchorEl: PropTypes.object,
/**
* Menu contents, normally `MenuItem`s.
*/
children: PropTypes.node,
/**
* Useful to extend the style applied to components.
*/
classes: PropTypes.object.isRequired,
/**
* Properties applied to the `MenuList` element.
*/
MenuListProps: PropTypes.object,
/**
* Callback fired when the component requests to be closed.
*
* @param {object} event The event source of the callback
*/
onClose: PropTypes.func,
/**
* Callback fired before the Menu enters.
*/
onEnter: PropTypes.func,
/**
* Callback fired when the Menu has entered.
*/
onEntered: PropTypes.func,
/**
* Callback fired when the Menu is entering.
*/
onEntering: PropTypes.func,
/**
* Callback fired before the Menu exits.
*/
onExit: PropTypes.func,
/**
* Callback fired when the Menu has exited.
*/
onExited: PropTypes.func,
/**
* Callback fired when the Menu is exiting.
*/
onExiting: PropTypes.func,
/**
* If `true`, the menu is visible.
*/
open: PropTypes.bool.isRequired,
/**
* @ignore
*/
PaperProps: PropTypes.object,
/**
* `classes` property applied to the `Popover` element.
*/
PopoverClasses: PropTypes.object,
/**
* @ignore
*/
theme: PropTypes.object.isRequired,
/**
* The length of the transition in `ms`, or 'auto'
*/
transitionDuration: PropTypes.oneOfType([
PropTypes.number,
PropTypes.shape({ enter: PropTypes.number, exit: PropTypes.number }),
PropTypes.oneOf(['auto']),
]),
};
Menu.defaultProps = {
transitionDuration: 'auto',
};
export default withStyles(styles, { name: 'MuiMenu', withTheme: true })(Menu);

View File

@@ -2,19 +2,13 @@ import * as React from 'react';
import { StandardProps } from '..';
import { ListItemProps, ListItemClassKey } from '../List';
export interface MenuItemProps extends StandardProps<
ListItemProps,
MenuItemClassKey
> {
component?: React.ReactType;
export interface MenuItemProps extends StandardProps<ListItemProps, MenuItemClassKey> {
component?: React.ReactType<MenuItemProps>;
role?: string;
selected?: boolean;
}
export type MenuItemClassKey =
| ListItemClassKey
| 'selected'
;
export type MenuItemClassKey = ListItemClassKey | 'selected';
declare const MenuItem: React.ComponentType<MenuItemProps>;

View File

@@ -17,13 +17,14 @@ var _extends2 = require('babel-runtime/helpers/extends');
var _extends3 = _interopRequireDefault(_extends2);
var _ref;
// @inheritedComponent ListItem
var _react = require('react');
var _react2 = _interopRequireDefault(_react);
var _propTypes = require('prop-types');
var _propTypes2 = _interopRequireDefault(_propTypes);
var _classnames = require('classnames');
var _classnames2 = _interopRequireDefault(_classnames);
@@ -38,65 +39,22 @@ var _ListItem2 = _interopRequireDefault(_ListItem);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var babelPluginFlowReactPropTypes_proptype_Node = require('react').babelPluginFlowReactPropTypes_proptype_Node || require('prop-types').any;
var babelPluginFlowReactPropTypes_proptype_ElementType = require('react').babelPluginFlowReactPropTypes_proptype_ElementType || require('prop-types').any;
var styles = exports.styles = function styles(theme) {
return {
root: (0, _extends3.default)({}, theme.typography.subheading, {
height: 24,
height: theme.spacing.unit * 3,
boxSizing: 'content-box',
background: 'none',
width: 'auto',
overflow: 'hidden',
textOverflow: 'ellipsis',
whiteSpace: 'nowrap',
'&:focus': {
background: theme.palette.text.divider
},
'&:hover': {
backgroundColor: theme.palette.text.divider
'&$selected': {
backgroundColor: theme.palette.action.selected
}
}),
selected: {
backgroundColor: theme.palette.text.divider
}
selected: {}
};
};
var babelPluginFlowReactPropTypes_proptype_Props = {
/**
* Menu item contents.
*/
children: typeof babelPluginFlowReactPropTypes_proptype_Node === 'function' ? babelPluginFlowReactPropTypes_proptype_Node : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_Node),
/**
* Useful to extend the style applied to components.
*/
classes: require('prop-types').object,
/**
* @ignore
*/
className: require('prop-types').string,
/**
* The component used for the root node.
* Either a string to use a DOM element or a component.
*/
component: typeof babelPluginFlowReactPropTypes_proptype_ElementType === 'function' ? babelPluginFlowReactPropTypes_proptype_ElementType : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_ElementType),
/**
* @ignore
*/
role: require('prop-types').string,
/**
* Use to apply selected styling.
*/
selected: require('prop-types').bool
};
}; // @inheritedComponent ListItem
function MenuItem(props) {
var classes = props.classes,
@@ -118,13 +76,36 @@ function MenuItem(props) {
}, other));
}
MenuItem.propTypes = process.env.NODE_ENV !== "production" ? (_ref = {
classes: require('prop-types').object.isRequired,
role: require('prop-types').string.isRequired,
selected: require('prop-types').bool.isRequired,
children: typeof babelPluginFlowReactPropTypes_proptype_Node === 'function' ? babelPluginFlowReactPropTypes_proptype_Node : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_Node)
}, (0, _defineProperty3.default)(_ref, 'classes', require('prop-types').object), (0, _defineProperty3.default)(_ref, 'className', require('prop-types').string), (0, _defineProperty3.default)(_ref, 'component', typeof babelPluginFlowReactPropTypes_proptype_ElementType === 'function' ? babelPluginFlowReactPropTypes_proptype_ElementType : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_ElementType)), (0, _defineProperty3.default)(_ref, 'role', require('prop-types').string), (0, _defineProperty3.default)(_ref, 'selected', require('prop-types').bool), _ref) : {};
MenuItem.propTypes = process.env.NODE_ENV !== "production" ? {
/**
* Menu item contents.
*/
children: _propTypes2.default.node,
/**
* Useful to extend the style applied to components.
*/
classes: _propTypes2.default.object.isRequired,
/**
* @ignore
*/
className: _propTypes2.default.string,
/**
* The component used for the root node.
* Either a string to use a DOM element or a component.
*/
component: _propTypes2.default.oneOfType([_propTypes2.default.string, _propTypes2.default.func]),
/**
* @ignore
*/
role: _propTypes2.default.string,
/**
* Use to apply selected styling.
*/
selected: _propTypes2.default.bool
} : {};
MenuItem.defaultProps = {
component: 'li',
role: 'menuitem',
selected: false
};

View File

@@ -1,68 +1,28 @@
// @flow
// @inheritedComponent ListItem
import React from 'react';
import type { ElementType, Node } from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import withStyles from '../styles/withStyles';
import ListItem from '../List/ListItem';
export const styles = (theme: Object) => ({
export const styles = theme => ({
root: {
...theme.typography.subheading,
height: 24,
height: theme.spacing.unit * 3,
boxSizing: 'content-box',
background: 'none',
width: 'auto',
overflow: 'hidden',
textOverflow: 'ellipsis',
whiteSpace: 'nowrap',
'&:focus': {
background: theme.palette.text.divider,
},
'&:hover': {
backgroundColor: theme.palette.text.divider,
'&$selected': {
backgroundColor: theme.palette.action.selected,
},
},
selected: {
backgroundColor: theme.palette.text.divider,
},
selected: {},
});
type ProvidedProps = {
classes: Object,
role: string,
selected: boolean,
};
export type Props = {
/**
* Menu item contents.
*/
children?: Node,
/**
* Useful to extend the style applied to components.
*/
classes?: Object,
/**
* @ignore
*/
className?: string,
/**
* The component used for the root node.
* Either a string to use a DOM element or a component.
*/
component?: ElementType,
/**
* @ignore
*/
role?: string,
/**
* Use to apply selected styling.
*/
selected?: boolean,
};
function MenuItem(props: ProvidedProps & Props) {
function MenuItem(props) {
const { classes, className: classNameProp, component, selected, role, ...other } = props;
const className = classNames(
@@ -85,7 +45,36 @@ function MenuItem(props: ProvidedProps & Props) {
);
}
MenuItem.propTypes = {
/**
* Menu item contents.
*/
children: PropTypes.node,
/**
* Useful to extend the style applied to components.
*/
classes: PropTypes.object.isRequired,
/**
* @ignore
*/
className: PropTypes.string,
/**
* The component used for the root node.
* Either a string to use a DOM element or a component.
*/
component: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
/**
* @ignore
*/
role: PropTypes.string,
/**
* Use to apply selected styling.
*/
selected: PropTypes.bool,
};
MenuItem.defaultProps = {
component: 'li',
role: 'menuitem',
selected: false,
};

View File

@@ -2,17 +2,11 @@ import * as React from 'react';
import { StandardProps } from '..';
import { ListProps, ListClassKey } from '../List';
export interface MenuListProps extends StandardProps<
ListProps,
MenuListClassKey,
'onKeyDown'
> {
export interface MenuListProps extends StandardProps<ListProps, MenuListClassKey, 'onKeyDown'> {
onKeyDown?: React.ReactEventHandler<React.KeyboardEvent<any>>;
}
export type MenuListClassKey =
| ListClassKey
;
export type MenuListClassKey = ListClassKey;
declare const MenuList: React.ComponentType<MenuListProps>;

View File

@@ -40,6 +40,10 @@ var _react = require('react');
var _react2 = _interopRequireDefault(_react);
var _propTypes = require('prop-types');
var _propTypes2 = _interopRequireDefault(_propTypes);
var _reactDom = require('react-dom');
var _keycode = require('keycode');
@@ -64,31 +68,8 @@ var _List2 = _interopRequireDefault(_List);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var babelPluginFlowReactPropTypes_proptype_Node = require('react').babelPluginFlowReactPropTypes_proptype_Node || require('prop-types').any;
// @inheritedComponent List
var babelPluginFlowReactPropTypes_proptype_Props = {
/**
* MenuList contents, normally `MenuItem`s.
*/
children: typeof babelPluginFlowReactPropTypes_proptype_Node === 'function' ? babelPluginFlowReactPropTypes_proptype_Node : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_Node),
/**
* @ignore
*/
className: require('prop-types').string,
/**
* @ignore
*/
onBlur: require('prop-types').func,
/**
* @ignore
*/
onKeyDown: require('prop-types').func
};
var MenuList = function (_React$Component) {
(0, _inherits3.default)(MenuList, _React$Component);
@@ -126,10 +107,8 @@ var MenuList = function (_React$Component) {
if ((key === 'up' || key === 'down') && (!currentFocus || currentFocus && !(0, _contains2.default)(list, currentFocus))) {
if (_this.selectedItem) {
// $FlowFixMe
(0, _reactDom.findDOMNode)(_this.selectedItem).focus();
} else {
// $FlowFixMe
list.firstChild.focus();
}
} else if (key === 'down') {
@@ -150,9 +129,7 @@ var MenuList = function (_React$Component) {
}, _this.handleItemFocus = function (event) {
var list = (0, _reactDom.findDOMNode)(_this.list);
if (list) {
// $FlowFixMe
for (var i = 0; i < list.children.length; i += 1) {
// $FlowFixMe
if (list.children[i] === event.currentTarget) {
_this.setTabIndex(i);
break;
@@ -188,10 +165,8 @@ var MenuList = function (_React$Component) {
}
if (currentTabIndex && currentTabIndex >= 0) {
// $FlowFixMe
list.children[currentTabIndex].focus();
} else {
// $FlowFixMe
list.firstChild.focus();
}
}
@@ -200,7 +175,6 @@ var MenuList = function (_React$Component) {
value: function resetTabIndex() {
var list = (0, _reactDom.findDOMNode)(this.list);
var currentFocus = (0, _activeElement2.default)((0, _ownerDocument2.default)(list));
// $FlowFixMe
var items = [].concat((0, _toConsumableArray3.default)(list.children));
var currentFocusIndex = items.indexOf(currentFocus);
@@ -231,7 +205,7 @@ var MenuList = function (_React$Component) {
_List2.default,
(0, _extends3.default)({
role: 'menu',
rootRef: function rootRef(node) {
ref: function ref(node) {
_this2.list = node;
},
className: className,
@@ -258,9 +232,22 @@ var MenuList = function (_React$Component) {
}(_react2.default.Component);
MenuList.propTypes = process.env.NODE_ENV !== "production" ? {
children: typeof babelPluginFlowReactPropTypes_proptype_Node === 'function' ? babelPluginFlowReactPropTypes_proptype_Node : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_Node),
className: require('prop-types').string,
onBlur: require('prop-types').func,
onKeyDown: require('prop-types').func
/**
* MenuList contents, normally `MenuItem`s.
*/
children: _propTypes2.default.node,
/**
* @ignore
*/
className: _propTypes2.default.string,
/**
* @ignore
*/
onBlur: _propTypes2.default.func,
/**
* @ignore
*/
onKeyDown: _propTypes2.default.func
} : {};
exports.default = MenuList;

View File

@@ -1,8 +1,7 @@
// @flow
// @inheritedComponent List
import React from 'react';
import type { Node } from 'react';
import PropTypes from 'prop-types';
import { findDOMNode } from 'react-dom';
import keycode from 'keycode';
import contains from 'dom-helpers/query/contains';
@@ -10,30 +9,7 @@ import activeElement from 'dom-helpers/activeElement';
import ownerDocument from 'dom-helpers/ownerDocument';
import List from '../List';
export type Props = {
/**
* MenuList contents, normally `MenuItem`s.
*/
children?: Node,
/**
* @ignore
*/
className?: string,
/**
* @ignore
*/
onBlur?: Function,
/**
* @ignore
*/
onKeyDown?: (event: SyntheticUIEvent<>, key: string) => void,
};
type State = {
currentTabIndex: ?number,
};
class MenuList extends React.Component<Props, State> {
class MenuList extends React.Component {
state = {
currentTabIndex: undefined,
};
@@ -46,7 +22,7 @@ class MenuList extends React.Component<Props, State> {
clearTimeout(this.blurTimer);
}
setTabIndex(index: number) {
setTabIndex(index) {
this.setState({ currentTabIndex: index });
}
@@ -54,7 +30,7 @@ class MenuList extends React.Component<Props, State> {
selectedItem = undefined;
blurTimer = undefined;
handleBlur = (event: SyntheticUIEvent<>) => {
handleBlur = event => {
this.blurTimer = setTimeout(() => {
if (this.list) {
const list = findDOMNode(this.list);
@@ -70,7 +46,7 @@ class MenuList extends React.Component<Props, State> {
}
};
handleKeyDown = (event: SyntheticUIEvent<>) => {
handleKeyDown = event => {
const list = findDOMNode(this.list);
const key = keycode(event);
const currentFocus = activeElement(ownerDocument(list));
@@ -80,10 +56,8 @@ class MenuList extends React.Component<Props, State> {
(!currentFocus || (currentFocus && !contains(list, currentFocus)))
) {
if (this.selectedItem) {
// $FlowFixMe
findDOMNode(this.selectedItem).focus();
} else {
// $FlowFixMe
list.firstChild.focus();
}
} else if (key === 'down') {
@@ -103,12 +77,10 @@ class MenuList extends React.Component<Props, State> {
}
};
handleItemFocus = (event: SyntheticUIEvent<>) => {
handleItemFocus = event => {
const list = findDOMNode(this.list);
if (list) {
// $FlowFixMe
for (let i = 0; i < list.children.length; i += 1) {
// $FlowFixMe
if (list.children[i] === event.currentTarget) {
this.setTabIndex(i);
break;
@@ -125,10 +97,8 @@ class MenuList extends React.Component<Props, State> {
}
if (currentTabIndex && currentTabIndex >= 0) {
// $FlowFixMe
list.children[currentTabIndex].focus();
} else {
// $FlowFixMe
list.firstChild.focus();
}
}
@@ -136,7 +106,6 @@ class MenuList extends React.Component<Props, State> {
resetTabIndex() {
const list = findDOMNode(this.list);
const currentFocus = activeElement(ownerDocument(list));
// $FlowFixMe
const items = [...list.children];
const currentFocusIndex = items.indexOf(currentFocus);
@@ -158,7 +127,7 @@ class MenuList extends React.Component<Props, State> {
<List
data-mui-test="MenuList"
role="menu"
rootRef={node => {
ref={node => {
this.list = node;
}}
className={className}
@@ -186,4 +155,23 @@ class MenuList extends React.Component<Props, State> {
}
}
MenuList.propTypes = {
/**
* MenuList contents, normally `MenuItem`s.
*/
children: PropTypes.node,
/**
* @ignore
*/
className: PropTypes.string,
/**
* @ignore
*/
onBlur: PropTypes.func,
/**
* @ignore
*/
onKeyDown: PropTypes.func,
};
export default MenuList;

View File

@@ -1,5 +1,3 @@
// @flow
export { default } from './Menu';
export { default as MenuList } from './MenuList';
export { default as MenuItem } from './MenuItem';