@deque/cauldron-react 7.6.0-canary.0419668f → 7.6.0-canary.17caea31
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.
|
@@ -14,15 +14,6 @@ interface CascadeOptions {
|
|
|
14
14
|
cascadeSelect: boolean;
|
|
15
15
|
cascadeDeselect: boolean;
|
|
16
16
|
}
|
|
17
|
-
/**
|
|
18
|
-
* Toggle a single node, applying cascade per the options (multiple mode only):
|
|
19
|
-
* - selecting + `cascadeSelect`: also selects all (non-disabled) descendants.
|
|
20
|
-
* - deselecting + `cascadeDeselect`: also deselects all descendants.
|
|
21
|
-
*
|
|
22
|
-
* In `single` mode only the clicked node is selected (clicking it again clears
|
|
23
|
-
* it); cascade does not apply.
|
|
24
|
-
*/
|
|
25
|
-
export declare function toggleSelection(nodes: TreeViewNode[], previous: Set<Key>, key: Key, selectionMode: 'single' | 'multiple', { cascadeSelect, cascadeDeselect }: CascadeOptions): Set<Key>;
|
|
26
17
|
/**
|
|
27
18
|
* Apply react-aria's proposed selection while enforcing cascade. Each key
|
|
28
19
|
* react-aria added cascades to its descendants when `cascadeSelect` is set; each
|
|
@@ -11,6 +11,8 @@ export declare const ROW_GAP = 2;
|
|
|
11
11
|
export declare const LIST_PADDING = 4;
|
|
12
12
|
type TreeViewProps = Cauldron.LabelProps & Omit<React.HTMLAttributes<HTMLDivElement>, 'children' | 'role' | 'dangerouslySetInnerHTML'> & {
|
|
13
13
|
items: TreeViewNode[];
|
|
14
|
+
/** Runs when an item is activated by a click, Space or Enter. Each of these
|
|
15
|
+
* also toggles the item's selection. Without selection, Space does not act. */
|
|
14
16
|
onAction?: (key: string) => void;
|
|
15
17
|
selectionMode?: 'none' | 'single' | 'multiple';
|
|
16
18
|
/** When true (multiple selection only), selecting a parent also selects all
|
package/lib/index.js
CHANGED
|
@@ -517,7 +517,7 @@ var Accordion = function (_a) {
|
|
|
517
517
|
var panelProps = panelElement.props;
|
|
518
518
|
return (React__default["default"].createElement("div", tslib.__assign({ className: "Accordion" }, props),
|
|
519
519
|
React__default["default"].createElement(ExpandCollapsePanel, tslib.__assign({ id: panelProps.id || "".concat(elementId, "-panel"), open: open, onToggle: onToggle, animationTiming: animationTiming }, panelProps),
|
|
520
|
-
React__default["default"].createElement(PanelTrigger$1, tslib.__assign({ iconCollapsed: "triangle-right", iconExpanded: "triangle-down",
|
|
520
|
+
React__default["default"].createElement(PanelTrigger$1, tslib.__assign({ iconCollapsed: "triangle-right", iconExpanded: "triangle-down", "aria-controls": panelProps.id || "".concat(elementId, "-panel"), heading: trigger.props.heading }, trigger.props, { className: classNames__default["default"]('Accordion__trigger', trigger.props.className) }), trigger),
|
|
521
521
|
panelElement)));
|
|
522
522
|
};
|
|
523
523
|
Accordion.displayName = 'Accordion';
|
|
@@ -1420,7 +1420,7 @@ function createFocusTrap(targetElement, initialFocusElement) {
|
|
|
1420
1420
|
suspended: false
|
|
1421
1421
|
};
|
|
1422
1422
|
var focusListener = function (event) {
|
|
1423
|
-
var _a, _b
|
|
1423
|
+
var _a, _b;
|
|
1424
1424
|
var eventTarget = event.target;
|
|
1425
1425
|
var elementContainsTarget = elementContains(targetElement, eventTarget);
|
|
1426
1426
|
if (focusTrapMetadata.suspended) {
|
|
@@ -1438,24 +1438,26 @@ function createFocusTrap(targetElement, initialFocusElement) {
|
|
|
1438
1438
|
return;
|
|
1439
1439
|
}
|
|
1440
1440
|
var focusableElements = Array.from((targetElement === null || targetElement === void 0 ? void 0 : targetElement.querySelectorAll(focusable__default["default"])) || []);
|
|
1441
|
+
// Tab stops such as contenteditable and video[controls] can report tabIndex -1 without a tabindex attribute.
|
|
1442
|
+
var wrapTargets = focusableElements.filter(function (element) { return !(element.hasAttribute('tabindex') && element.tabIndex < 0); });
|
|
1441
1443
|
// If focus reaches the trap guards, we need to wrap focus around to the leading
|
|
1442
1444
|
// or trailing focusable element depending on which guard obtained focus
|
|
1443
|
-
if (
|
|
1444
|
-
|
|
1445
|
+
if (wrapTargets.length && eventTarget === startGuard) {
|
|
1446
|
+
wrapTargets[wrapTargets.length - 1].focus();
|
|
1445
1447
|
return;
|
|
1446
1448
|
}
|
|
1447
|
-
else if (
|
|
1448
|
-
|
|
1449
|
+
else if (wrapTargets.length && eventTarget === endGuard) {
|
|
1450
|
+
wrapTargets[0].focus();
|
|
1449
1451
|
return;
|
|
1450
1452
|
}
|
|
1451
1453
|
// If focus somehow escaped the trap, we need to try to restore focus to
|
|
1452
1454
|
// to a suitable focusable element within the focus trap target. Otherwise
|
|
1453
1455
|
// we'll need to focus on an alternative within the container.
|
|
1454
1456
|
if (elementContains(targetElement, focusTrapMetadata.lastFocusedElement)) {
|
|
1455
|
-
(
|
|
1457
|
+
(_a = focusTrapMetadata.lastFocusedElement) === null || _a === void 0 ? void 0 : _a.focus();
|
|
1456
1458
|
}
|
|
1457
1459
|
else if (focusableElements.length) {
|
|
1458
|
-
(
|
|
1460
|
+
(_b = focusableElements[0]) === null || _b === void 0 ? void 0 : _b.focus();
|
|
1459
1461
|
}
|
|
1460
1462
|
else {
|
|
1461
1463
|
// if there are no focusable elements, just focus the container
|
|
@@ -5604,45 +5606,6 @@ function collectDescendantKeys(node) {
|
|
|
5604
5606
|
function collectDisabledKeys(nodes) {
|
|
5605
5607
|
return nodes.flatMap(function (node) { return tslib.__spreadArray(tslib.__spreadArray([], tslib.__read((node.disabled ? [node.id] : [])), false), tslib.__read((node.children ? collectDisabledKeys(node.children) : [])), false); });
|
|
5606
5608
|
}
|
|
5607
|
-
/**
|
|
5608
|
-
* Toggle a single node, applying cascade per the options (multiple mode only):
|
|
5609
|
-
* - selecting + `cascadeSelect`: also selects all (non-disabled) descendants.
|
|
5610
|
-
* - deselecting + `cascadeDeselect`: also deselects all descendants.
|
|
5611
|
-
*
|
|
5612
|
-
* In `single` mode only the clicked node is selected (clicking it again clears
|
|
5613
|
-
* it); cascade does not apply.
|
|
5614
|
-
*/
|
|
5615
|
-
function toggleSelection(nodes, previous, key, selectionMode, _a) {
|
|
5616
|
-
var cascadeSelect = _a.cascadeSelect, cascadeDeselect = _a.cascadeDeselect;
|
|
5617
|
-
if (selectionMode === 'single') {
|
|
5618
|
-
var result_1 = new Set();
|
|
5619
|
-
if (!previous.has(key)) {
|
|
5620
|
-
result_1.add(key);
|
|
5621
|
-
}
|
|
5622
|
-
return result_1;
|
|
5623
|
-
}
|
|
5624
|
-
var result = new Set(previous);
|
|
5625
|
-
var node = findNode(nodes, key);
|
|
5626
|
-
var descendants = node ? collectDescendantKeys(node) : [];
|
|
5627
|
-
var disabled = new Set(collectDisabledKeys(nodes));
|
|
5628
|
-
if (!previous.has(key)) {
|
|
5629
|
-
result.add(key);
|
|
5630
|
-
if (cascadeSelect) {
|
|
5631
|
-
descendants.forEach(function (k) {
|
|
5632
|
-
if (!disabled.has(k)) {
|
|
5633
|
-
result.add(k);
|
|
5634
|
-
}
|
|
5635
|
-
});
|
|
5636
|
-
}
|
|
5637
|
-
}
|
|
5638
|
-
else {
|
|
5639
|
-
result.delete(key);
|
|
5640
|
-
if (cascadeDeselect) {
|
|
5641
|
-
descendants.forEach(function (k) { return result.delete(k); });
|
|
5642
|
-
}
|
|
5643
|
-
}
|
|
5644
|
-
return result;
|
|
5645
|
-
}
|
|
5646
5609
|
/**
|
|
5647
5610
|
* Apply react-aria's proposed selection while enforcing cascade. Each key
|
|
5648
5611
|
* react-aria added cascades to its descendants when `cascadeSelect` is set; each
|
|
@@ -5690,6 +5653,7 @@ var ROW_GAP = 2;
|
|
|
5690
5653
|
var LIST_PADDING = 4;
|
|
5691
5654
|
var TreeView = React.forwardRef(function (_a, ref) {
|
|
5692
5655
|
var items = _a.items, onAction = _a.onAction, _b = _a.selectionMode, selectionMode = _b === void 0 ? 'none' : _b, _c = _a.cascadeSelect, cascadeSelect = _c === void 0 ? false : _c, _d = _a.cascadeDeselect, cascadeDeselect = _d === void 0 ? false : _d, defaultExpandedKeys = _a.defaultExpandedKeys, _e = _a.virtualized, virtualized = _e === void 0 ? false : _e, height = _a.height, className = _a.className, style = _a.style, other = tslib.__rest(_a, ["items", "onAction", "selectionMode", "cascadeSelect", "cascadeDeselect", "defaultExpandedKeys", "virtualized", "height", "className", "style"]);
|
|
5656
|
+
var treeRef = useSharedRef(ref);
|
|
5693
5657
|
var _f = tslib.__read(React.useState(new Set()), 2), selectedKeys = _f[0], setSelectedKeys = _f[1];
|
|
5694
5658
|
var cascade = { cascadeSelect: cascadeSelect, cascadeDeselect: cascadeDeselect };
|
|
5695
5659
|
// Cascade only applies to multiple selection.
|
|
@@ -5704,16 +5668,48 @@ var TreeView = React.forwardRef(function (_a, ref) {
|
|
|
5704
5668
|
: selection;
|
|
5705
5669
|
});
|
|
5706
5670
|
};
|
|
5707
|
-
//
|
|
5708
|
-
//
|
|
5709
|
-
|
|
5710
|
-
|
|
5711
|
-
|
|
5712
|
-
|
|
5713
|
-
|
|
5714
|
-
|
|
5715
|
-
|
|
5716
|
-
|
|
5671
|
+
// react-aria only reports a press as an action while nothing is selected, so
|
|
5672
|
+
// activation is driven here and react-aria is left to own selection. Click,
|
|
5673
|
+
// Space and Enter all do the same thing: toggle the checkbox and run the action.
|
|
5674
|
+
// Without selection react-aria handles the action itself (see the Tree props).
|
|
5675
|
+
React.useEffect(function () {
|
|
5676
|
+
var node = treeRef.current;
|
|
5677
|
+
if (!node || !onAction || selectionMode === 'none')
|
|
5678
|
+
return;
|
|
5679
|
+
var rowKey = function (target) {
|
|
5680
|
+
var _a;
|
|
5681
|
+
var row = (_a = target === null || target === void 0 ? void 0 : target.closest) === null || _a === void 0 ? void 0 : _a.call(target, '[role="row"][data-key]');
|
|
5682
|
+
if (!row || row.getAttribute('aria-disabled') === 'true')
|
|
5683
|
+
return null;
|
|
5684
|
+
return row.getAttribute('data-key');
|
|
5685
|
+
};
|
|
5686
|
+
var handleKeyDown = function (event) {
|
|
5687
|
+
if (event.key !== 'Enter' && event.key !== ' ')
|
|
5688
|
+
return;
|
|
5689
|
+
if (event.repeat || event.defaultPrevented)
|
|
5690
|
+
return;
|
|
5691
|
+
var key = rowKey(event.target);
|
|
5692
|
+
if (key)
|
|
5693
|
+
onAction(key);
|
|
5694
|
+
};
|
|
5695
|
+
var handleClick = function (event) {
|
|
5696
|
+
var _a;
|
|
5697
|
+
var target = event.target;
|
|
5698
|
+
// The chevron expands rather than activates, and a click on the
|
|
5699
|
+
// checkbox box or label is re-dispatched on the checkbox itself.
|
|
5700
|
+
if ((_a = target === null || target === void 0 ? void 0 : target.closest) === null || _a === void 0 ? void 0 : _a.call(target, '.TreeView__chevron, label[for], .Checkbox__overlay'))
|
|
5701
|
+
return;
|
|
5702
|
+
var key = rowKey(target);
|
|
5703
|
+
if (key)
|
|
5704
|
+
onAction(key);
|
|
5705
|
+
};
|
|
5706
|
+
node.addEventListener('keydown', handleKeyDown);
|
|
5707
|
+
node.addEventListener('click', handleClick);
|
|
5708
|
+
return function () {
|
|
5709
|
+
node.removeEventListener('keydown', handleKeyDown);
|
|
5710
|
+
node.removeEventListener('click', handleClick);
|
|
5711
|
+
};
|
|
5712
|
+
}, [onAction, selectionMode, virtualized]);
|
|
5717
5713
|
// Disabled nodes are non-selectable; react-aria disables them via disabledKeys.
|
|
5718
5714
|
var disabledKeys = React.useMemo(function () { return collectDisabledKeys(items); }, [items]);
|
|
5719
5715
|
// Always control selection: react-aria's own state is lost if the tree
|
|
@@ -5725,9 +5721,11 @@ var TreeView = React.forwardRef(function (_a, ref) {
|
|
|
5725
5721
|
// The `height` prop outranks `style.height`, but only when it is actually
|
|
5726
5722
|
// set — spreading an undefined `height` would wipe the caller's own.
|
|
5727
5723
|
var mergedStyle = virtualized && height !== undefined ? tslib.__assign(tslib.__assign({}, style), { height: height }) : style;
|
|
5728
|
-
var tree = (React__default["default"].createElement(reactAriaComponents.Tree, tslib.__assign({ ref:
|
|
5724
|
+
var tree = (React__default["default"].createElement(reactAriaComponents.Tree, tslib.__assign({ ref: treeRef, className: classNames__default["default"]('TreeView', className, {
|
|
5729
5725
|
'TreeView--virtualized': virtualized
|
|
5730
|
-
}), selectionMode: selectionMode, defaultExpandedKeys: defaultExpandedKeys }, (disabledKeys.length > 0 ? { disabledKeys: disabledKeys } : {}), (onAction
|
|
5726
|
+
}), selectionMode: selectionMode, defaultExpandedKeys: defaultExpandedKeys }, (disabledKeys.length > 0 ? { disabledKeys: disabledKeys } : {}), (onAction && selectionMode === 'none'
|
|
5727
|
+
? { onAction: function (key) { return onAction(String(key)); } }
|
|
5728
|
+
: {}), selectionProps, other, { style: mergedStyle }), items.map(function (item) { return (React__default["default"].createElement(TreeViewItem, tslib.__assign({ key: item.id }, item))); })));
|
|
5731
5729
|
// Rows are absolutely positioned here, so the list layout owns their spacing
|
|
5732
5730
|
// rather than `.TreeView`'s flex `gap`/`padding`.
|
|
5733
5731
|
if (virtualized) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@deque/cauldron-react",
|
|
3
|
-
"version": "7.6.0-canary.
|
|
3
|
+
"version": "7.6.0-canary.17caea31",
|
|
4
4
|
"license": "MPL-2.0",
|
|
5
5
|
"description": "Fully accessible react components library for Deque Cauldron",
|
|
6
6
|
"homepage": "https://cauldron.dequelabs.com/",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"@rollup/plugin-typescript": "^11.1.2",
|
|
38
38
|
"@svgr/rollup": "^6.1.2",
|
|
39
39
|
"@testing-library/dom": "^10.4.0",
|
|
40
|
-
"@testing-library/jest-dom": "^7.0.
|
|
40
|
+
"@testing-library/jest-dom": "^7.0.1",
|
|
41
41
|
"@testing-library/react": "^16.0.1",
|
|
42
42
|
"@testing-library/user-event": "^14.6.7",
|
|
43
43
|
"@types/classnames": "^2.2.10",
|