carbon-react 114.16.0 → 114.17.1

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.
Files changed (41) hide show
  1. package/esm/__internal__/focus-trap/focus-trap.component.d.ts +2 -2
  2. package/esm/__internal__/focus-trap/index.d.ts +1 -1
  3. package/esm/components/advanced-color-picker/advanced-color-picker-cell.style.d.ts +4 -0
  4. package/esm/components/advanced-color-picker/advanced-color-picker.component.d.ts +43 -0
  5. package/esm/components/advanced-color-picker/advanced-color-picker.component.js +203 -74
  6. package/esm/components/advanced-color-picker/advanced-color-picker.style.d.ts +6 -0
  7. package/esm/components/advanced-color-picker/index.d.ts +2 -1
  8. package/esm/components/alert/alert.component.js +11 -5
  9. package/esm/components/confirm/confirm.component.js +11 -5
  10. package/esm/components/dialog/dialog.component.d.ts +2 -4
  11. package/esm/components/dialog/dialog.component.js +11 -5
  12. package/esm/components/dialog-full-screen/dialog-full-screen.component.d.ts +3 -2
  13. package/esm/components/dialog-full-screen/dialog-full-screen.component.js +14 -8
  14. package/esm/components/menu/__internal__/submenu/submenu.component.js +5 -2
  15. package/esm/components/menu/menu-item/menu-item.component.js +3 -2
  16. package/esm/components/search/index.d.ts +1 -1
  17. package/esm/components/simple-color-picker/index.d.ts +1 -1
  18. package/esm/components/simple-color-picker/simple-color-picker.component.d.ts +5 -1
  19. package/esm/components/simple-color-picker/simple-color-picker.component.js +20 -15
  20. package/lib/__internal__/focus-trap/focus-trap.component.d.ts +2 -2
  21. package/lib/__internal__/focus-trap/index.d.ts +1 -1
  22. package/lib/components/advanced-color-picker/advanced-color-picker-cell.style.d.ts +4 -0
  23. package/lib/components/advanced-color-picker/advanced-color-picker.component.d.ts +43 -0
  24. package/lib/components/advanced-color-picker/advanced-color-picker.component.js +203 -76
  25. package/lib/components/advanced-color-picker/advanced-color-picker.style.d.ts +6 -0
  26. package/lib/components/advanced-color-picker/index.d.ts +2 -1
  27. package/lib/components/alert/alert.component.js +11 -5
  28. package/lib/components/confirm/confirm.component.js +11 -5
  29. package/lib/components/dialog/dialog.component.d.ts +2 -4
  30. package/lib/components/dialog/dialog.component.js +11 -5
  31. package/lib/components/dialog-full-screen/dialog-full-screen.component.d.ts +3 -2
  32. package/lib/components/dialog-full-screen/dialog-full-screen.component.js +14 -8
  33. package/lib/components/menu/__internal__/submenu/submenu.component.js +5 -2
  34. package/lib/components/menu/menu-item/menu-item.component.js +3 -2
  35. package/lib/components/search/index.d.ts +1 -1
  36. package/lib/components/simple-color-picker/index.d.ts +1 -1
  37. package/lib/components/simple-color-picker/simple-color-picker.component.d.ts +5 -1
  38. package/lib/components/simple-color-picker/simple-color-picker.component.js +19 -12
  39. package/package.json +1 -1
  40. package/esm/components/advanced-color-picker/advanced-color-picker.d.ts +0 -42
  41. package/lib/components/advanced-color-picker/advanced-color-picker.d.ts +0 -42
@@ -2,11 +2,9 @@ import React from "react";
2
2
  import { ModalProps } from "../modal";
3
3
  import { TagProps } from "../../__internal__/utils/helpers/tags/tags";
4
4
  import { DialogSizes } from "./dialog.config";
5
+ import { CustomRefObject } from "../../__internal__/focus-trap";
5
6
  declare const PADDING_VALUES: readonly [0, 1, 2, 3, 4, 5, 6, 7, 8];
6
7
  declare type PaddingValues = typeof PADDING_VALUES[number];
7
- declare type CustomRefObject<T> = {
8
- current?: T | null;
9
- };
10
8
  export interface ContentPaddingInterface {
11
9
  p?: PaddingValues;
12
10
  py?: PaddingValues;
@@ -37,7 +35,7 @@ export interface DialogProps extends ModalProps, TagProps {
37
35
  */
38
36
  bespokeFocusTrap?: (ev: KeyboardEvent, firstElement?: HTMLElement, lastElement?: HTMLElement) => void;
39
37
  /** Optional reference to an element meant to be focused on open */
40
- focusFirstElement?: React.MutableRefObject<HTMLElement | null>;
38
+ focusFirstElement?: CustomRefObject<HTMLElement> | HTMLElement | null;
41
39
  /** Optional selector to identify the focusable elements, if not provided a default selector is used */
42
40
  focusableSelectors?: string;
43
41
  /** Allows developers to specify a specific height for the dialog. */
@@ -248,15 +248,21 @@ Dialog.propTypes = {
248
248
  }
249
249
  })),
