@carbon/react 1.80.0-rc.0 → 1.80.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.
- package/.playwright/INTERNAL_AVT_REPORT_DO_NOT_USE.json +822 -822
- package/es/components/ComposedModal/ComposedModal.js +16 -8
- package/es/components/InlineLoading/InlineLoading.js +10 -2
- package/es/components/Menu/MenuItem.d.ts +3 -3
- package/es/components/Menu/MenuItem.js +1 -1
- package/es/components/Modal/Modal.js +17 -5
- package/es/components/OverflowMenu/OverflowMenu.js +2 -2
- package/es/components/Tag/DismissibleTag.d.ts +1 -55
- package/es/components/Tag/DismissibleTag.js +6 -4
- package/es/components/Tag/OperationalTag.d.ts +1 -1
- package/es/components/Tag/SelectableTag.d.ts +1 -43
- package/es/components/Tag/SelectableTag.js +7 -5
- package/es/components/TreeView/TreeNode.d.ts +1 -1
- package/es/components/TreeView/TreeNode.js +11 -4
- package/es/components/TreeView/TreeView.d.ts +1 -1
- package/es/components/TreeView/TreeView.js +6 -6
- package/es/internal/ClickListener.d.ts +13 -0
- package/es/internal/ClickListener.js +33 -60
- package/es/internal/useControllableState.d.ts +34 -0
- package/es/internal/useControllableState.js +15 -30
- package/es/internal/useOutsideClick.d.ts +8 -0
- package/es/internal/useOutsideClick.js +9 -6
- package/lib/components/ComposedModal/ComposedModal.js +14 -6
- package/lib/components/InlineLoading/InlineLoading.js +10 -2
- package/lib/components/Menu/MenuItem.d.ts +3 -3
- package/lib/components/Menu/MenuItem.js +1 -1
- package/lib/components/Modal/Modal.js +15 -3
- package/lib/components/OverflowMenu/OverflowMenu.js +2 -2
- package/lib/components/Tag/DismissibleTag.d.ts +1 -55
- package/lib/components/Tag/DismissibleTag.js +5 -3
- package/lib/components/Tag/OperationalTag.d.ts +1 -1
- package/lib/components/Tag/SelectableTag.d.ts +1 -43
- package/lib/components/Tag/SelectableTag.js +6 -4
- package/lib/components/TreeView/TreeNode.d.ts +1 -1
- package/lib/components/TreeView/TreeNode.js +11 -4
- package/lib/components/TreeView/TreeView.d.ts +1 -1
- package/lib/components/TreeView/TreeView.js +6 -6
- package/lib/internal/ClickListener.d.ts +13 -0
- package/lib/internal/ClickListener.js +32 -64
- package/lib/internal/useControllableState.d.ts +34 -0
- package/lib/internal/useControllableState.js +15 -30
- package/lib/internal/useOutsideClick.d.ts +8 -0
- package/lib/internal/useOutsideClick.js +9 -6
- package/package.json +8 -7
|
@@ -17,14 +17,15 @@ import mergeRefs from '../../tools/mergeRefs.js';
|
|
|
17
17
|
import cx from 'classnames';
|
|
18
18
|
import toggleClass from '../../tools/toggleClass.js';
|
|
19
19
|
import requiredIfGivenPropIsTruthy from '../../prop-types/requiredIfGivenPropIsTruthy.js';
|
|
20
|
-
import wrapFocus, { elementOrParentIsFloatingMenu } from '../../internal/wrapFocus.js';
|
|
20
|
+
import wrapFocus, { wrapFocusWithoutSentinels, elementOrParentIsFloatingMenu } from '../../internal/wrapFocus.js';
|
|
21
21
|
import { usePrefix } from '../../internal/usePrefix.js';
|
|
22
|
-
import { Escape } from '../../internal/keyboard/keys.js';
|
|
22
|
+
import { Escape, Tab } from '../../internal/keyboard/keys.js';
|
|
23
23
|
import { match } from '../../internal/keyboard/match.js';
|
|
24
24
|
import { useFeatureFlag } from '../FeatureFlags/index.js';
|
|
25
25
|
import { composeEventHandlers } from '../../tools/events.js';
|
|
26
26
|
import deprecate from '../../prop-types/deprecate.js';
|
|
27
27
|
import { unstable__Dialog } from '../Dialog/index.js';
|
|
28
|
+
import { warning } from '../../internal/warning.js';
|
|
28
29
|
import { debounce } from '../../node_modules/es-toolkit/dist/compat/function/debounce.mjs.js';
|
|
29
30
|
|
|
30
31
|
const ModalBody = /*#__PURE__*/React__default.forwardRef(function ModalBody(_ref, ref) {
|
|
@@ -121,9 +122,9 @@ const ComposedModal = /*#__PURE__*/React__default.forwardRef(function ComposedMo
|
|
|
121
122
|
const startSentinel = useRef(null);
|
|
122
123
|
const endSentinel = useRef(null);
|
|
123
124
|
const onMouseDownTarget = useRef(null);
|
|
124
|
-
const enableDialogElement =
|
|
125
|
-
|
|
126
|
-
|
|
125
|
+
const enableDialogElement = useFeatureFlag('enable-dialog-element');
|
|
126
|
+
const focusTrapWithoutSentinels = useFeatureFlag('enable-experimental-focus-wrap-without-sentinels');
|
|
127
|
+
process.env.NODE_ENV !== "production" ? warning(!(focusTrapWithoutSentinels && enableDialogElement), '`<Modal>` detected both `focusTrapWithoutSentinels` and ' + '`enableDialogElement` feature flags are enabled. The native dialog ' + 'element handles focus, so `enableDialogElement` must be off for ' + '`focusTrapWithoutSentinels` to have any effect.') : void 0;
|
|
127
128
|
|
|
128
129
|
// Keep track of modal open/close state
|
|
129
130
|
// and propagate it to the document.body
|
|
@@ -149,6 +150,13 @@ const ComposedModal = /*#__PURE__*/React__default.forwardRef(function ComposedMo
|
|
|
149
150
|
if (match(event, Escape)) {
|
|
150
151
|
closeModal(event);
|
|
151
152
|
}
|
|
153
|
+
if (focusTrapWithoutSentinels && open && match(event, Tab) && innerModal.current) {
|
|
154
|
+
wrapFocusWithoutSentinels({
|
|
155
|
+
containerNode: innerModal.current,
|
|
156
|
+
currentActiveNode: event.target,
|
|
157
|
+
event: event
|
|
158
|
+
});
|
|
159
|
+
}
|
|
152
160
|
}
|
|
153
161
|
onKeyDown?.(event);
|
|
154
162
|
}
|
|
@@ -283,7 +291,7 @@ const ComposedModal = /*#__PURE__*/React__default.forwardRef(function ComposedMo
|
|
|
283
291
|
"aria-modal": "true",
|
|
284
292
|
"aria-label": ariaLabel ? ariaLabel : generatedAriaLabel,
|
|
285
293
|
"aria-labelledby": ariaLabelledBy
|
|
286
|
-
}, /*#__PURE__*/React__default.createElement("button", {
|
|
294
|
+
}, !focusTrapWithoutSentinels && /*#__PURE__*/React__default.createElement("button", {
|
|
287
295
|
type: "button",
|
|
288
296
|
ref: startSentinel,
|
|
289
297
|
className: `${prefix}--visually-hidden`
|
|
@@ -292,7 +300,7 @@ const ComposedModal = /*#__PURE__*/React__default.forwardRef(function ComposedMo
|
|
|
292
300
|
className: `${prefix}--modal-container-body`
|
|
293
301
|
}, slug ? normalizedDecorator : decorator ? /*#__PURE__*/React__default.createElement("div", {
|
|
294
302
|
className: `${prefix}--modal--inner__decorator`
|
|
295
|
-
}, normalizedDecorator) : '', childrenWithProps), /*#__PURE__*/React__default.createElement("button", {
|
|
303
|
+
}, normalizedDecorator) : '', childrenWithProps), !focusTrapWithoutSentinels && /*#__PURE__*/React__default.createElement("button", {
|
|
296
304
|
type: "button",
|
|
297
305
|
ref: endSentinel,
|
|
298
306
|
className: `${prefix}--visually-hidden`
|
|
@@ -302,7 +310,7 @@ const ComposedModal = /*#__PURE__*/React__default.forwardRef(function ComposedMo
|
|
|
302
310
|
role: "presentation",
|
|
303
311
|
ref: ref,
|
|
304
312
|
"aria-hidden": !open,
|
|
305
|
-
onBlur: !enableDialogElement ? handleBlur : () => {},
|
|
313
|
+
onBlur: !enableDialogElement && !focusTrapWithoutSentinels ? handleBlur : () => {},
|
|
306
314
|
onClick: composeEventHandlers([rest?.onClick, handleOnClick]),
|
|
307
315
|
onMouseDown: composeEventHandlers([rest?.onMouseDown, handleOnMouseDown]),
|
|
308
316
|
onKeyDown: handleKeyDown,
|
|
@@ -53,9 +53,9 @@ const InlineLoading = _ref => {
|
|
|
53
53
|
className: `${prefix}--inline-loading__checkmark-container`
|
|
54
54
|
}, /*#__PURE__*/React__default.createElement("title", null, iconLabel));
|
|
55
55
|
}
|
|
56
|
-
if (status === '
|
|
56
|
+
if (status === 'active') {
|
|
57
57
|
if (!iconDescription) {
|
|
58
|
-
iconLabel =
|
|
58
|
+
iconLabel = 'loading';
|
|
59
59
|
}
|
|
60
60
|
return /*#__PURE__*/React__default.createElement(Loading, {
|
|
61
61
|
small: true,
|
|
@@ -64,6 +64,14 @@ const InlineLoading = _ref => {
|
|
|
64
64
|
active: status === 'active'
|
|
65
65
|
});
|
|
66
66
|
}
|
|
67
|
+
if (status === 'inactive') {
|
|
68
|
+
if (!iconDescription) {
|
|
69
|
+
iconLabel = 'not loading';
|
|
70
|
+
}
|
|
71
|
+
return /*#__PURE__*/React__default.createElement("title", {
|
|
72
|
+
className: `${prefix}--inline-loading__inactive-status`
|
|
73
|
+
}, iconLabel);
|
|
74
|
+
}
|
|
67
75
|
return undefined;
|
|
68
76
|
};
|
|
69
77
|
const loadingText = description && /*#__PURE__*/React__default.createElement("div", {
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* This source code is licensed under the Apache-2.0 license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
import React, {
|
|
7
|
+
import React, { ComponentProps, FC, KeyboardEvent, LiHTMLAttributes, MouseEvent, ReactNode } from 'react';
|
|
8
8
|
export interface MenuItemProps extends LiHTMLAttributes<HTMLLIElement> {
|
|
9
9
|
/**
|
|
10
10
|
* Optionally provide another Menu to create a submenu. props.children can't be used to specify the content of the MenuItem itself. Use props.label instead.
|
|
@@ -48,7 +48,7 @@ export interface MenuItemSelectableProps extends Omit<MenuItemProps, 'onChange'>
|
|
|
48
48
|
/**
|
|
49
49
|
* Provide an optional function to be called when the selection state changes.
|
|
50
50
|
*/
|
|
51
|
-
onChange?:
|
|
51
|
+
onChange?: (checked: boolean) => void;
|
|
52
52
|
/**
|
|
53
53
|
* Controls the state of this option.
|
|
54
54
|
*/
|
|
@@ -94,7 +94,7 @@ export interface MenuItemRadioGroupProps<Item> extends Omit<ComponentProps<'ul'>
|
|
|
94
94
|
/**
|
|
95
95
|
* Provide an optional function to be called when the selection changes.
|
|
96
96
|
*/
|
|
97
|
-
onChange?:
|
|
97
|
+
onChange?: (selectedItem: Item) => void;
|
|
98
98
|
/**
|
|
99
99
|
* Provide props.selectedItem to control the state of this radio group. Must match the type of props.items.
|
|
100
100
|
*/
|
|
@@ -333,7 +333,7 @@ const MenuItemRadioGroup = /*#__PURE__*/forwardRef(function MenuItemRadioGroup(_
|
|
|
333
333
|
const [selection, setSelection] = useControllableState({
|
|
334
334
|
value: selectedItem,
|
|
335
335
|
onChange,
|
|
336
|
-
defaultValue: defaultSelectedItem
|
|
336
|
+
defaultValue: defaultSelectedItem ?? {}
|
|
337
337
|
});
|
|
338
338
|
function handleClick(item, e) {
|
|
339
339
|
setSelection(item);
|
|
@@ -17,11 +17,11 @@ import ButtonSet from '../ButtonSet/ButtonSet.js';
|
|
|
17
17
|
import InlineLoading from '../InlineLoading/InlineLoading.js';
|
|
18
18
|
import { Layer } from '../Layer/index.js';
|
|
19
19
|
import requiredIfGivenPropIsTruthy from '../../prop-types/requiredIfGivenPropIsTruthy.js';
|
|
20
|
-
import wrapFocus, { elementOrParentIsFloatingMenu } from '../../internal/wrapFocus.js';
|
|
20
|
+
import wrapFocus, { wrapFocusWithoutSentinels, elementOrParentIsFloatingMenu } from '../../internal/wrapFocus.js';
|
|
21
21
|
import useIsomorphicEffect from '../../internal/useIsomorphicEffect.js';
|
|
22
22
|
import { useId } from '../../internal/useId.js';
|
|
23
23
|
import { usePrefix } from '../../internal/usePrefix.js';
|
|
24
|
-
import { Escape, Enter } from '../../internal/keyboard/keys.js';
|
|
24
|
+
import { Escape, Enter, Tab } from '../../internal/keyboard/keys.js';
|
|
25
25
|
import { match } from '../../internal/keyboard/match.js';
|
|
26
26
|
import { IconButton } from '../IconButton/index.js';
|
|
27
27
|
import { noopFn } from '../../internal/noopFn.js';
|
|
@@ -30,6 +30,7 @@ import { useFeatureFlag } from '../FeatureFlags/index.js';
|
|
|
30
30
|
import { composeEventHandlers } from '../../tools/events.js';
|
|
31
31
|
import deprecate from '../../prop-types/deprecate.js';
|
|
32
32
|
import { unstable__Dialog } from '../Dialog/index.js';
|
|
33
|
+
import { warning } from '../../internal/warning.js';
|
|
33
34
|
import { debounce } from '../../node_modules/es-toolkit/dist/compat/function/debounce.mjs.js';
|
|
34
35
|
import { Text } from '../Text/Text.js';
|
|
35
36
|
|
|
@@ -87,7 +88,9 @@ const Modal = /*#__PURE__*/React__default.forwardRef(function Modal(_ref, ref) {
|
|
|
87
88
|
[`${prefix}--btn--loading`]: loadingStatus !== 'inactive'
|
|
88
89
|
});
|
|
89
90
|
const loadingActive = loadingStatus !== 'inactive';
|
|
90
|
-
const
|
|
91
|
+
const focusTrapWithoutSentinels = useFeatureFlag('enable-experimental-focus-wrap-without-sentinels');
|
|
92
|
+
const enableDialogElement = useFeatureFlag('enable-dialog-element');
|
|
93
|
+
process.env.NODE_ENV !== "production" ? warning(!(focusTrapWithoutSentinels && enableDialogElement), '`<Modal>` detected both `focusTrapWithoutSentinels` and ' + '`enableDialogElement` feature flags are enabled. The native dialog ' + 'element handles focus, so `enableDialogElement` must be off for ' + '`focusTrapWithoutSentinels` to have any effect.') : void 0;
|
|
91
94
|
function isCloseButton(element) {
|
|
92
95
|
return !onSecondarySubmit && element === secondaryButton.current || element.classList.contains(modalCloseButtonClass);
|
|
93
96
|
}
|
|
@@ -100,6 +103,15 @@ const Modal = /*#__PURE__*/React__default.forwardRef(function Modal(_ref, ref) {
|
|
|
100
103
|
if (match(evt, Enter) && shouldSubmitOnEnter && !isCloseButton(evt.target)) {
|
|
101
104
|
onRequestSubmit(evt);
|
|
102
105
|
}
|
|
106
|
+
if (focusTrapWithoutSentinels && !enableDialogElement && match(evt, Tab) && innerModal.current) {
|
|
107
|
+
wrapFocusWithoutSentinels({
|
|
108
|
+
containerNode: innerModal.current,
|
|
109
|
+
currentActiveNode: evt.target,
|
|
110
|
+
// TODO: Delete type assertion following util rewrite.
|
|
111
|
+
// https://github.com/carbon-design-system/carbon/pull/18913
|
|
112
|
+
event: evt
|
|
113
|
+
});
|
|
114
|
+
}
|
|
103
115
|
}
|
|
104
116
|
}
|
|
105
117
|
function handleOnClick(evt) {
|
|
@@ -326,7 +338,7 @@ const Modal = /*#__PURE__*/React__default.forwardRef(function Modal(_ref, ref) {
|
|
|
326
338
|
iconDescription: loadingIconDescription,
|
|
327
339
|
className: `${prefix}--inline-loading--btn`,
|
|
328
340
|
onSuccess: onLoadingSuccess
|
|
329
|
-
})))) : /*#__PURE__*/React__default.createElement(React__default.Fragment, null, !enableDialogElement && /*#__PURE__*/React__default.createElement("span", {
|
|
341
|
+
})))) : /*#__PURE__*/React__default.createElement(React__default.Fragment, null, !enableDialogElement && !focusTrapWithoutSentinels && /*#__PURE__*/React__default.createElement("span", {
|
|
330
342
|
ref: startTrap,
|
|
331
343
|
tabIndex: 0,
|
|
332
344
|
role: "link",
|
|
@@ -385,7 +397,7 @@ const Modal = /*#__PURE__*/React__default.forwardRef(function Modal(_ref, ref) {
|
|
|
385
397
|
iconDescription: loadingIconDescription,
|
|
386
398
|
className: `${prefix}--inline-loading--btn`,
|
|
387
399
|
onSuccess: onLoadingSuccess
|
|
388
|
-
})))), !enableDialogElement && /*#__PURE__*/React__default.createElement("span", {
|
|
400
|
+
})))), !enableDialogElement && !focusTrapWithoutSentinels && /*#__PURE__*/React__default.createElement("span", {
|
|
389
401
|
ref: endTrap,
|
|
390
402
|
tabIndex: 0,
|
|
391
403
|
role: "link",
|
|
@@ -11,7 +11,7 @@ import { OverflowMenuVertical } from '@carbon/icons-react';
|
|
|
11
11
|
import cx from 'classnames';
|
|
12
12
|
import invariant from 'invariant';
|
|
13
13
|
import PropTypes from 'prop-types';
|
|
14
|
-
import ClickListener from '../../internal/ClickListener.js';
|
|
14
|
+
import { ClickListener } from '../../internal/ClickListener.js';
|
|
15
15
|
import { DIRECTION_TOP, DIRECTION_BOTTOM, FloatingMenu } from '../../internal/FloatingMenu.js';
|
|
16
16
|
import { ArrowUp, ArrowRight, ArrowDown, ArrowLeft, Escape } from '../../internal/keyboard/keys.js';
|
|
17
17
|
import { matches } from '../../internal/keyboard/match.js';
|
|
@@ -201,7 +201,7 @@ const OverflowMenu = /*#__PURE__*/forwardRef((_ref, ref) => {
|
|
|
201
201
|
}
|
|
202
202
|
};
|
|
203
203
|
const handleClickOutside = evt => {
|
|
204
|
-
if (open && (!menuBodyRef.current || !menuBodyRef.current.contains(evt.target))) {
|
|
204
|
+
if (open && (!menuBodyRef.current || evt.target instanceof Node && !menuBodyRef.current.contains(evt.target))) {
|
|
205
205
|
closeMenu();
|
|
206
206
|
}
|
|
207
207
|
};
|
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
* This source code is licensed under the Apache-2.0 license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
import PropTypes from 'prop-types';
|
|
8
7
|
import React, { ReactNode } from 'react';
|
|
9
8
|
import { PolymorphicProps } from '../../types/common';
|
|
10
9
|
import { SIZES, TYPES } from './Tag';
|
|
@@ -61,59 +60,6 @@ export interface DismissibleTagBaseProps {
|
|
|
61
60
|
type?: keyof typeof TYPES;
|
|
62
61
|
}
|
|
63
62
|
export type DismissibleTagProps<T extends React.ElementType> = PolymorphicProps<T, DismissibleTagBaseProps>;
|
|
64
|
-
declare const DismissibleTag:
|
|
65
|
-
<T extends React.ElementType>({ className, decorator, disabled, id, renderIcon, title, onClose, slug, size, text, tagTitle, type, ...other }: DismissibleTagProps<T>): import("react/jsx-runtime").JSX.Element;
|
|
66
|
-
propTypes: {
|
|
67
|
-
/**
|
|
68
|
-
* Provide a custom className that is applied to the containing <span>
|
|
69
|
-
*/
|
|
70
|
-
className: PropTypes.Requireable<string>;
|
|
71
|
-
/**
|
|
72
|
-
* **Experimental:** Provide a `decorator` component to be rendered inside the `DismissibleTag` component
|
|
73
|
-
*/
|
|
74
|
-
decorator: PropTypes.Requireable<PropTypes.ReactNodeLike>;
|
|
75
|
-
/**
|
|
76
|
-
* Specify if the `DismissibleTag` is disabled
|
|
77
|
-
*/
|
|
78
|
-
disabled: PropTypes.Requireable<boolean>;
|
|
79
|
-
/**
|
|
80
|
-
* Specify the id for the tag.
|
|
81
|
-
*/
|
|
82
|
-
id: PropTypes.Requireable<string>;
|
|
83
|
-
/**
|
|
84
|
-
* Click handler for filter tag close button.
|
|
85
|
-
*/
|
|
86
|
-
onClose: PropTypes.Requireable<(...args: any[]) => any>;
|
|
87
|
-
/**
|
|
88
|
-
* A component used to render an icon.
|
|
89
|
-
*/
|
|
90
|
-
renderIcon: PropTypes.Requireable<object>;
|
|
91
|
-
/**
|
|
92
|
-
* Specify the size of the Tag. Currently supports either `sm`,
|
|
93
|
-
* `md` (default) or `lg` sizes.
|
|
94
|
-
*/
|
|
95
|
-
size: PropTypes.Requireable<string>;
|
|
96
|
-
/**
|
|
97
|
-
* **Experimental:** Provide a `Slug` component to be rendered inside the `DismissibleTag` component
|
|
98
|
-
*/
|
|
99
|
-
slug: (props: any, propName: any, componentName: any, ...rest: any[]) => any;
|
|
100
|
-
/**
|
|
101
|
-
* Provide text to be rendered inside of a the tag.
|
|
102
|
-
*/
|
|
103
|
-
text: PropTypes.Requireable<string>;
|
|
104
|
-
/**
|
|
105
|
-
* Provide a custom `title` to be inserted in the tag.
|
|
106
|
-
*/
|
|
107
|
-
tagTitle: PropTypes.Requireable<string>;
|
|
108
|
-
/**
|
|
109
|
-
* Text to show on clear filters
|
|
110
|
-
*/
|
|
111
|
-
title: PropTypes.Requireable<string>;
|
|
112
|
-
/**
|
|
113
|
-
* Specify the type of the `Tag`
|
|
114
|
-
*/
|
|
115
|
-
type: PropTypes.Requireable<string>;
|
|
116
|
-
};
|
|
117
|
-
};
|
|
63
|
+
declare const DismissibleTag: React.ForwardRefExoticComponent<Omit<DismissibleTagProps<React.ElementType<any, keyof React.JSX.IntrinsicElements>>, "ref"> & React.RefAttributes<HTMLDivElement>>;
|
|
118
64
|
export declare const types: string[];
|
|
119
65
|
export default DismissibleTag;
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
|
|
8
8
|
import { extends as _extends } from '../../_virtual/_rollupPluginBabelHelpers.js';
|
|
9
9
|
import PropTypes from 'prop-types';
|
|
10
|
-
import React__default, { useRef, useState, useLayoutEffect } from 'react';
|
|
10
|
+
import React__default, { forwardRef, useRef, useState, useLayoutEffect } from 'react';
|
|
11
11
|
import cx from 'classnames';
|
|
12
12
|
import { useId } from '../../internal/useId.js';
|
|
13
13
|
import { usePrefix } from '../../internal/usePrefix.js';
|
|
@@ -18,10 +18,11 @@ import '../Tooltip/DefinitionTooltip.js';
|
|
|
18
18
|
import { Tooltip } from '../Tooltip/Tooltip.js';
|
|
19
19
|
import '../Text/index.js';
|
|
20
20
|
import { isEllipsisActive } from './isEllipsisActive.js';
|
|
21
|
+
import mergeRefs from '../../tools/mergeRefs.js';
|
|
21
22
|
import { Text } from '../Text/Text.js';
|
|
22
23
|
|
|
23
24
|
var _Close;
|
|
24
|
-
const DismissibleTag = _ref => {
|
|
25
|
+
const DismissibleTag = /*#__PURE__*/forwardRef((_ref, forwardRef) => {
|
|
25
26
|
let {
|
|
26
27
|
className,
|
|
27
28
|
decorator,
|
|
@@ -46,6 +47,7 @@ const DismissibleTag = _ref => {
|
|
|
46
47
|
const newElement = tagLabelRef.current?.getElementsByClassName(`${prefix}--tag__label`)[0];
|
|
47
48
|
setIsEllipsisApplied(isEllipsisActive(newElement));
|
|
48
49
|
}, [prefix, tagLabelRef]);
|
|
50
|
+
const combinedRef = mergeRefs(tagLabelRef, forwardRef);
|
|
49
51
|
const handleClose = event => {
|
|
50
52
|
if (onClose) {
|
|
51
53
|
event.stopPropagation();
|
|
@@ -69,7 +71,7 @@ const DismissibleTag = _ref => {
|
|
|
69
71
|
} = other;
|
|
70
72
|
const dismissLabel = `Dismiss "${text}"`;
|
|
71
73
|
return /*#__PURE__*/React__default.createElement(Tag, _extends({
|
|
72
|
-
ref:
|
|
74
|
+
ref: combinedRef,
|
|
73
75
|
type: type,
|
|
74
76
|
size: size,
|
|
75
77
|
renderIcon: renderIcon,
|
|
@@ -96,7 +98,7 @@ const DismissibleTag = _ref => {
|
|
|
96
98
|
disabled: disabled,
|
|
97
99
|
"aria-label": title
|
|
98
100
|
}, _Close || (_Close = /*#__PURE__*/React__default.createElement(Close, null))))));
|
|
99
|
-
};
|
|
101
|
+
});
|
|
100
102
|
DismissibleTag.propTypes = {
|
|
101
103
|
/**
|
|
102
104
|
* Provide a custom className that is applied to the containing <span>
|
|
@@ -52,6 +52,6 @@ export interface OperationalTagBaseProps {
|
|
|
52
52
|
type?: keyof typeof TYPES;
|
|
53
53
|
}
|
|
54
54
|
export type OperationalTagProps<T extends React.ElementType> = PolymorphicProps<T, OperationalTagBaseProps>;
|
|
55
|
-
declare const OperationalTag: React.ForwardRefExoticComponent<Omit<OperationalTagProps<React.ElementType<any, keyof React.JSX.IntrinsicElements>>, "ref"> & React.RefAttributes<
|
|
55
|
+
declare const OperationalTag: React.ForwardRefExoticComponent<Omit<OperationalTagProps<React.ElementType<any, keyof React.JSX.IntrinsicElements>>, "ref"> & React.RefAttributes<HTMLButtonElement>>;
|
|
56
56
|
export declare const types: string[];
|
|
57
57
|
export default OperationalTag;
|
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
* This source code is licensed under the Apache-2.0 license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
import PropTypes from 'prop-types';
|
|
8
7
|
import React, { MouseEvent } from 'react';
|
|
9
8
|
import { PolymorphicProps } from '../../types/common';
|
|
10
9
|
import { SIZES } from './Tag';
|
|
@@ -48,46 +47,5 @@ export interface SelectableTagBaseProps {
|
|
|
48
47
|
text?: string;
|
|
49
48
|
}
|
|
50
49
|
export type SelectableTagProps<T extends React.ElementType> = PolymorphicProps<T, SelectableTagBaseProps>;
|
|
51
|
-
declare const SelectableTag:
|
|
52
|
-
<T extends React.ElementType>({ className, disabled, id, renderIcon, onChange, onClick, selected, size, text, ...other }: SelectableTagProps<T>): import("react/jsx-runtime").JSX.Element;
|
|
53
|
-
propTypes: {
|
|
54
|
-
/**
|
|
55
|
-
* Provide a custom className that is applied to the containing <span>
|
|
56
|
-
*/
|
|
57
|
-
className: PropTypes.Requireable<string>;
|
|
58
|
-
/**
|
|
59
|
-
* Specify if the `SelectableTag` is disabled
|
|
60
|
-
*/
|
|
61
|
-
disabled: PropTypes.Requireable<boolean>;
|
|
62
|
-
/**
|
|
63
|
-
* Specify the id for the tag.
|
|
64
|
-
*/
|
|
65
|
-
id: PropTypes.Requireable<string>;
|
|
66
|
-
/**
|
|
67
|
-
* A component used to render an icon.
|
|
68
|
-
*/
|
|
69
|
-
renderIcon: PropTypes.Requireable<object>;
|
|
70
|
-
/**
|
|
71
|
-
* Provide an optional hook that is called when selected is changed
|
|
72
|
-
*/
|
|
73
|
-
onChange: PropTypes.Requireable<(...args: any[]) => any>;
|
|
74
|
-
/**
|
|
75
|
-
* Provide an optional function to be called when the tag is clicked.
|
|
76
|
-
*/
|
|
77
|
-
onClick: PropTypes.Requireable<(...args: any[]) => any>;
|
|
78
|
-
/**
|
|
79
|
-
* Specify the state of the selectable tag.
|
|
80
|
-
*/
|
|
81
|
-
selected: PropTypes.Requireable<boolean>;
|
|
82
|
-
/**
|
|
83
|
-
* Specify the size of the Tag. Currently supports either `sm`,
|
|
84
|
-
* `md` (default) or `lg` sizes.
|
|
85
|
-
*/
|
|
86
|
-
size: PropTypes.Requireable<string>;
|
|
87
|
-
/**
|
|
88
|
-
* Provide text to be rendered inside of a the tag.
|
|
89
|
-
*/
|
|
90
|
-
text: PropTypes.Requireable<string>;
|
|
91
|
-
};
|
|
92
|
-
};
|
|
50
|
+
declare const SelectableTag: React.ForwardRefExoticComponent<Omit<SelectableTagProps<React.ElementType<any, keyof React.JSX.IntrinsicElements>>, "ref"> & React.RefAttributes<HTMLButtonElement>>;
|
|
93
51
|
export default SelectableTag;
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
|
|
8
8
|
import { extends as _extends } from '../../_virtual/_rollupPluginBabelHelpers.js';
|
|
9
9
|
import PropTypes from 'prop-types';
|
|
10
|
-
import React__default, { useRef, useState, useLayoutEffect } from 'react';
|
|
10
|
+
import React__default, { forwardRef, useRef, useState, useLayoutEffect } from 'react';
|
|
11
11
|
import cx from 'classnames';
|
|
12
12
|
import { useId } from '../../internal/useId.js';
|
|
13
13
|
import { usePrefix } from '../../internal/usePrefix.js';
|
|
@@ -16,9 +16,10 @@ import '../Tooltip/DefinitionTooltip.js';
|
|
|
16
16
|
import { Tooltip } from '../Tooltip/Tooltip.js';
|
|
17
17
|
import '../Text/index.js';
|
|
18
18
|
import { isEllipsisActive } from './isEllipsisActive.js';
|
|
19
|
+
import mergeRefs from '../../tools/mergeRefs.js';
|
|
19
20
|
import { Text } from '../Text/Text.js';
|
|
20
21
|
|
|
21
|
-
const SelectableTag = _ref => {
|
|
22
|
+
const SelectableTag = /*#__PURE__*/forwardRef((_ref, forwardRef) => {
|
|
22
23
|
let {
|
|
23
24
|
className,
|
|
24
25
|
disabled,
|
|
@@ -44,6 +45,7 @@ const SelectableTag = _ref => {
|
|
|
44
45
|
setIsEllipsisApplied(isEllipsisActive(newElement));
|
|
45
46
|
}, [prefix, tagRef]);
|
|
46
47
|
const tooltipClasses = cx(`${prefix}--icon-tooltip`, `${prefix}--tag-label-tooltip`);
|
|
48
|
+
const combinedRef = mergeRefs(tagRef, forwardRef);
|
|
47
49
|
const handleClick = e => {
|
|
48
50
|
setSelectedTag(!selectedTag);
|
|
49
51
|
onChange?.(!selectedTag);
|
|
@@ -58,7 +60,7 @@ const SelectableTag = _ref => {
|
|
|
58
60
|
onMouseEnter: () => false
|
|
59
61
|
}, /*#__PURE__*/React__default.createElement(Tag, _extends({
|
|
60
62
|
"aria-pressed": selectedTag !== false,
|
|
61
|
-
ref:
|
|
63
|
+
ref: combinedRef,
|
|
62
64
|
size: size,
|
|
63
65
|
renderIcon: renderIcon,
|
|
64
66
|
disabled: disabled,
|
|
@@ -72,7 +74,7 @@ const SelectableTag = _ref => {
|
|
|
72
74
|
}
|
|
73
75
|
return /*#__PURE__*/React__default.createElement(Tag, _extends({
|
|
74
76
|
"aria-pressed": selectedTag !== false,
|
|
75
|
-
ref:
|
|
77
|
+
ref: combinedRef,
|
|
76
78
|
size: size,
|
|
77
79
|
renderIcon: renderIcon,
|
|
78
80
|
disabled: disabled,
|
|
@@ -83,7 +85,7 @@ const SelectableTag = _ref => {
|
|
|
83
85
|
title: text,
|
|
84
86
|
className: `${prefix}--tag__label`
|
|
85
87
|
}, text));
|
|
86
|
-
};
|
|
88
|
+
});
|
|
87
89
|
SelectableTag.propTypes = {
|
|
88
90
|
/**
|
|
89
91
|
* Provide a custom className that is applied to the containing <span>
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* This source code is licensed under the Apache-2.0 license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
import React, { ComponentType, FunctionComponent } from 'react';
|
|
7
|
+
import React, { type ComponentType, type FunctionComponent } from 'react';
|
|
8
8
|
export type TreeNodeProps = {
|
|
9
9
|
/**
|
|
10
10
|
* **Note:** this is controlled by the parent TreeView component, do not set manually.
|
|
@@ -47,10 +47,17 @@ const TreeNode = /*#__PURE__*/React__default.forwardRef((_ref, forwardedRef) =>
|
|
|
47
47
|
} = useRef(nodeId || uniqueId());
|
|
48
48
|
const controllableExpandedState = useControllableState({
|
|
49
49
|
value: isExpanded,
|
|
50
|
-
onChange:
|
|
51
|
-
|
|
50
|
+
onChange: newValue => {
|
|
51
|
+
onToggle?.(undefined, {
|
|
52
|
+
id,
|
|
53
|
+
isExpanded: newValue,
|
|
54
|
+
label,
|
|
55
|
+
value
|
|
56
|
+
});
|
|
57
|
+
},
|
|
58
|
+
defaultValue: defaultIsExpanded ?? false
|
|
52
59
|
});
|
|
53
|
-
const uncontrollableExpandedState = useState(isExpanded);
|
|
60
|
+
const uncontrollableExpandedState = useState(isExpanded ?? false);
|
|
54
61
|
const [expanded, setExpanded] = enableTreeviewControllable ? controllableExpandedState : uncontrollableExpandedState;
|
|
55
62
|
const currentNode = useRef(null);
|
|
56
63
|
const currentNodeLabel = useRef(null);
|
|
@@ -244,7 +251,7 @@ const TreeNode = /*#__PURE__*/React__default.forwardRef((_ref, forwardedRef) =>
|
|
|
244
251
|
}
|
|
245
252
|
if (!enableTreeviewControllable) {
|
|
246
253
|
// sync props and state
|
|
247
|
-
setExpanded(isExpanded);
|
|
254
|
+
setExpanded(isExpanded ?? false);
|
|
248
255
|
}
|
|
249
256
|
}, [children, depth, Icon, isExpanded, enableTreeviewControllable, setExpanded]);
|
|
250
257
|
const treeNodeProps = {
|
|
@@ -44,7 +44,11 @@ const TreeView = _ref => {
|
|
|
44
44
|
const treeWalker = useRef(treeRootRef?.current);
|
|
45
45
|
const controllableSelectionState = useControllableState({
|
|
46
46
|
value: preselected,
|
|
47
|
-
onChange:
|
|
47
|
+
onChange: newSelected => {
|
|
48
|
+
onSelect?.(undefined, {
|
|
49
|
+
activeNodeId: newSelected[0]
|
|
50
|
+
});
|
|
51
|
+
},
|
|
48
52
|
defaultValue: []
|
|
49
53
|
});
|
|
50
54
|
const uncontrollableSelectionState = useState(preselected ?? []);
|
|
@@ -127,11 +131,7 @@ const TreeView = _ref => {
|
|
|
127
131
|
});
|
|
128
132
|
function handleKeyDown(event) {
|
|
129
133
|
event.stopPropagation();
|
|
130
|
-
if (matches(event, [ArrowUp, ArrowDown, Home, End
|
|
131
|
-
// @ts-ignore - `matches` doesn't like the object syntax without missing properties
|
|
132
|
-
{
|
|
133
|
-
code: 'KeyA'
|
|
134
|
-
}])) {
|
|
134
|
+
if (matches(event, [ArrowUp, ArrowDown, Home, End])) {
|
|
135
135
|
event.preventDefault();
|
|
136
136
|
}
|
|
137
137
|
if (!treeWalker.current) {
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright IBM Corp. 2016, 2025
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import React, { type ReactElement } from 'react';
|
|
8
|
+
interface ClickListenerProps {
|
|
9
|
+
children: ReactElement;
|
|
10
|
+
onClickOutside: (event: MouseEvent) => void;
|
|
11
|
+
}
|
|
12
|
+
export declare const ClickListener: ({ children, onClickOutside, }: ClickListenerProps) => React.ReactElement<any, string | React.JSXElementConstructor<any>>;
|
|
13
|
+
export {};
|
|
@@ -5,70 +5,43 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import {
|
|
9
|
-
import PropTypes from 'prop-types';
|
|
10
|
-
import React__default from 'react';
|
|
8
|
+
import { useRef, useEffect, cloneElement } from 'react';
|
|
11
9
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
if (
|
|
20
|
-
return
|
|
10
|
+
const ClickListener = _ref => {
|
|
11
|
+
let {
|
|
12
|
+
children,
|
|
13
|
+
onClickOutside
|
|
14
|
+
} = _ref;
|
|
15
|
+
const elementRef = useRef(null);
|
|
16
|
+
const getEventTarget = event => {
|
|
17
|
+
if (event.composed && typeof event.composedPath === 'function') {
|
|
18
|
+
return event.composedPath()[0];
|
|
21
19
|
}
|
|
22
|
-
return
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
this.handleDocumentClick = this.handleDocumentClick.bind(this);
|
|
30
|
-
}
|
|
31
|
-
componentDidMount() {
|
|
32
|
-
document.addEventListener('click', this.handleDocumentClick);
|
|
33
|
-
}
|
|
34
|
-
componentWillUnmount() {
|
|
35
|
-
document.removeEventListener('click', this.handleDocumentClick);
|
|
36
|
-
}
|
|
37
|
-
handleDocumentClick(evt) {
|
|
38
|
-
if (this.element) {
|
|
39
|
-
if (this.element.contains && !this.element.contains(ClickListener.getEventTarget(evt))) {
|
|
40
|
-
this.props.onClickOutside(evt);
|
|
20
|
+
return event.target;
|
|
21
|
+
};
|
|
22
|
+
const handleDocumentClick = event => {
|
|
23
|
+
if (elementRef.current?.contains) {
|
|
24
|
+
const eventTarget = getEventTarget(event);
|
|
25
|
+
if (eventTarget instanceof Node && !elementRef.current.contains(eventTarget)) {
|
|
26
|
+
onClickOutside(event);
|
|
41
27
|
}
|
|
42
28
|
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
* This means that here we target the following `ref` location:
|
|
54
|
-
*
|
|
55
|
-
* <ClickListener onClickOutside={() => {}}>
|
|
56
|
-
* <Child ref={targetedRefHere} />
|
|
57
|
-
* </ClickListener>
|
|
58
|
-
*/
|
|
59
|
-
if (children.ref && typeof children.ref === 'function') {
|
|
29
|
+
};
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
document.addEventListener('click', handleDocumentClick);
|
|
32
|
+
return () => {
|
|
33
|
+
document.removeEventListener('click', handleDocumentClick);
|
|
34
|
+
};
|
|
35
|
+
}, [onClickOutside]);
|
|
36
|
+
const handleRef = el => {
|
|
37
|
+
elementRef.current = el;
|
|
38
|
+
if ('ref' in children && typeof children.ref === 'function') {
|
|
60
39
|
children.ref(el);
|
|
61
40
|
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
_defineProperty(ClickListener, "propTypes", {
|
|
70
|
-
children: PropTypes.element.isRequired,
|
|
71
|
-
onClickOutside: PropTypes.func.isRequired
|
|
72
|
-
});
|
|
41
|
+
};
|
|
42
|
+
return /*#__PURE__*/cloneElement(children, {
|
|
43
|
+
ref: handleRef
|
|
44
|
+
});
|
|
45
|
+
};
|
|
73
46
|
|
|
74
|
-
export { ClickListener
|
|
47
|
+
export { ClickListener };
|