carbon-react 94.0.2 → 94.0.3

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.
@@ -56,7 +56,7 @@ const ActionPopover = ({
56
56
  const [isOpen, setOpenState] = (0, _react.useState)(false);
57
57
  const [focusIndex, setFocusIndex] = (0, _react.useState)(0);
58
58
  const [guid] = (0, _react.useState)((0, _guid.default)());
59
- const button = (0, _react.useRef)();
59
+ const buttonRef = (0, _react.useRef)();
60
60
  const menu = (0, _react.useRef)();
61
61
  const itemCount = (0, _react.useMemo)(() => {
62
62
  return _react.default.Children.toArray(children).filter(child => child.type === _actionPopoverItem.default).length;
@@ -94,7 +94,7 @@ const ActionPopover = ({
94
94
 
95
95
  if (!isOpening) {
96
96
  // Closing the menu should focus the MenuButton
97
- button.current.focus();
97
+ buttonRef.current.querySelector("[data-component='action-popover-button']").focus();
98
98
  }
99
99
  }, [isOpen, setOpen]); // Keyboard commands implemented as recommended by WAI-ARIA best practices
100
100
  // https://www.w3.org/TR/wai-aria-practices/examples/menu-button/menu-button-actions.html
@@ -112,7 +112,7 @@ const ActionPopover = ({
112
112
  setOpen(true);
113
113
  }
114
114
  }, [itemCount, setOpen]);
115
- const focusButton = (0, _react.useCallback)(() => button.current.focus(), []);
115
+ const focusButton = (0, _react.useCallback)(() => buttonRef.current.querySelector("[data-component='action-popover-button']").focus(), []);
116
116
  (0, _react.useEffect)(() => {
117
117
  const handler = ({
118
118
  target
@@ -120,7 +120,7 @@ const ActionPopover = ({
120
120
  // If the event didn't came from part of this component, close the menu.
121
121
  // There will be multiple document click listeners but we cant prevent propagation because it will interfere with
122
122
  // other instances on the same page
123
- if (!button.current.contains(target) && menu.current && !menu.current.contains(target)) {
123
+ if (!buttonRef.current.contains(target) && menu.current && !menu.current.contains(target)) {
124
124
  setOpen(false);
125
125
  }
126
126
  };
@@ -136,23 +136,37 @@ const ActionPopover = ({
136
136
  };
137
137
  }, [setOpen]);
138
138
 
139
- const menuButton = () => {
139
+ const menuButton = menuID => {
140
140
  if (renderButton) {
141
141
  return renderButton({
142
- tabIndex: -1,
143
- "data-element": "action-popover-menu-button"
142
+ tabIndex: isOpen ? "-1" : "0",
143
+ "data-component": "action-popover-button",
144
+ ariaAttributes: {
145
+ "aria-haspopup": "true",
146
+ "aria-label": l.actionPopover.ariaLabel(),
147
+ "aria-controls": menuID,
148
+ "aria-expanded": isOpen
149
+ }
144
150
  });
145
151
  }
146
152
 
147
- return /*#__PURE__*/_react.default.createElement(_actionPopover.ButtonIcon, {
153
+ return /*#__PURE__*/_react.default.createElement(_actionPopover.StyledButtonIcon, {
154
+ role: "button",
155
+ "aria-haspopup": "true",
156
+ "aria-label": l.actionPopover.ariaLabel(),
157
+ "aria-controls": menuID,
158
+ "aria-expanded": isOpen,
159
+ tabIndex: isOpen ? "-1" : "0",
160
+ "data-component": "action-popover-button"
161
+ }, /*#__PURE__*/_react.default.createElement(_actionPopover.ButtonIcon, {
148
162
  type: "ellipsis_vertical"
149
- });
163
+ }));
150
164
  };
151
165
 
152
166
  const parentID = id || `ActionPopoverButton_${guid}`;
153
167
  const menuID = `ActionPopoverMenu_${guid}`;
154
168
  const menuProps = {
155
- button,
169
+ buttonRef,
156
170
  parentID,
157
171
  setFocusIndex,
158
172
  focusIndex,
@@ -165,18 +179,12 @@ const ActionPopover = ({
165
179
  };
166
180
  return /*#__PURE__*/_react.default.createElement(_actionPopover.MenuButton, _extends({
167
181
  id: parentID,
168
- "data-component": "action-popover-button",
169
- role: "button",
170
- "aria-haspopup": "true",
171
- "aria-label": l.actionPopover.ariaLabel(),
172
- "aria-controls": menuID,
173
- "aria-expanded": isOpen,
174
- tabIndex: isOpen ? "-1" : "0",
182
+ "data-component": "action-popover-wrapper",
175
183
  onKeyDown: onButtonKeyDown,
176
184
  onClick: onButtonClick,
177
185
  isOpen,
178
- ref: button
179
- }, rest), menuButton(), /*#__PURE__*/_react.default.createElement(_actionPopoverContext.default.Provider, {
186
+ ref: buttonRef
187
+ }, rest), menuButton(menuID), /*#__PURE__*/_react.default.createElement(_actionPopoverContext.default.Provider, {
180
188
  value: {
181
189
  setOpenPopover: setOpen,
182
190
  focusButton,
@@ -184,7 +192,7 @@ const ActionPopover = ({
184
192
  }
185
193
  }, isOpen && /*#__PURE__*/_react.default.createElement(_popover.default, {
186
194
  placement: mappedPlacement,
187
- reference: button
195
+ reference: buttonRef
188
196
  }, /*#__PURE__*/_react.default.createElement(_actionPopoverMenu.default, _extends({
189
197
  "data-component": "action-popover",
190
198
  role: "menu",
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.StyledMenuItem = exports.MenuButtonOverrideWrapper = exports.SubMenuItemIcon = exports.MenuItemDivider = exports.MenuItemIcon = exports.ButtonIcon = exports.MenuButton = exports.MenuItemFactory = exports.Menu = void 0;
6
+ exports.StyledMenuItem = exports.MenuButtonOverrideWrapper = exports.SubMenuItemIcon = exports.MenuItemDivider = exports.MenuItemIcon = exports.StyledButtonIcon = exports.ButtonIcon = exports.MenuButton = exports.MenuItemFactory = exports.Menu = void 0;
7
7
 
8
8
  var _react = _interopRequireDefault(require("react"));
9
9
 
@@ -131,16 +131,6 @@ const MenuButton = _styledComponents.default.div`
131
131
  isOpen,
132
132
  theme
133
133
  }) => isOpen && `background-color: ${theme.colors.white}`}
134
- &:hover, &:focus {
135
- background-color: ${({
136
- theme
137
- }) => theme.colors.white};
138
- }
139
- &:focus {
140
- outline: 2px solid ${({
141
- theme
142
- }) => theme.colors.focus};
143
- }
144
134
  `;
145
135
  /**
146
136
  * Creates a factory that returns a styled component with a custom
@@ -168,6 +158,21 @@ const iconThemeProviderFactory = (Component, themeFn) => (0, _styledComponents.w
168
158
 
169
159
  const ButtonIcon = iconThemeProviderFactory(_icon.default, palette => palette.slate);
170
160
  exports.ButtonIcon = ButtonIcon;
161
+ const StyledButtonIcon = _styledComponents.default.div`
162
+ &:hover,
163
+ &:focus {
164
+ background-color: ${({
165
+ theme
166
+ }) => theme.colors.white};
167
+ }
168
+
169
+ &:focus {
170
+ outline: 2px solid ${({
171
+ theme
172
+ }) => theme.colors.focus};
173
+ }
174
+ `;
175
+ exports.StyledButtonIcon = StyledButtonIcon;
171
176
  const MenuItemIcon = (0, _styledComponents.default)(iconThemeProviderFactory(_icon.default, () => "inherit"))`
172
177
  ${({
173
178
  theme,
@@ -203,13 +208,18 @@ exports.SubMenuItemIcon = SubMenuItemIcon;
203
208
  const MenuButtonOverrideWrapper = _styledComponents.default.div`
204
209
  ${({
205
210
  theme
206
- }) => `
211
+ }) => (0, _styledComponents.css)`
207
212
  ${_button.default} {
208
213
  padding: 0px ${theme.spacing}px;
209
214
  width: 100%;
210
215
  &:focus {
211
216
  outline-width: 2px;
212
217
  }
218
+
219
+ &:hover,
220
+ &:focus {
221
+ background-color: ${theme.colors.white};
222
+ }
213
223
  }
214
224
  `}
215
225
  `;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "carbon-react",
3
- "version": "94.0.2",
3
+ "version": "94.0.3",
4
4
  "description": "A library of reusable React components for easily building user interfaces.",
5
5
  "engineStrict": true,
6
6
  "engines": {