draft-components 1.0.0-beta.5 → 1.0.0-beta.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/components/menu/menu-item.cjs +11 -4
- package/cjs/components/menu/menu.cjs +3 -4
- package/css/draft-components.css +1832 -1823
- package/esm/components/menu/menu-item.js +11 -4
- package/esm/components/menu/menu.js +3 -4
- package/package.json +3 -3
- package/types/components/menu/menu-item.d.ts +6 -3
- package/types/components/menu/menu.d.ts +4 -3
|
@@ -4,11 +4,18 @@ const jsxRuntime = require('react/jsx-runtime');
|
|
|
4
4
|
const react = require('react');
|
|
5
5
|
const reactHelpers = require('../../lib/react-helpers.cjs');
|
|
6
6
|
|
|
7
|
-
const MenuItem = react.forwardRef(function MenuItem({
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
const MenuItem = react.forwardRef(function MenuItem({ role = 'menuitem', appearance = 'default', iconLeft = null, iconRight = null, className, children, ...props }, ref) {
|
|
8
|
+
let label = children;
|
|
9
|
+
if (iconLeft || iconRight) {
|
|
10
|
+
const className = reactHelpers.classNames('dc-menu-btn__label', {
|
|
11
|
+
'dc-menu-btn__label_gap_left': iconLeft,
|
|
12
|
+
'dc-menu-btn__label_gap_right': iconRight,
|
|
13
|
+
});
|
|
14
|
+
label = jsxRuntime.jsx("span", { className: className, children: label });
|
|
15
|
+
}
|
|
16
|
+
return (jsxRuntime.jsx("li", { role: "presentation", children: jsxRuntime.jsxs("button", { ...props, ref: ref, className: reactHelpers.classNames(className, 'dc-menu-btn', {
|
|
10
17
|
[`dc-menu-btn_${appearance}`]: appearance,
|
|
11
|
-
}), type: "button", role:
|
|
18
|
+
}), type: "button", role: role, tabIndex: -1, children: [iconLeft, label, iconRight] }) }));
|
|
12
19
|
});
|
|
13
20
|
|
|
14
21
|
exports.MenuItem = MenuItem;
|
|
@@ -10,7 +10,7 @@ require('../button/icon-button.cjs');
|
|
|
10
10
|
const popover = require('../popover/popover.cjs');
|
|
11
11
|
const menuItem = require('./menu-item.cjs');
|
|
12
12
|
|
|
13
|
-
function Menu({ defaultIsOpen = false, placement = 'bottom', alignment = 'start', buttonAppearance = 'default', buttonVariant = 'filled', button: button$1, className, children, onOpen, onClose, onKeyDown, ...props }) {
|
|
13
|
+
function Menu({ defaultIsOpen = false, placement = 'bottom', alignment = 'start', buttonClassName = '', buttonAppearance = 'default', buttonVariant = 'filled', button: button$1, className, children, onOpen, onClose, onKeyDown, ...props }) {
|
|
14
14
|
const id = react.useId();
|
|
15
15
|
const menuId = props.id || id;
|
|
16
16
|
const buttonId = `menu-button-${menuId}`;
|
|
@@ -83,12 +83,11 @@ function Menu({ defaultIsOpen = false, placement = 'bottom', alignment = 'start'
|
|
|
83
83
|
const handleButtonClick = (event) => {
|
|
84
84
|
if (isOpen) {
|
|
85
85
|
closeMenu();
|
|
86
|
-
focusMenuButton();
|
|
87
86
|
}
|
|
88
87
|
else {
|
|
89
88
|
openMenu();
|
|
90
|
-
window.setTimeout(focusFirstMenuItem);
|
|
91
89
|
}
|
|
90
|
+
focusMenuButton();
|
|
92
91
|
event.preventDefault();
|
|
93
92
|
event.stopPropagation();
|
|
94
93
|
};
|
|
@@ -159,7 +158,7 @@ function Menu({ defaultIsOpen = false, placement = 'bottom', alignment = 'start'
|
|
|
159
158
|
closeMenu,
|
|
160
159
|
});
|
|
161
160
|
}
|
|
162
|
-
return (jsxRuntime.jsx(button.Button, { ref: ref, id: buttonId, "aria-haspopup": true, "aria-expanded": isOpen, "aria-controls": menuId, onClick: handleButtonClick, onKeyDown: handleButtonKeyDown, appearance: buttonAppearance, variant: buttonVariant, children: button$1 }));
|
|
161
|
+
return (jsxRuntime.jsx(button.Button, { "data-testid": "menu-button", ref: ref, id: buttonId, "aria-haspopup": true, "aria-expanded": isOpen, "aria-controls": menuId, onClick: handleButtonClick, onKeyDown: handleButtonKeyDown, className: buttonClassName, appearance: buttonAppearance, variant: buttonVariant, children: button$1 }));
|
|
163
162
|
};
|
|
164
163
|
return (jsxRuntime.jsx(popover.Popover, { className: "dc-menu__container", placement: placement, alignment: alignment, anchor: renderAnchor, isOpen: isOpen, onClose: closeMenu, children: jsxRuntime.jsx("ul", { ...props, className: reactHelpers.classNames('dc-menu', className), role: "menu", id: menuId, "aria-labelledby": buttonId, onKeyDown: handleMenuKeyDown, children: react.Children.map(children, (child) => {
|
|
165
164
|
if (isMenuItem(child)) {
|