@carbon/react 1.87.0 → 1.87.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 +902 -902
- package/es/components/TreeView/TreeContext.d.ts +1 -2
- package/es/components/TreeView/TreeNode.d.ts +8 -6
- package/es/components/TreeView/TreeNode.js +1 -8
- package/es/components/TreeView/TreeView.d.ts +7 -5
- package/es/components/TreeView/TreeView.js +20 -22
- package/lib/components/TreeView/TreeContext.d.ts +1 -2
- package/lib/components/TreeView/TreeNode.d.ts +8 -6
- package/lib/components/TreeView/TreeNode.js +1 -8
- package/lib/components/TreeView/TreeView.d.ts +7 -5
- package/lib/components/TreeView/TreeView.js +20 -22
- package/package.json +4 -4
|
@@ -4,13 +4,12 @@
|
|
|
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 { type MouseEvent } from 'react';
|
|
8
7
|
import type { TreeNodeProps } from './TreeNode';
|
|
9
8
|
interface TreeContextProps {
|
|
10
9
|
active?: string | number;
|
|
11
10
|
multiselect?: boolean;
|
|
12
11
|
onActivate?: (nodeId?: string | number) => void;
|
|
13
|
-
onTreeSelect?:
|
|
12
|
+
onTreeSelect?: TreeNodeProps['onTreeSelect'];
|
|
14
13
|
selected?: Array<string | number>;
|
|
15
14
|
size?: 'xs' | 'sm';
|
|
16
15
|
}
|
|
@@ -5,6 +5,8 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
import React, { type ComponentType, type FunctionComponent } from 'react';
|
|
8
|
+
type UncontrolledOnToggle = (event: React.MouseEvent | React.KeyboardEvent, node: Pick<TreeNodeProps, 'id' | 'label' | 'value' | 'isExpanded'>) => void;
|
|
9
|
+
type ControlledOnToggle = (isExpanded: TreeNodeProps['isExpanded']) => void;
|
|
8
10
|
export type TreeNodeProps = {
|
|
9
11
|
/**
|
|
10
12
|
* **Note:** this is controlled by the parent TreeView component, do not set manually.
|
|
@@ -52,15 +54,15 @@ export type TreeNodeProps = {
|
|
|
52
54
|
/**
|
|
53
55
|
* Callback function for when the node is selected
|
|
54
56
|
*/
|
|
55
|
-
onSelect?: (event: React.MouseEvent, node
|
|
57
|
+
onSelect?: (event: React.MouseEvent | React.KeyboardEvent, node: Pick<TreeNodeProps, 'id' | 'label' | 'value'>) => void;
|
|
56
58
|
/**
|
|
57
59
|
* Callback function for when a parent node is expanded or collapsed
|
|
58
60
|
*/
|
|
59
|
-
onToggle?:
|
|
61
|
+
onToggle?: UncontrolledOnToggle | ControlledOnToggle;
|
|
60
62
|
/**
|
|
61
63
|
* Callback function for when any node in the tree is selected
|
|
62
64
|
*/
|
|
63
|
-
onTreeSelect?: (event: React.MouseEvent, node
|
|
65
|
+
onTreeSelect?: (event: React.MouseEvent | React.KeyboardEvent, node: Pick<TreeNodeProps, 'id' | 'label' | 'value'>) => void;
|
|
64
66
|
/**
|
|
65
67
|
* A component used to render an icon.
|
|
66
68
|
*/
|
|
@@ -137,15 +139,15 @@ declare const TreeNode: React.ForwardRefExoticComponent<{
|
|
|
137
139
|
/**
|
|
138
140
|
* Callback function for when the node is selected
|
|
139
141
|
*/
|
|
140
|
-
onSelect?: (event: React.MouseEvent, node
|
|
142
|
+
onSelect?: (event: React.MouseEvent | React.KeyboardEvent, node: Pick<TreeNodeProps, "id" | "label" | "value">) => void;
|
|
141
143
|
/**
|
|
142
144
|
* Callback function for when a parent node is expanded or collapsed
|
|
143
145
|
*/
|
|
144
|
-
onToggle?:
|
|
146
|
+
onToggle?: UncontrolledOnToggle | ControlledOnToggle;
|
|
145
147
|
/**
|
|
146
148
|
* Callback function for when any node in the tree is selected
|
|
147
149
|
*/
|
|
148
|
-
onTreeSelect?: (event: React.MouseEvent, node
|
|
150
|
+
onTreeSelect?: (event: React.MouseEvent | React.KeyboardEvent, node: Pick<TreeNodeProps, "id" | "label" | "value">) => void;
|
|
149
151
|
/**
|
|
150
152
|
* A component used to render an icon.
|
|
151
153
|
*/
|
|
@@ -130,14 +130,7 @@ const TreeNode = /*#__PURE__*/React.forwardRef(({
|
|
|
130
130
|
} = useRef(nodeId || useId());
|
|
131
131
|
const controllableExpandedState = useControllableState({
|
|
132
132
|
value: isExpanded,
|
|
133
|
-
onChange:
|
|
134
|
-
onToggle?.(undefined, {
|
|
135
|
-
id,
|
|
136
|
-
isExpanded: newValue,
|
|
137
|
-
label,
|
|
138
|
-
value
|
|
139
|
-
});
|
|
140
|
-
},
|
|
133
|
+
onChange: onToggle,
|
|
141
134
|
defaultValue: defaultIsExpanded ?? false
|
|
142
135
|
});
|
|
143
136
|
const uncontrollableExpandedState = useState(isExpanded ?? false);
|
|
@@ -5,7 +5,11 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
import React, { type JSX } from 'react';
|
|
8
|
-
import TreeNode, { TreeNodeProps } from './TreeNode';
|
|
8
|
+
import TreeNode, { type TreeNodeProps } from './TreeNode';
|
|
9
|
+
type UncontrolledOnSelect = (event: React.MouseEvent | React.KeyboardEvent, payload: Parameters<NonNullable<TreeNodeProps['onSelect']>>[1] & {
|
|
10
|
+
activeNodeId?: TreeViewProps['active'];
|
|
11
|
+
}) => void;
|
|
12
|
+
type ControlledOnSelect = (selected: TreeViewProps['selected']) => void;
|
|
9
13
|
export type TreeViewProps = {
|
|
10
14
|
/**
|
|
11
15
|
* Mark the active node in the tree, represented by its ID
|
|
@@ -36,13 +40,11 @@ export type TreeViewProps = {
|
|
|
36
40
|
* **[Experimental]** Callback function that is called when any node is activated.
|
|
37
41
|
* *This is only supported with the `enable-treeview-controllable` feature flag!*
|
|
38
42
|
*/
|
|
39
|
-
onActivate?: (
|
|
43
|
+
onActivate?: (active: TreeViewProps['active']) => void;
|
|
40
44
|
/**
|
|
41
45
|
* Callback function that is called when any node is selected
|
|
42
46
|
*/
|
|
43
|
-
onSelect?:
|
|
44
|
-
activeNodeId?: string | number;
|
|
45
|
-
}) => void;
|
|
47
|
+
onSelect?: UncontrolledOnSelect | ControlledOnSelect;
|
|
46
48
|
/**
|
|
47
49
|
* Array representing all selected node IDs in the tree
|
|
48
50
|
*/
|
|
@@ -45,11 +45,7 @@ const TreeView = ({
|
|
|
45
45
|
const treeWalker = useRef(null);
|
|
46
46
|
const controllableSelectionState = useControllableState({
|
|
47
47
|
value: preselected,
|
|
48
|
-
onChange:
|
|
49
|
-
onSelect?.(undefined, {
|
|
50
|
-
activeNodeId: newSelected[0]
|
|
51
|
-
});
|
|
52
|
-
},
|
|
48
|
+
onChange: onSelect,
|
|
53
49
|
defaultValue: []
|
|
54
50
|
});
|
|
55
51
|
const uncontrollableSelectionState = useState(preselected ?? []);
|
|
@@ -66,25 +62,27 @@ const TreeView = ({
|
|
|
66
62
|
item.tabIndex = -1;
|
|
67
63
|
});
|
|
68
64
|
}
|
|
69
|
-
function handleTreeSelect(event, node
|
|
65
|
+
function handleTreeSelect(event, node) {
|
|
70
66
|
const nodeId = node.id;
|
|
71
|
-
if (
|
|
72
|
-
if (
|
|
73
|
-
|
|
67
|
+
if (nodeId) {
|
|
68
|
+
if (multiselect && (event.metaKey || event.ctrlKey)) {
|
|
69
|
+
if (!selected.includes(nodeId)) {
|
|
70
|
+
setSelected(selected.concat(nodeId));
|
|
71
|
+
} else {
|
|
72
|
+
setSelected(selected.filter(selectedId => selectedId !== nodeId));
|
|
73
|
+
}
|
|
74
|
+
if (!enableTreeviewControllable) {
|
|
75
|
+
onSelect?.(event, node);
|
|
76
|
+
}
|
|
74
77
|
} else {
|
|
75
|
-
setSelected(
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
if (!enableTreeviewControllable) {
|
|
84
|
-
onSelect?.(event, {
|
|
85
|
-
activeNodeId: nodeId,
|
|
86
|
-
...node
|
|
87
|
-
});
|
|
78
|
+
setSelected([nodeId]);
|
|
79
|
+
setActive(nodeId);
|
|
80
|
+
if (!enableTreeviewControllable) {
|
|
81
|
+
onSelect?.(event, {
|
|
82
|
+
activeNodeId: nodeId,
|
|
83
|
+
...node
|
|
84
|
+
});
|
|
85
|
+
}
|
|
88
86
|
}
|
|
89
87
|
}
|
|
90
88
|
}
|
|
@@ -4,13 +4,12 @@
|
|
|
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 { type MouseEvent } from 'react';
|
|
8
7
|
import type { TreeNodeProps } from './TreeNode';
|
|
9
8
|
interface TreeContextProps {
|
|
10
9
|
active?: string | number;
|
|
11
10
|
multiselect?: boolean;
|
|
12
11
|
onActivate?: (nodeId?: string | number) => void;
|
|
13
|
-
onTreeSelect?:
|
|
12
|
+
onTreeSelect?: TreeNodeProps['onTreeSelect'];
|
|
14
13
|
selected?: Array<string | number>;
|
|
15
14
|
size?: 'xs' | 'sm';
|
|
16
15
|
}
|
|
@@ -5,6 +5,8 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
import React, { type ComponentType, type FunctionComponent } from 'react';
|
|
8
|
+
type UncontrolledOnToggle = (event: React.MouseEvent | React.KeyboardEvent, node: Pick<TreeNodeProps, 'id' | 'label' | 'value' | 'isExpanded'>) => void;
|
|
9
|
+
type ControlledOnToggle = (isExpanded: TreeNodeProps['isExpanded']) => void;
|
|
8
10
|
export type TreeNodeProps = {
|
|
9
11
|
/**
|
|
10
12
|
* **Note:** this is controlled by the parent TreeView component, do not set manually.
|
|
@@ -52,15 +54,15 @@ export type TreeNodeProps = {
|
|
|
52
54
|
/**
|
|
53
55
|
* Callback function for when the node is selected
|
|
54
56
|
*/
|
|
55
|
-
onSelect?: (event: React.MouseEvent, node
|
|
57
|
+
onSelect?: (event: React.MouseEvent | React.KeyboardEvent, node: Pick<TreeNodeProps, 'id' | 'label' | 'value'>) => void;
|
|
56
58
|
/**
|
|
57
59
|
* Callback function for when a parent node is expanded or collapsed
|
|
58
60
|
*/
|
|
59
|
-
onToggle?:
|
|
61
|
+
onToggle?: UncontrolledOnToggle | ControlledOnToggle;
|
|
60
62
|
/**
|
|
61
63
|
* Callback function for when any node in the tree is selected
|
|
62
64
|
*/
|
|
63
|
-
onTreeSelect?: (event: React.MouseEvent, node
|
|
65
|
+
onTreeSelect?: (event: React.MouseEvent | React.KeyboardEvent, node: Pick<TreeNodeProps, 'id' | 'label' | 'value'>) => void;
|
|
64
66
|
/**
|
|
65
67
|
* A component used to render an icon.
|
|
66
68
|
*/
|
|
@@ -137,15 +139,15 @@ declare const TreeNode: React.ForwardRefExoticComponent<{
|
|
|
137
139
|
/**
|
|
138
140
|
* Callback function for when the node is selected
|
|
139
141
|
*/
|
|
140
|
-
onSelect?: (event: React.MouseEvent, node
|
|
142
|
+
onSelect?: (event: React.MouseEvent | React.KeyboardEvent, node: Pick<TreeNodeProps, "id" | "label" | "value">) => void;
|
|
141
143
|
/**
|
|
142
144
|
* Callback function for when a parent node is expanded or collapsed
|
|
143
145
|
*/
|
|
144
|
-
onToggle?:
|
|
146
|
+
onToggle?: UncontrolledOnToggle | ControlledOnToggle;
|
|
145
147
|
/**
|
|
146
148
|
* Callback function for when any node in the tree is selected
|
|
147
149
|
*/
|
|
148
|
-
onTreeSelect?: (event: React.MouseEvent, node
|
|
150
|
+
onTreeSelect?: (event: React.MouseEvent | React.KeyboardEvent, node: Pick<TreeNodeProps, "id" | "label" | "value">) => void;
|
|
149
151
|
/**
|
|
150
152
|
* A component used to render an icon.
|
|
151
153
|
*/
|
|
@@ -134,14 +134,7 @@ const TreeNode = /*#__PURE__*/React.forwardRef(({
|
|
|
134
134
|
} = React.useRef(nodeId || useId.useId());
|
|
135
135
|
const controllableExpandedState = useControllableState.useControllableState({
|
|
136
136
|
value: isExpanded,
|
|
137
|
-
onChange:
|
|
138
|
-
onToggle?.(undefined, {
|
|
139
|
-
id,
|
|
140
|
-
isExpanded: newValue,
|
|
141
|
-
label,
|
|
142
|
-
value
|
|
143
|
-
});
|
|
144
|
-
},
|
|
137
|
+
onChange: onToggle,
|
|
145
138
|
defaultValue: defaultIsExpanded ?? false
|
|
146
139
|
});
|
|
147
140
|
const uncontrollableExpandedState = React.useState(isExpanded ?? false);
|
|
@@ -5,7 +5,11 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
import React, { type JSX } from 'react';
|
|
8
|
-
import TreeNode, { TreeNodeProps } from './TreeNode';
|
|
8
|
+
import TreeNode, { type TreeNodeProps } from './TreeNode';
|
|
9
|
+
type UncontrolledOnSelect = (event: React.MouseEvent | React.KeyboardEvent, payload: Parameters<NonNullable<TreeNodeProps['onSelect']>>[1] & {
|
|
10
|
+
activeNodeId?: TreeViewProps['active'];
|
|
11
|
+
}) => void;
|
|
12
|
+
type ControlledOnSelect = (selected: TreeViewProps['selected']) => void;
|
|
9
13
|
export type TreeViewProps = {
|
|
10
14
|
/**
|
|
11
15
|
* Mark the active node in the tree, represented by its ID
|
|
@@ -36,13 +40,11 @@ export type TreeViewProps = {
|
|
|
36
40
|
* **[Experimental]** Callback function that is called when any node is activated.
|
|
37
41
|
* *This is only supported with the `enable-treeview-controllable` feature flag!*
|
|
38
42
|
*/
|
|
39
|
-
onActivate?: (
|
|
43
|
+
onActivate?: (active: TreeViewProps['active']) => void;
|
|
40
44
|
/**
|
|
41
45
|
* Callback function that is called when any node is selected
|
|
42
46
|
*/
|
|
43
|
-
onSelect?:
|
|
44
|
-
activeNodeId?: string | number;
|
|
45
|
-
}) => void;
|
|
47
|
+
onSelect?: UncontrolledOnSelect | ControlledOnSelect;
|
|
46
48
|
/**
|
|
47
49
|
* Array representing all selected node IDs in the tree
|
|
48
50
|
*/
|
|
@@ -49,11 +49,7 @@ const TreeView = ({
|
|
|
49
49
|
const treeWalker = React.useRef(null);
|
|
50
50
|
const controllableSelectionState = useControllableState.useControllableState({
|
|
51
51
|
value: preselected,
|
|
52
|
-
onChange:
|
|
53
|
-
onSelect?.(undefined, {
|
|
54
|
-
activeNodeId: newSelected[0]
|
|
55
|
-
});
|
|
56
|
-
},
|
|
52
|
+
onChange: onSelect,
|
|
57
53
|
defaultValue: []
|
|
58
54
|
});
|
|
59
55
|
const uncontrollableSelectionState = React.useState(preselected ?? []);
|
|
@@ -70,25 +66,27 @@ const TreeView = ({
|
|
|
70
66
|
item.tabIndex = -1;
|
|
71
67
|
});
|
|
72
68
|
}
|
|
73
|
-
function handleTreeSelect(event, node
|
|
69
|
+
function handleTreeSelect(event, node) {
|
|
74
70
|
const nodeId = node.id;
|
|
75
|
-
if (
|
|
76
|
-
if (
|
|
77
|
-
|
|
71
|
+
if (nodeId) {
|
|
72
|
+
if (multiselect && (event.metaKey || event.ctrlKey)) {
|
|
73
|
+
if (!selected.includes(nodeId)) {
|
|
74
|
+
setSelected(selected.concat(nodeId));
|
|
75
|
+
} else {
|
|
76
|
+
setSelected(selected.filter(selectedId => selectedId !== nodeId));
|
|
77
|
+
}
|
|
78
|
+
if (!enableTreeviewControllable) {
|
|
79
|
+
onSelect?.(event, node);
|
|
80
|
+
}
|
|
78
81
|
} else {
|
|
79
|
-
setSelected(
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
if (!enableTreeviewControllable) {
|
|
88
|
-
onSelect?.(event, {
|
|
89
|
-
activeNodeId: nodeId,
|
|
90
|
-
...node
|
|
91
|
-
});
|
|
82
|
+
setSelected([nodeId]);
|
|
83
|
+
setActive(nodeId);
|
|
84
|
+
if (!enableTreeviewControllable) {
|
|
85
|
+
onSelect?.(event, {
|
|
86
|
+
activeNodeId: nodeId,
|
|
87
|
+
...node
|
|
88
|
+
});
|
|
89
|
+
}
|
|
92
90
|
}
|
|
93
91
|
}
|
|
94
92
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@carbon/react",
|
|
3
3
|
"description": "React components for the Carbon Design System",
|
|
4
|
-
"version": "1.87.
|
|
4
|
+
"version": "1.87.1",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "lib/index.js",
|
|
7
7
|
"types": "lib/index.d.ts",
|
|
@@ -52,10 +52,10 @@
|
|
|
52
52
|
},
|
|
53
53
|
"dependencies": {
|
|
54
54
|
"@babel/runtime": "^7.27.3",
|
|
55
|
-
"@carbon/feature-flags": "^0.28.
|
|
55
|
+
"@carbon/feature-flags": "^0.28.1",
|
|
56
56
|
"@carbon/icons-react": "^11.63.0",
|
|
57
57
|
"@carbon/layout": "^11.37.0",
|
|
58
|
-
"@carbon/styles": "^1.86.
|
|
58
|
+
"@carbon/styles": "^1.86.1",
|
|
59
59
|
"@carbon/utilities": "^0.7.0",
|
|
60
60
|
"@floating-ui/react": "^0.27.4",
|
|
61
61
|
"@ibm/telemetry-js": "^1.5.0",
|
|
@@ -139,5 +139,5 @@
|
|
|
139
139
|
"**/*.scss",
|
|
140
140
|
"**/*.css"
|
|
141
141
|
],
|
|
142
|
-
"gitHead": "
|
|
142
|
+
"gitHead": "f420c48d3859804a62811e6420d940f2e2602219"
|
|
143
143
|
}
|