carbon-react 147.3.0 → 147.4.0

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.
@@ -11,7 +11,6 @@ export interface InputIconToggleProps extends InputIconToggleStyleProps, Validat
11
11
  onFocus?: (ev: React.FocusEvent<HTMLElement>) => void;
12
12
  onMouseDown?: (ev: React.MouseEvent<HTMLElement>) => void;
13
13
  readOnly?: boolean;
14
- tooltipId?: string;
15
14
  useValidationIcon?: boolean;
16
15
  /** Id of the validation icon */
17
16
  validationIconId?: string;
@@ -56,11 +56,12 @@ const InputIconToggle = ({
56
56
  onFocus: onFocus,
57
57
  onBlur: onBlur,
58
58
  onMouseDown: onMouseDown,
59
- tabIndex: iconTabIndex,
60
59
  "data-element": "input-icon-toggle",
61
60
  disabled: disabled,
62
61
  readOnly: readOnly,
63
- "data-role": "input-icon-toggle"
62
+ "data-role": "input-icon-toggle",
63
+ "aria-hidden": "true",
64
+ tabIndex: -1
64
65
  }, /*#__PURE__*/React.createElement(Icon, {
65
66
  disabled: disabled || readOnly,
66
67
  type: type
@@ -4,4 +4,5 @@ export declare const getItems: (children: React.ReactNode | React.ReactNode[]) =
4
4
  export declare const isItemDisabled: (item: ReactItem) => boolean;
5
5
  export declare const findFirstFocusableItem: (items: ReactItem[]) => number;
6
6
  export declare const findLastFocusableItem: (items: ReactItem[]) => number;
7
+ export declare const checkChildrenForString: (children: React.ReactNode) => boolean;
7
8
  export {};
@@ -17,4 +17,12 @@ export const findLastFocusableItem = items => {
17
17
  }
18
18
  }
19
19
  return -1;
20
+ };
21
+ export const checkChildrenForString = children => {
22
+ return React.Children.toArray(children).some(child => {
23
+ if (typeof child === "string") {
24
+ return true;
25
+ }
26
+ return /*#__PURE__*/React.isValidElement(child) ? checkChildrenForString(child.props.children) : false;
27
+ });
20
28
  };
@@ -3,7 +3,7 @@ import { ButtonIconPosition, ButtonTypes, SizeOptions } from "../../button/butto
3
3
  import { IconType } from "../../icon";
4
4
  export declare type ActionPopoverMenuButtonAria = {
5
5
  "aria-haspopup": string;
6
- "aria-label": string;
6
+ "aria-label"?: string;
7
7
  "aria-labelledby"?: string;
8
8
  "aria-describedby"?: string;
9
9
  "aria-controls": string;
@@ -6,7 +6,7 @@ export interface RenderButtonProps {
6
6
  "data-element": string;
7
7
  ariaAttributes: {
8
8
  "aria-haspopup": string;
9
- "aria-label": string;
9
+ "aria-label"?: string;
10
10
  "aria-labelledby"?: string;
11
11
  "aria-describedby"?: string;
12
12
  "aria-controls": string;
@@ -12,7 +12,7 @@ import ActionPopoverItem from "./action-popover-item/action-popover-item.compone
12
12
  import ActionPopoverDivider from "./action-popover-divider/action-popover-divider.component";
13
13
  import ActionPopoverContext from "./__internal__/action-popover.context";
14
14
  import useModalManager from "../../hooks/__internal__/useModalManager";
15
- import { findFirstFocusableItem, findLastFocusableItem, getItems } from "./__internal__/action-popover-utils";
15
+ import { findFirstFocusableItem, findLastFocusableItem, getItems, checkChildrenForString } from "./__internal__/action-popover-utils";
16
16
  const onOpenDefault = () => {};
17
17
  const onCloseDefault = () => {};
18
18
  const ActionPopover = /*#__PURE__*/forwardRef(({
@@ -139,7 +139,7 @@ const ActionPopover = /*#__PURE__*/forwardRef(({
139
139
  }, [setOpen]);
140
140
  const menuButton = menuID => {
141
141
  if (renderButton) {
142
- return renderButton({
142
+ const renderButtonComponent = renderButton({
143
143
  tabIndex: isOpen ? -1 : 0,
144
144
  "data-element": "action-popover-button",
145
145
  ariaAttributes: {
@@ -151,6 +151,19 @@ const ActionPopover = /*#__PURE__*/forwardRef(({
151
151
  "aria-expanded": `${isOpen}`
152
152
  }
153
153
  });
154
+ const buttonHasString = checkChildrenForString(renderButtonComponent);
155
+ return renderButton({
156
+ tabIndex: isOpen ? -1 : 0,
157
+ "data-element": "action-popover-button",
158
+ ariaAttributes: {
159
+ "aria-haspopup": "true",
160
+ "aria-label": buttonHasString ? undefined : ariaLabel || l.actionPopover.ariaLabel(),
161
+ "aria-labelledby": ariaLabelledBy,
162
+ "aria-describedby": ariaDescribedBy,
163
+ "aria-controls": menuID,
164
+ "aria-expanded": `${isOpen}`
165
+ }
166
+ });
154
167
  }
155
168
  return /*#__PURE__*/React.createElement(StyledButtonIcon, {
156
169
  role: "button",
@@ -106,13 +106,6 @@ export const MenuItem = ({
106
106
  if (ref.current && Events.isEscKey(event)) {
107
107
  ref.current?.focus();
108
108
  }
109
- const inputIcon = ref.current?.querySelector("[data-element='input-icon-toggle']");
110
- const shouldFocusIcon = inputIcon?.getAttribute("tabindex") === "0" && document.activeElement === inputRef.current && inputRef.current?.value;
111
-
112
- // let natural tab order move focus if input icon is tabbable or input with button exists
113
- if (Events.isTabKey(event) && (!Events.isShiftKey(event) && shouldFocusIcon || Events.isShiftKey(event) && document.activeElement === inputIcon)) {
114
- return;
115
- }
116
109
  if (handleSubmenuKeyDown) {
117
110
  handleSubmenuKeyDown(event);
118
111
  }
@@ -10,6 +10,7 @@ import Textbox from "../textbox";
10
10
  import Button from "../button";
11
11
  import Logger from "../../__internal__/utils/logger";
12
12
  import useLocale from "../../hooks/__internal__/useLocale";
13
+ import Events from "../../__internal__/utils/helpers/events";
13
14
  let deprecateUncontrolledWarnTriggered = false;
14
15
  const Search = /*#__PURE__*/React.forwardRef(({
15
16
  defaultValue,
@@ -125,6 +126,21 @@ const Search = /*#__PURE__*/React.forwardRef(({
125
126
  if (event.key.length === 1) {
126
127
  event.stopPropagation();
127
128
  }
129
+ if (Events.isEscKey(event) && !isSearchValueEmpty) {
130
+ event.stopPropagation();
131
+ setSearchValue("");
132
+ onChange?.({
133
+ target: {
134
+ ...(name && {
135
+ name
136
+ }),
137
+ ...(id && {
138
+ id
139
+ }),
140
+ value: ""
141
+ }
142
+ });
143
+ }
128
144
  if (onKeyDown) {
129
145
  onKeyDown(event);
130
146
  }
@@ -11,7 +11,6 @@ export interface InputIconToggleProps extends InputIconToggleStyleProps, Validat
11
11
  onFocus?: (ev: React.FocusEvent<HTMLElement>) => void;
12
12
  onMouseDown?: (ev: React.MouseEvent<HTMLElement>) => void;
13
13
  readOnly?: boolean;
14
- tooltipId?: string;
15
14
  useValidationIcon?: boolean;
16
15
  /** Id of the validation icon */
17
16
  validationIconId?: string;
@@ -63,11 +63,12 @@ const InputIconToggle = ({
63
63
  onFocus: onFocus,
64
64
  onBlur: onBlur,
65
65
  onMouseDown: onMouseDown,
66
- tabIndex: iconTabIndex,
67
66
  "data-element": "input-icon-toggle",
68
67
  disabled: disabled,
69
68
  readOnly: readOnly,
70
- "data-role": "input-icon-toggle"
69
+ "data-role": "input-icon-toggle",
70
+ "aria-hidden": "true",
71
+ tabIndex: -1
71
72
  }, /*#__PURE__*/_react.default.createElement(_icon.default, {
72
73
  disabled: disabled || readOnly,
73
74
  type: type
@@ -4,4 +4,5 @@ export declare const getItems: (children: React.ReactNode | React.ReactNode[]) =
4
4
  export declare const isItemDisabled: (item: ReactItem) => boolean;
5
5
  export declare const findFirstFocusableItem: (items: ReactItem[]) => number;
6
6
  export declare const findLastFocusableItem: (items: ReactItem[]) => number;
7
+ export declare const checkChildrenForString: (children: React.ReactNode) => boolean;
7
8
  export {};
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.isItemDisabled = exports.getItems = exports.findLastFocusableItem = exports.findFirstFocusableItem = void 0;
6
+ exports.isItemDisabled = exports.getItems = exports.findLastFocusableItem = exports.findFirstFocusableItem = exports.checkChildrenForString = void 0;
7
7
  var _react = _interopRequireDefault(require("react"));
8
8
  var _actionPopoverItem = require("../action-popover-item/action-popover-item.component");
9
9
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
@@ -27,4 +27,13 @@ const findLastFocusableItem = items => {
27
27
  }
28
28
  return -1;
29
29
  };
30
- exports.findLastFocusableItem = findLastFocusableItem;
30
+ exports.findLastFocusableItem = findLastFocusableItem;
31
+ const checkChildrenForString = children => {
32
+ return _react.default.Children.toArray(children).some(child => {
33
+ if (typeof child === "string") {
34
+ return true;
35
+ }
36
+ return /*#__PURE__*/_react.default.isValidElement(child) ? checkChildrenForString(child.props.children) : false;
37
+ });
38
+ };
39
+ exports.checkChildrenForString = checkChildrenForString;
@@ -3,7 +3,7 @@ import { ButtonIconPosition, ButtonTypes, SizeOptions } from "../../button/butto
3
3
  import { IconType } from "../../icon";
4
4
  export declare type ActionPopoverMenuButtonAria = {
5
5
  "aria-haspopup": string;
6
- "aria-label": string;
6
+ "aria-label"?: string;
7
7
  "aria-labelledby"?: string;
8
8
  "aria-describedby"?: string;
9
9
  "aria-controls": string;
@@ -6,7 +6,7 @@ export interface RenderButtonProps {
6
6
  "data-element": string;
7
7
  ariaAttributes: {
8
8
  "aria-haspopup": string;
9
- "aria-label": string;
9
+ "aria-label"?: string;
10
10
  "aria-labelledby"?: string;
11
11
  "aria-describedby"?: string;
12
12
  "aria-controls": string;
@@ -148,7 +148,7 @@ const ActionPopover = exports.ActionPopover = /*#__PURE__*/(0, _react.forwardRef
148
148
  }, [setOpen]);
149
149
  const menuButton = menuID => {
150
150
  if (renderButton) {
151
- return renderButton({
151
+ const renderButtonComponent = renderButton({
152
152
  tabIndex: isOpen ? -1 : 0,
153
153
  "data-element": "action-popover-button",
154
154
  ariaAttributes: {
@@ -160,6 +160,19 @@ const ActionPopover = exports.ActionPopover = /*#__PURE__*/(0, _react.forwardRef
160
160
  "aria-expanded": `${isOpen}`
161
161
  }
162
162
  });
163
+ const buttonHasString = (0, _actionPopoverUtils.checkChildrenForString)(renderButtonComponent);
164
+ return renderButton({
165
+ tabIndex: isOpen ? -1 : 0,
166
+ "data-element": "action-popover-button",
167
+ ariaAttributes: {
168
+ "aria-haspopup": "true",
169
+ "aria-label": buttonHasString ? undefined : ariaLabel || l.actionPopover.ariaLabel(),
170
+ "aria-labelledby": ariaLabelledBy,
171
+ "aria-describedby": ariaDescribedBy,
172
+ "aria-controls": menuID,
173
+ "aria-expanded": `${isOpen}`
174
+ }
175
+ });
163
176
  }
164
177
  return /*#__PURE__*/_react.default.createElement(_actionPopover.StyledButtonIcon, {
165
178
  role: "button",
@@ -115,13 +115,6 @@ const MenuItem = ({
115
115
  if (ref.current && _events.default.isEscKey(event)) {
116
116
  ref.current?.focus();
117
117
  }
118
- const inputIcon = ref.current?.querySelector("[data-element='input-icon-toggle']");
119
- const shouldFocusIcon = inputIcon?.getAttribute("tabindex") === "0" && document.activeElement === inputRef.current && inputRef.current?.value;
120
-
121
- // let natural tab order move focus if input icon is tabbable or input with button exists
122
- if (_events.default.isTabKey(event) && (!_events.default.isShiftKey(event) && shouldFocusIcon || _events.default.isShiftKey(event) && document.activeElement === inputIcon)) {
123
- return;
124
- }
125
118
  if (handleSubmenuKeyDown) {
126
119
  handleSubmenuKeyDown(event);
127
120
  }
@@ -15,6 +15,7 @@ var _textbox = _interopRequireDefault(require("../textbox"));
15
15
  var _button = _interopRequireDefault(require("../button"));
16
16
  var _logger = _interopRequireDefault(require("../../__internal__/utils/logger"));
17
17
  var _useLocale = _interopRequireDefault(require("../../hooks/__internal__/useLocale"));
18
+ var _events = _interopRequireDefault(require("../../__internal__/utils/helpers/events"));
18
19
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
19
20
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
20
21
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
@@ -134,6 +135,21 @@ const Search = exports.Search = /*#__PURE__*/_react.default.forwardRef(({
134
135
  if (event.key.length === 1) {
135
136
  event.stopPropagation();
136
137
  }
138
+ if (_events.default.isEscKey(event) && !isSearchValueEmpty) {
139
+ event.stopPropagation();
140
+ setSearchValue("");
141
+ onChange?.({
142
+ target: {
143
+ ...(name && {
144
+ name
145
+ }),
146
+ ...(id && {
147
+ id
148
+ }),
149
+ value: ""
150
+ }
151
+ });
152
+ }
137
153
  if (onKeyDown) {
138
154
  onKeyDown(event);
139
155
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "carbon-react",
3
- "version": "147.3.0",
3
+ "version": "147.4.0",
4
4
  "description": "A library of reusable React components for easily building user interfaces.",
5
5
  "files": [
6
6
  "lib",