250
250
  "focusableSelectors": _propTypes.default.string,
251
- "focusFirstElement": _propTypes.default.shape({
252
- "current": _propTypes.default.oneOfType([_propTypes.default.oneOf([null]), function (props, propName) {
251
+ "focusFirstElement": _propTypes.default.oneOfType([function (props, propName) {
252
+ if (props[propName] == null) {
253
+ return new Error("Prop '" + propName + "' is required but wasn't specified");
254
+ } else if (typeof props[propName] !== 'object' || props[propName].nodeType !== 1) {
255
+ return new Error("Expected prop '" + propName + "' to be of type Element");
256
+ }
257
+ }, _propTypes.default.shape({
258
+ "current": function (props, propName) {
253
259
  if (props[propName] == null) {
254
- return new Error("Prop '" + propName + "' is required but wasn't specified");
260
+ return null;
255
261
  } else if (typeof props[propName] !== 'object' || props[propName].nodeType !== 1) {
256
262
  return new Error("Expected prop '" + propName + "' to be of type Element");
257
263
  }
258
- }]).isRequired
259
- }),
264
+ }
265
+ })]),
260
266
  "height": _propTypes.default.string,
261
267
  "help": _propTypes.default.string,
262
268
  "onCancel": _propTypes.default.func,
@@ -1,5 +1,6 @@
1
1
  import React from "react";
2
2
  import { ModalProps } from "../modal";
