UNPKG

1.51 kBJavaScriptView Raw
1import cx from 'classnames';
2import PropTypes from 'prop-types';
3import React, { Children } from 'react';
4import { BaseMenuItem } from '../MenuItem';
5import { preventInputBlur } from '../../utils';
6import { checkPropType, isRequiredForA11y } from '../../propTypes';
7const MenuDivider = () => React.createElement("div", { className: "dropdown-divider", role: "separator" });
8const MenuHeader = (props) => (React.createElement("div", { ...props, className: "dropdown-header", role: "heading" }));
9const propTypes = {
10 'aria-label': PropTypes.string,
11 emptyLabel: PropTypes.node,
12 id: checkPropType(PropTypes.oneOfType([PropTypes.number, PropTypes.string]), isRequiredForA11y),
13 maxHeight: PropTypes.string,
14};
15const defaultProps = {
16 'aria-label': 'menu-options',
17};
18const Menu = ({ emptyLabel = 'No matches found.', innerRef, maxHeight = '300px', style, ...props }) => {
19 const children = Children.count(props.children) === 0 ? (React.createElement(BaseMenuItem, { disabled: true, role: "option" }, emptyLabel)) : (props.children);
20 return (React.createElement("div", { ...props, className: cx('rbt-menu', 'dropdown-menu', 'show', props.className), onMouseDown: preventInputBlur, ref: innerRef, role: "listbox", style: {
21 ...style,
22 display: 'block',
23 maxHeight,
24 overflow: 'auto',
25 } }, children));
26};
27Menu.propTypes = propTypes;
28Menu.defaultProps = defaultProps;
29Menu.Divider = MenuDivider;
30Menu.Header = MenuHeader;
31export default Menu;