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

@@ -1,24 +1,21 @@
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
import _extends from 'babel-runtime/helpers/extends';
import _objectWithoutProperties from 'babel-runtime/helpers/objectWithoutProperties';
// @inheritedComponent Popover
import React 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';
const rtlOrigin = {
const RTL_ORIGIN = {
vertical: 'top',
horizontal: 'right'
};
const ltrOrigin = {
const LTR_ORIGIN = {
vertical: 'top',
horizontal: 'left'
};
@@ -40,26 +37,22 @@ class Menu extends React.Component {
return _temp = super(...args), this.getContentAnchorEl = () => {
if (!this.menuList || !this.menuList.selectedItem) {
// $FlowFixMe
return findDOMNode(this.menuList).firstChild;
}
return findDOMNode(this.menuList.selectedItem);
}, this.menuList = undefined, this.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();
}
}, this.handleEnter = element => {
const { theme } = this.props;
const menuList = findDOMNode(this.menuList);
// Focus so the scroll computation of the Popover works as expected.
@@ -67,12 +60,9 @@ class Menu extends 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) {
const size = `${getScrollbarSize()}px`;
// $FlowFixMe
menuList.style[theme.direction === 'rtl' ? 'paddingLeft' : 'paddingRight'] = size;
// $FlowFixMe
menuList.style.width = `calc(100% + ${size})`;
}
@@ -83,8 +73,8 @@ class Menu extends React.Component {
if (key === 'tab') {
event.preventDefault();
if (this.props.onRequestClose) {
this.props.onRequestClose(event);
if (this.props.onClose) {
this.props.onClose(event);
}
}
}, _temp;
@@ -96,14 +86,6 @@ class Menu extends React.Component {
}
}
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();
}
}
render() {
const _props = this.props,
{
@@ -123,8 +105,8 @@ class Menu extends 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: _extends({}, PaperProps, {
classes: _extends({}, PaperProps.classes, {
root: classes.paper
@@ -134,7 +116,6 @@ class Menu extends React.Component {
React.createElement(
MenuList,
_extends({
'data-mui-test': 'Menu',
role: 'menu',
onKeyDown: this.handleListKeyDown
}, MenuListProps, {
@@ -148,8 +129,77 @@ class Menu extends React.Component {
}
}
Menu.propTypes = process.env.NODE_ENV !== "production" ? {
/**
* 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 = {
open: false,
transitionDuration: 'auto'
};
export default withStyles(styles, { withTheme: true, name: 'MuiMenu' })(Menu);
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

@@ -1,33 +1,26 @@
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
import _objectWithoutProperties from 'babel-runtime/helpers/objectWithoutProperties';
import _extends from 'babel-runtime/helpers/extends';
// @inheritedComponent ListItem
import React 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 => ({
root: _extends({}, 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: {}
});
function MenuItem(props) {
@@ -47,7 +40,36 @@ function MenuItem(props) {
}, other));
}
MenuItem.propTypes = process.env.NODE_ENV !== "production" ? {
/**
* 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

@@ -1,11 +1,9 @@
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
import _extends from 'babel-runtime/helpers/extends';
import _objectWithoutProperties from 'babel-runtime/helpers/objectWithoutProperties';
// @inheritedComponent List
import React from 'react';
import PropTypes from 'prop-types';
import { findDOMNode } from 'react-dom';
import keycode from 'keycode';
import contains from 'dom-helpers/query/contains';
@@ -40,10 +38,8 @@ class MenuList extends React.Component {
if ((key === 'up' || key === 'down') && (!currentFocus || currentFocus && !contains(list, currentFocus))) {
if (this.selectedItem) {
// $FlowFixMe
findDOMNode(this.selectedItem).focus();
} else {
// $FlowFixMe
list.firstChild.focus();
}
} else if (key === 'down') {
@@ -64,9 +60,7 @@ class MenuList extends React.Component {
}, this.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;
@@ -96,10 +90,8 @@ class MenuList extends React.Component {
}
if (currentTabIndex && currentTabIndex >= 0) {
// $FlowFixMe
list.children[currentTabIndex].focus();
} else {
// $FlowFixMe
list.firstChild.focus();
}
}
@@ -107,7 +99,6 @@ class MenuList extends React.Component {
resetTabIndex() {
const list = findDOMNode(this.list);
const currentFocus = activeElement(ownerDocument(list));
// $FlowFixMe
const items = [...list.children];
const currentFocusIndex = items.indexOf(currentFocus);
@@ -130,9 +121,8 @@ class MenuList extends React.Component {
return React.createElement(
List,
_extends({
'data-mui-test': 'MenuList',
role: 'menu',
rootRef: node => {
ref: node => {
this.list = node;
},
className: className,
@@ -156,4 +146,23 @@ class MenuList extends React.Component {
}
}
MenuList.propTypes = process.env.NODE_ENV !== "production" ? {
/**
* MenuList contents, normally `MenuItem`s.
*/
children: PropTypes.node,
/**
* @ignore
*/
className: PropTypes.string,
/**
* @ignore
*/
onBlur: PropTypes.func,
/**
* @ignore
*/
onKeyDown: PropTypes.func
} : {};
export default MenuList;