3
+ import { CustomRefObject } from "../../__internal__/focus-trap";
3
4
  export interface DialogFullScreenProps extends ModalProps {
4
5
  /** Prop to specify the aria-describedby property of the DialogFullscreen component */
5
6
  "aria-describedby"?: string;
@@ -23,7 +24,7 @@ export interface DialogFullScreenProps extends ModalProps {
23
24
  /** remove padding from content */
24
25
  disableContentPadding?: boolean;
25
26
  /** Optional reference to an element meant to be focused on open */
26
- focusFirstElement?: React.MutableRefObject<HTMLElement | null>;
27
+ focusFirstElement?: CustomRefObject<HTMLElement> | HTMLElement | null;
27
28
  /**
28
29
  * Function to replace focus trap
29
30
  * @ignore
@@ -45,7 +46,7 @@ export interface DialogFullScreenProps extends ModalProps {
45
46
  /** The ARIA role to be applied to the DialogFullscreen container */
46
47
  role?: string;
47
48
  /** an optional array of refs to containers whose content should also be reachable by tabbing from the dialog */
48
- focusableContainers?: React.MutableRefObject<HTMLElement | null>[];
49
+ focusableContainers?: CustomRefObject<HTMLElement>[];
49
50
  /** Optional selector to identify the focusable elements, if not provided a default selector is used */
50
51
  focusableSelectors?: string;
51
52
  /** A custom close event handler */
@@ -162,24 +162,30 @@ DialogFullScreen.propTypes = {
162
162
  "disableEscKey": _propTypes.default.bool,
163
163
  "enableBackgroundUI": _propTypes.default.bool,
164
164
  "focusableContainers": _propTypes.default.arrayOf(_propTypes.default.shape({
165
- "current": _propTypes.default.oneOfType([_propTypes.default.oneOf([null]), function (props, propName) {
165
+ "current": function (props, propName) {
166
166
  if (props[propName] == null) {
167
- return new Error("Prop '" + propName + "' is required but wasn't specified");
167
+ return null;
168
168
  } else if (typeof props[propName] !== 'object' || props[propName].nodeType !== 1) {
169
169
  return new Error("Expected prop '" + propName + "' to be of type Element");
170
170
  }
171
- }]).isRequired
171
+ }
172
172
  })),
173
173
  "focusableSelectors": _propTypes.default.string,
174
- "focusFirstElement": _propTypes.default.shape({
175
- "current": _propTypes.default.oneOfType([_propTypes.default.oneOf([null]), function (props, propName) {
174
+ "focusFirstElement": _propTypes.default.oneOfType([function (props, propName) {
175
+ if (props[propName] == null) {
176
+ return new Error("Prop '" + propName + "' is required but wasn't specified");
177
+ } else if (typeof props[propName] !== 'object' || props[propName].nodeType !== 1) {
178
+ return new Error("Expected prop '" + propName + "' to be of type Element");
179
+ }
180
+ }, _propTypes.default.shape({
181
+ "current": function (props, propName) {
176
182
  if (props[propName] == null) {
177
- return new Error("Prop '" + propName + "' is required but wasn't specified");
183
+ return null;
178
184
  } else if (typeof props[propName] !== 'object' || props[propName].nodeType !== 1) {
179
185
  return new Error("Expected prop '" + propName + "' to be of type Element");
180
186
  }
181
- }]).isRequired
182
- }),
187
+ }
188
+ })]),
183
189
  "headerChildren": _propTypes.default.node,
184
190
  "help": _propTypes.default.string,
185
191
  "onCancel": _propTypes.default.func,
@@ -68,6 +68,7 @@ const Submenu = /*#__PURE__*/_react.default.forwardRef(({
68
68
  const [submenuItemIds, setSubmenuItemIds] = (0, _react.useState)([]);
69
69
  const [characterString, setCharacterString] = (0, _react.useState)("");
70
70
  const shiftTabPressed = (0, _react.useRef)(false);
71
+ const focusFirstMenuItemOnOpen = (0, _react.useRef)(false);
71
72
  const registerItem = (0, _react.useCallback)(id => {
72
73
  setSubmenuItemIds(prevState => {
73
74
  return [...prevState, id];
@@ -134,6 +135,7 @@ const Submenu = /*#__PURE__*/_react.default.forwardRef(({
134
135
  if (_events.default.isEnterKey(event) || _events.default.isSpaceKey(event) || _events.default.isDownKey(event) || _events.default.isUpKey(event)) {
135
136
  event.preventDefault();
136
137
  openSubmenu();
138
+ focusFirstMenuItemOnOpen.current = !href;
137
139
  }
138
140
  }
139
141
 
@@ -237,10 +239,11 @@ const Submenu = /*#__PURE__*/_react.default.forwardRef(({
237
239
  }
238
240
  }, [submenuItemIds, submenuOpen, href, numberOfChildren, submenuFocusId, findCurrentIndex, openSubmenu, closeSubmenu, onKeyDown, characterString, restartCharacterTimeout, startCharacterTimeout]);
239
241
  (0, _react.useEffect)(() => {
240
- if (submenuOpen && !href && !submenuFocusId && submenuItemIds.length) {
242
+ if (focusFirstMenuItemOnOpen.current && submenuOpen && !submenuFocusId && submenuItemIds.length) {
243
+ focusFirstMenuItemOnOpen.current = false;
241
244
  setSubmenuFocusId(submenuItemIds[0]);
242
245
  }
243
- }, [submenuOpen, href, submenuFocusId, submenuItemIds]);
246
+ }, [submenuOpen, submenuFocusId, submenuItemIds]);
244
247
 
245
248
  const handleClickAway = () => {
246
249
  document.removeEventListener("click", handleClickAway);
@@ -147,7 +147,7 @@ const MenuItem = ({
147
147
  href,
148
148
  target,
149
149
  rel,
150
- onClick: onClick || (inputRef.current ? updateFocusOnClick : undefined),
150
+ onClick,
151
151
  icon,
152
152
  selected,
153
153
  variant,
@@ -196,7 +196,8 @@ const MenuItem = ({
196
196
  }, rest, {
197
197
  inFullscreenView: inFullscreenView && !Object.keys(submenuContext).length,
198
198
  menuOpen: menuOpen,
199
- id: menuItemId.current
199
+ id: menuItemId.current,
200
+ onClick: updateFocusOnClick
200
201
  }), /*#__PURE__*/_react.default.createElement(_menuItem.default, _extends({
201
202
  as: inputRef.current ? "div" : _link.default,
202
203
  isSearch: inputRef.current,
@@ -1,2 +1,2 @@
1
1
  export { default } from "./search.component";
2
- export type { SearchProps } from "./search.component";
2
+ export type { SearchProps, SearchEvent } from "./search.component";
@@ -1,4 +1,4 @@
1
1
  export { default as SimpleColorPicker } from "./simple-color-picker.component";
2
- export type { SimpleColorPickerProps } from "./simple-color-picker.component";
2
+ export type { SimpleColorPickerProps, SimpleColorPickerRef, } from "./simple-color-picker.component";
3
3
  export { default as SimpleColor } from "./simple-color";
4
4
  export type { SimpleColorProps } from "./simple-color";
@@ -27,5 +27,9 @@ export interface SimpleColorPickerProps extends ValidationProps, MarginProps {
27
27
  /** The currently selected color. */
28
28
  value?: string;
29
29
  }
30
- export declare const SimpleColorPicker: (props: SimpleColorPickerProps) => JSX.Element;
30
+ export interface SimpleColorPickerRef {
31
+ /** List of color input HTML refs */
32
+ gridItemRefs: (HTMLInputElement | null)[];
33
+ }
34
+ export declare const SimpleColorPicker: React.ForwardRefExoticComponent<SimpleColorPickerProps & React.RefAttributes<SimpleColorPickerRef>>;
31
35
  export default SimpleColorPicker;
@@ -37,7 +37,7 @@ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj;
37
37
 
38
38
  function _extends() { _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; }; return _extends.apply(this, arguments); }
39
39
 
40
- const SimpleColorPicker = props => {
40
+ const SimpleColorPicker = /*#__PURE__*/_react.default.forwardRef((props, ref) => {
41
41
  const {
42
42
  children,
43
43
  error,
@@ -77,7 +77,7 @@ const SimpleColorPicker = props => {
77
77
  let blankSlots = itemsPerRow * rowCount - (filteredChildren === null || filteredChildren === void 0 ? void 0 : filteredChildren.length);
78
78
  let currentRow = 1;
79
79
  let loopCounter = 1;
80
- const gridItemRefs = (0, _react.useMemo)(() => filteredChildren.map(child => child.ref || /*#__PURE__*/_react.default.createRef()), [filteredChildren]);
80
+ const gridItemRefs = (0, _react.useRef)([]);
81
81
  const navigationGrid = filteredChildren.map((child, index) => {
82
82
  const allowUp = currentRow !== 1;
83
83
  let allowDown = false;
@@ -107,7 +107,9 @@ const SimpleColorPicker = props => {
107
107
  }
108
108
 
109
109
  const childProps = {
110
- ref: gridItemRefs[index],
110
+ ref: element => {
111
+ gridItemRefs.current[index] = element;
112
+ },
111
113
  "data-up": allowUp,
112
114
  "data-down": allowDown,
113
115
  "data-item-up": upItem,
@@ -117,6 +119,14 @@ const SimpleColorPicker = props => {
117
119
  loopCounter += 1;
118
120
  return /*#__PURE__*/_react.default.cloneElement(child, childProps);
119
121
  });
122
+ (0, _react.useImperativeHandle)(ref, () => ({
123
+ gridItemRefs: gridItemRefs.current
124
+ }), [gridItemRefs]);
125
+ const getElementPosition = (0, _react.useCallback)(target => {
126
+ return navigationGrid.findIndex(element => {
127
+ return target.getAttribute("value") === element.props.value;
128
+ });
129
+ }, [navigationGrid]);
120
130
  const onKeyDownHandler = (0, _react.useCallback)(e => {
121
131
  if (onKeyDown) {
122
132
  onKeyDown(e);
@@ -137,14 +147,10 @@ const SimpleColorPicker = props => {
137
147
  }
138
148
 
139
149
  if (_events.default.isLeftKey(e) || _events.default.isRightKey(e)) {
140
- const position = element => {
141
- return target.getAttribute("value") === element.props.value;
142
- };
143
-
144
150
  if (_events.default.isLeftKey(e)) {
145
- itemIndex = navigationGrid.findIndex(position) - 1;
151
+ itemIndex = getElementPosition(target) - 1;
146
152
  } else {
147
- itemIndex = navigationGrid.findIndex(position) + 1;
153
+ itemIndex = getElementPosition(target) + 1;
148
154
  }
149
155
 
150
156
  if (itemIndex < 0) {
@@ -157,11 +163,11 @@ const SimpleColorPicker = props => {
157
163
 
158
164
 
159
165
  if (itemIndex !== null) {
160
- const item = gridItemRefs[itemIndex].current;
166
+ const item = gridItemRefs.current[itemIndex];
161
167
  item === null || item === void 0 ? void 0 : item.focus();
162
168
  item === null || item === void 0 ? void 0 : item.click();
163
169
  }
164
- }, [onKeyDown, navigationGrid, gridItemRefs]);
170
+ }, [onKeyDown, navigationGrid, getElementPosition]);
165
171
 
166
172
  const handleClickOutside = ev => {
167
173
  if (internalRef.current && ev.target && !internalRef.current.contains(ev.target)) {
@@ -229,7 +235,7 @@ const SimpleColorPicker = props => {
229
235
  }, navigationGrid))), !validationOnLegend && /*#__PURE__*/_react.default.createElement(_validationIcon.default, _extends({}, validationProps, {
230
236
  tooltipFlipOverrides: ["top", "bottom"]
231
237
  }))));
232
- };
238
+ });
233
239
 
234
240
  exports.SimpleColorPicker = SimpleColorPicker;
235
241
  SimpleColorPicker.propTypes = {
@@ -403,5 +409,6 @@ SimpleColorPicker.propTypes = {
403
409
  "value": _propTypes.default.string,
404
410
  "warning": _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.bool])
405
411
  };
412
+ SimpleColorPicker.displayName = "SimpleColorPicker";
406
413
  var _default = SimpleColorPicker;
407
414
  exports.default = _default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "carbon-react",
3
- "version": "114.16.0",
3
+ "version": "114.17.1",
4
4
  "description": "A library of reusable React components for easily building user interfaces.",
5
5
  "files": [
6
6
  "lib",
@@ -1,42 +0,0 @@
1
- import * as React from "react";
2
- import { MarginProps } from "styled-system";
3
-
4
- export interface AdvancedColor {
5
- label: string;
6
- value: string;
7
- }
8
-
9
- export interface AdvancedColorPickerPropTypes extends MarginProps {
10
- /** Prop to specify the aria-describedby property of the component */
11
- "aria-describedby"?: string;
12
- /** Prop to specify the aria-label of the component */
13
- "aria-label"?: string;
14
- /** Prop to specify the aria-labeledby property of the component */
15
- "aria-labelledby"?: string;
16
- /** Prop for `availableColors` containing array of objects of colors */
17
- availableColors: AdvancedColor[];
18
- /** Prop for `defaultColor` containing the default color for `uncontrolled` use */
19
- defaultColor: string;
20
- /** Specifies the name prop to be applied to each color in the group */
21
- name: string;
22
- /** Prop for `onBlur` event */
23
- onBlur?: (ev: React.FocusEvent<HTMLInputElement>) => void;
24
- /** Prop for `onChange` event */
25
- onChange?: (ev: React.ChangeEvent<HTMLElement>) => void;
26
- /** Prop for `onClose` event */
27
- onClose?: (ev: React.MouseEvent<HTMLElement>) => void;
28
- /** Prop for `onOpen` event */
29
- onOpen?: (ev: React.MouseEvent<HTMLElement>) => void;
30
- /** Prop for `open` status */
31
- open?: boolean;
32
- /** The ARIA role to be applied to the component container */
33
- role?: string;
34
- /** Prop for `selectedColor` containing pre-selected color for `controlled` use */
35
- selectedColor?: string;
36
- }
37
-
38
- declare function AdvancedColorPicker(
39
- props: AdvancedColorPickerPropTypes
40
- ): JSX.Element;
41
-
42
- export default AdvancedColorPicker;
@@ -1,42 +0,0 @@
1
- import * as React from "react";
2
- import { MarginProps } from "styled-system";
3
-
4
- export interface AdvancedColor {
5
- label: string;
6
- value: string;
7
- }
8
-
9
- export interface AdvancedColorPickerPropTypes extends MarginProps {
10
- /** Prop to specify the aria-describedby property of the component */
11
- "aria-describedby"?: string;
12
- /** Prop to specify the aria-label of the component */
13
- "aria-label"?: string;
14
- /** Prop to specify the aria-labeledby property of the component */
15
- "aria-labelledby"?: string;
16
- /** Prop for `availableColors` containing array of objects of colors */
17
- availableColors: AdvancedColor[];
18
- /** Prop for `defaultColor` containing the default color for `uncontrolled` use */
19
- defaultColor: string;
20
- /** Specifies the name prop to be applied to each color in the group */
21
- name: string;
22
- /** Prop for `onBlur` event */
23
- onBlur?: (ev: React.FocusEvent<HTMLInputElement>) => void;
24
- /** Prop for `onChange` event */
25
- onChange?: (ev: React.ChangeEvent<HTMLElement>) => void;
26
- /** Prop for `onClose` event */
27
- onClose?: (ev: React.MouseEvent<HTMLElement>) => void;
28
- /** Prop for `onOpen` event */
29
- onOpen?: (ev: React.MouseEvent<HTMLElement>) => void;
30
- /** Prop for `open` status */
31
- open?: boolean;
32
- /** The ARIA role to be applied to the component container */
33
- role?: string;
34
- /** Prop for `selectedColor` containing pre-selected color for `controlled` use */
35
- selectedColor?: string;
36
- }
37
-
38
- declare function AdvancedColorPicker(
39
- props: AdvancedColorPickerPropTypes
40
- ): JSX.Element;
41
-
42
- export default AdvancedColorPicker;