@deque/cauldron-react 7.6.0-canary.c56fdf76 → 7.6.0-canary.c59590bf
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.
|
@@ -1,34 +1,16 @@
|
|
|
1
|
-
import React
|
|
1
|
+
import React from 'react';
|
|
2
2
|
export interface TextFieldProps extends Omit<React.InputHTMLAttributes<HTMLInputElement>, 'onChange'> {
|
|
3
3
|
label: React.ReactNode;
|
|
4
4
|
description?: React.ReactNode;
|
|
5
5
|
error?: React.ReactNode;
|
|
6
6
|
defaultValue?: string;
|
|
7
7
|
onChange?: (value: string, e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => void;
|
|
8
|
+
/**
|
|
9
|
+
* @deprecated Use the forwarded `ref` instead. Will be removed in the next major version.
|
|
10
|
+
*/
|
|
8
11
|
fieldRef?: React.Ref<HTMLInputElement | HTMLTextAreaElement>;
|
|
9
12
|
requiredText?: string;
|
|
10
13
|
multiline?: boolean;
|
|
11
14
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
export default class TextField extends React.Component<TextFieldProps, TextFieldState> {
|
|
16
|
-
static displayName: string;
|
|
17
|
-
static defaultProps: {
|
|
18
|
-
error: null;
|
|
19
|
-
required: boolean;
|
|
20
|
-
defaultValue: null;
|
|
21
|
-
onChange: () => void;
|
|
22
|
-
fieldRef: () => void;
|
|
23
|
-
requiredText: string;
|
|
24
|
-
multiline: boolean;
|
|
25
|
-
};
|
|
26
|
-
private inputId;
|
|
27
|
-
private errorId;
|
|
28
|
-
private descriptionId;
|
|
29
|
-
private input;
|
|
30
|
-
constructor(props: TextFieldProps);
|
|
31
|
-
render(): React.JSX.Element;
|
|
32
|
-
onChange(e: ChangeEvent<HTMLInputElement | HTMLTextAreaElement>): void;
|
|
33
|
-
}
|
|
34
|
-
export {};
|
|
15
|
+
declare const TextField: React.ForwardRefExoticComponent<TextFieldProps & React.RefAttributes<HTMLInputElement | HTMLTextAreaElement>>;
|
|
16
|
+
export default TextField;
|
|
@@ -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
|
|
@@ -2,8 +2,17 @@ import React from 'react';
|
|
|
2
2
|
import { Cauldron } from '../../types';
|
|
3
3
|
import { TreeViewNode } from './types';
|
|
4
4
|
export type { TreeViewNode } from './types';
|
|
5
|
-
|
|
5
|
+
/** Seeds the initial scroll math. Keep in step with `--tree-view-row-height`,
|
|
6
|
+
* which sizes a virtualized row — see the spacing-parity test. */
|
|
7
|
+
export declare const ESTIMATED_ROW_HEIGHT = 36;
|
|
8
|
+
/** Keep in step with `--space-quarter` / `--space-half`, which `.TreeView` uses
|
|
9
|
+
* for its flex spacing — see the spacing-parity test. */
|
|
10
|
+
export declare const ROW_GAP = 2;
|
|
11
|
+
export declare const LIST_PADDING = 4;
|
|
12
|
+
type TreeViewProps = Cauldron.LabelProps & Omit<React.HTMLAttributes<HTMLDivElement>, 'children' | 'role' | 'dangerouslySetInnerHTML'> & {
|
|
6
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. */
|
|
7
16
|
onAction?: (key: string) => void;
|
|
8
17
|
selectionMode?: 'none' | 'single' | 'multiple';
|
|
9
18
|
/** When true (multiple selection only), selecting a parent also selects all
|
|
@@ -13,7 +22,15 @@ type TreeViewProps = Cauldron.LabelProps & {
|
|
|
13
22
|
* all of its descendants. */
|
|
14
23
|
cascadeDeselect?: boolean;
|
|
15
24
|
defaultExpandedKeys?: string[];
|
|
16
|
-
|
|
25
|
+
/** Render only the rows in view. Use for long lists, where rendering every
|
|
26
|
+
* row makes selection changes slow enough to look frozen. Needs a height —
|
|
27
|
+
* from `height`, `style`, or CSS — or no rows render. Toggling this at
|
|
28
|
+
* runtime remounts the tree, which resets expansion and scroll position. */
|
|
29
|
+
virtualized?: boolean;
|
|
30
|
+
/** Height of the scroll region, taking precedence over `style.height`. Only
|
|
31
|
+
* applies when `virtualized` is set. A relative unit (`"20rem"`) keeps the
|
|
32
|
+
* visible row count stable at zoom. */
|
|
33
|
+
height?: number | string;
|
|
17
34
|
};
|
|
18
35
|
declare const TreeView: React.ForwardRefExoticComponent<TreeViewProps & React.RefAttributes<HTMLDivElement>>;
|
|
19
36
|
export default TreeView;
|
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
|
|
@@ -2747,89 +2749,53 @@ function TooltipTabstop(_a) {
|
|
|
2747
2749
|
}
|
|
2748
2750
|
TooltipTabstop.displayName = 'TooltipTabstop';
|
|
2749
2751
|
|
|
2750
|
-
var TextField =
|
|
2751
|
-
|
|
2752
|
-
|
|
2753
|
-
|
|
2754
|
-
|
|
2755
|
-
|
|
2756
|
-
|
|
2757
|
-
|
|
2758
|
-
|
|
2759
|
-
|
|
2760
|
-
|
|
2761
|
-
|
|
2762
|
-
|
|
2763
|
-
|
|
2764
|
-
|
|
2765
|
-
TextField.prototype.render = function () {
|
|
2766
|
-
var _this = this;
|
|
2767
|
-
var isRequired = !!this.props.required;
|
|
2768
|
-
// disabling `no-unused-vars` to prevent specific
|
|
2769
|
-
// props from being passed through to the input
|
|
2770
|
-
var _a = this.props, label = _a.label, fieldRef = _a.fieldRef, value = _a.value, description = _a.description;
|
|
2771
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
2772
|
-
_a.onChange;
|
|
2773
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
2774
|
-
_a.defaultValue; var _b = _a.error, error = _b === void 0 ? null : _b, requiredText = _a.requiredText, multiline = _a.multiline, ariaDescribedby = _a["aria-describedby"]; _a.children; var className = _a.className, other = tslib.__rest(_a, ["label", "fieldRef", "value", "description", "onChange", "defaultValue", "error", "requiredText", "multiline", 'aria-describedby', "children", "className"]);
|
|
2775
|
-
// typescript can't infer the type so it's complaining about
|
|
2776
|
-
// textarea and input props being incompatible
|
|
2777
|
-
// we should probably fix this
|
|
2778
|
-
var Field = multiline ? 'textarea' : 'input';
|
|
2779
|
-
var describedby = description
|
|
2780
|
-
? addIdRef(ariaDescribedby, this.descriptionId)
|
|
2781
|
-
: ariaDescribedby;
|
|
2782
|
-
var inputProps = {
|
|
2783
|
-
'aria-describedby': error
|
|
2784
|
-
? addIdRef(describedby, this.errorId)
|
|
2785
|
-
: describedby
|
|
2786
|
-
};
|
|
2787
|
-
return (React__default["default"].createElement("div", { className: "Field" },
|
|
2788
|
-
React__default["default"].createElement("label", { className: classNames__default["default"]('Field__label', {
|
|
2789
|
-
'Field__label--is-required': isRequired,
|
|
2790
|
-
'Field__label--has-error': error
|
|
2791
|
-
}), htmlFor: this.inputId },
|
|
2792
|
-
React__default["default"].createElement("span", null, label),
|
|
2793
|
-
isRequired && (React__default["default"].createElement("span", { className: "Field__required-text", "aria-hidden": "true" }, requiredText))),
|
|
2794
|
-
description && (React__default["default"].createElement("div", { className: "Field__description", id: this.descriptionId }, description)),
|
|
2795
|
-
error && (React__default["default"].createElement("div", { className: "Field__error", id: this.errorId },
|
|
2796
|
-
React__default["default"].createElement(Icon, { type: "caution" }),
|
|
2797
|
-
error)),
|
|
2798
|
-
React__default["default"].createElement(Field, tslib.__assign({ className: classNames__default["default"](className, {
|
|
2799
|
-
'Field__text-input': !multiline,
|
|
2800
|
-
Field__textarea: multiline,
|
|
2801
|
-
'Field--has-error': error
|
|
2802
|
-
}), id: this.inputId, value: typeof value !== 'undefined' ? value : this.state.value, onChange: this.onChange, "aria-invalid": !!error, ref: function (input) {
|
|
2803
|
-
_this.input = input;
|
|
2804
|
-
setRef(fieldRef, input);
|
|
2805
|
-
} }, other, inputProps))));
|
|
2806
|
-
};
|
|
2807
|
-
TextField.prototype.onChange = function (e) {
|
|
2808
|
-
var _a, _b;
|
|
2809
|
-
if (this.props.onChange) {
|
|
2810
|
-
this.props.onChange(((_a = this.input) === null || _a === void 0 ? void 0 : _a.value) || /* istanbul ignore next: default value */ '', e);
|
|
2811
|
-
}
|
|
2812
|
-
if (typeof this.props.value !== 'undefined') {
|
|
2752
|
+
var TextField = React.forwardRef(function (_a, ref) {
|
|
2753
|
+
var id = _a.id, label = _a.label, fieldRef = _a.fieldRef, value = _a.value, description = _a.description, onChange = _a.onChange, defaultValue = _a.defaultValue, _b = _a.error, error = _b === void 0 ? null : _b, _c = _a.required, required = _c === void 0 ? false : _c, _d = _a.requiredText, requiredText = _d === void 0 ? 'Required' : _d, _e = _a.multiline, multiline = _e === void 0 ? false : _e, ariaDescribedby = _a["aria-describedby"];
|
|
2754
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
2755
|
+
_a.children; var className = _a.className, other = tslib.__rest(_a, ["id", "label", "fieldRef", "value", "description", "onChange", "defaultValue", "error", "required", "requiredText", "multiline", 'aria-describedby', "children", "className"]);
|
|
2756
|
+
var _f = tslib.__read(nextId.useId(3, 'textfield'), 3), generatedInputId = _f[0], errorId = _f[1], descriptionId = _f[2];
|
|
2757
|
+
var inputId = id || generatedInputId;
|
|
2758
|
+
var isControlled = typeof value !== 'undefined';
|
|
2759
|
+
var _g = tslib.__read(React.useState(isControlled ? value : defaultValue || ''), 2), uncontrolledValue = _g[0], setUncontrolledValue = _g[1];
|
|
2760
|
+
var setFieldRef = React.useCallback(function (field) {
|
|
2761
|
+
setRef(ref, field);
|
|
2762
|
+
setRef(fieldRef, field);
|
|
2763
|
+
}, [ref, fieldRef]);
|
|
2764
|
+
var handleChange = function (e) {
|
|
2765
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(e.target.value, e);
|
|
2766
|
+
if (isControlled) {
|
|
2813
2767
|
return;
|
|
2814
2768
|
}
|
|
2815
|
-
|
|
2816
|
-
value: (_b = this.input) === null || _b === void 0 ? void 0 : _b.value
|
|
2817
|
-
});
|
|
2769
|
+
setUncontrolledValue(e.target.value);
|
|
2818
2770
|
};
|
|
2819
|
-
|
|
2820
|
-
|
|
2821
|
-
|
|
2822
|
-
|
|
2823
|
-
|
|
2824
|
-
|
|
2825
|
-
|
|
2826
|
-
|
|
2827
|
-
|
|
2828
|
-
requiredText: 'Required',
|
|
2829
|
-
multiline: false
|
|
2771
|
+
// typescript can't infer the type so it's complaining about
|
|
2772
|
+
// textarea and input props being incompatible
|
|
2773
|
+
// we should probably fix this
|
|
2774
|
+
var Field = multiline ? 'textarea' : 'input';
|
|
2775
|
+
var describedby = description
|
|
2776
|
+
? addIdRef(ariaDescribedby, descriptionId)
|
|
2777
|
+
: ariaDescribedby;
|
|
2778
|
+
var inputProps = {
|
|
2779
|
+
'aria-describedby': error ? addIdRef(describedby, errorId) : describedby
|
|
2830
2780
|
};
|
|
2831
|
-
return
|
|
2832
|
-
|
|
2781
|
+
return (React__default["default"].createElement("div", { className: "Field" },
|
|
2782
|
+
React__default["default"].createElement("label", { className: classNames__default["default"]('Field__label', {
|
|
2783
|
+
'Field__label--is-required': required,
|
|
2784
|
+
'Field__label--has-error': error
|
|
2785
|
+
}), htmlFor: inputId },
|
|
2786
|
+
React__default["default"].createElement("span", null, label),
|
|
2787
|
+
required && (React__default["default"].createElement("span", { className: "Field__required-text", "aria-hidden": "true" }, requiredText))),
|
|
2788
|
+
description && (React__default["default"].createElement("div", { className: "Field__description", id: descriptionId }, description)),
|
|
2789
|
+
error && (React__default["default"].createElement("div", { className: "Field__error", id: errorId },
|
|
2790
|
+
React__default["default"].createElement(Icon, { type: "caution" }),
|
|
2791
|
+
error)),
|
|
2792
|
+
React__default["default"].createElement(Field, tslib.__assign({ className: classNames__default["default"](className, {
|
|
2793
|
+
'Field__text-input': !multiline,
|
|
2794
|
+
Field__textarea: multiline,
|
|
2795
|
+
'Field--has-error': error
|
|
2796
|
+
}), id: inputId, value: isControlled ? value : uncontrolledValue, onChange: handleChange, "aria-invalid": !!error, required: required, ref: setFieldRef }, other, inputProps))));
|
|
2797
|
+
});
|
|
2798
|
+
TextField.displayName = 'TextField';
|
|
2833
2799
|
|
|
2834
2800
|
var TextFieldWrapper = React.forwardRef(function (_a, ref) {
|
|
2835
2801
|
var className = _a.className, children = _a.children, otherProps = tslib.__rest(_a, ["className", "children"]);
|
|
@@ -3766,7 +3732,7 @@ var Notice = React.forwardRef(function (_a, ref) {
|
|
|
3766
3732
|
_b["Notice--".concat(type)] = type,
|
|
3767
3733
|
_b["Notice--condensed"] = variant === 'condensed',
|
|
3768
3734
|
_b)), ref: ref }, otherProps),
|
|
3769
|
-
React__default["default"].createElement(Icon, { type: icon || iconTypeMap[type] }),
|
|
3735
|
+
React__default["default"].createElement(Icon, { className: "Notice__icon", type: icon || iconTypeMap[type] }),
|
|
3770
3736
|
React__default["default"].createElement("div", { className: "Notice__title" }, title),
|
|
3771
3737
|
children && React__default["default"].createElement("div", { className: "Notice__content" }, children)));
|
|
3772
3738
|
});
|
|
@@ -5604,45 +5570,6 @@ function collectDescendantKeys(node) {
|
|
|
5604
5570
|
function collectDisabledKeys(nodes) {
|
|
5605
5571
|
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
5572
|
}
|
|
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
5573
|
/**
|
|
5647
5574
|
* Apply react-aria's proposed selection while enforcing cascade. Each key
|
|
5648
5575
|
* react-aria added cascades to its descendants when `cascadeSelect` is set; each
|
|
@@ -5681,9 +5608,17 @@ function applyCascade(nodes, previous, next, selectionMode, _a) {
|
|
|
5681
5608
|
return result;
|
|
5682
5609
|
}
|
|
5683
5610
|
|
|
5611
|
+
/** Seeds the initial scroll math. Keep in step with `--tree-view-row-height`,
|
|
5612
|
+
* which sizes a virtualized row — see the spacing-parity test. */
|
|
5613
|
+
var ESTIMATED_ROW_HEIGHT = 36;
|
|
5614
|
+
/** Keep in step with `--space-quarter` / `--space-half`, which `.TreeView` uses
|
|
5615
|
+
* for its flex spacing — see the spacing-parity test. */
|
|
5616
|
+
var ROW_GAP = 2;
|
|
5617
|
+
var LIST_PADDING = 4;
|
|
5684
5618
|
var TreeView = React.forwardRef(function (_a, ref) {
|
|
5685
|
-
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, className = _a.className, other = tslib.__rest(_a, ["items", "onAction", "selectionMode", "cascadeSelect", "cascadeDeselect", "defaultExpandedKeys", "className"]);
|
|
5686
|
-
var
|
|
5619
|
+
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"]);
|
|
5620
|
+
var treeRef = useSharedRef(ref);
|
|
5621
|
+
var _f = tslib.__read(React.useState(new Set()), 2), selectedKeys = _f[0], setSelectedKeys = _f[1];
|
|
5687
5622
|
var cascade = { cascadeSelect: cascadeSelect, cascadeDeselect: cascadeDeselect };
|
|
5688
5623
|
// Cascade only applies to multiple selection.
|
|
5689
5624
|
var isCascade = selectionMode === 'multiple' && (cascadeSelect || cascadeDeselect);
|
|
@@ -5697,24 +5632,74 @@ var TreeView = React.forwardRef(function (_a, ref) {
|
|
|
5697
5632
|
: selection;
|
|
5698
5633
|
});
|
|
5699
5634
|
};
|
|
5700
|
-
//
|
|
5701
|
-
//
|
|
5702
|
-
|
|
5703
|
-
|
|
5704
|
-
|
|
5705
|
-
|
|
5706
|
-
|
|
5707
|
-
|
|
5708
|
-
|
|
5709
|
-
|
|
5635
|
+
// react-aria only reports a press as an action while nothing is selected, so
|
|
5636
|
+
// activation is driven here and react-aria is left to own selection. Click,
|
|
5637
|
+
// Space and Enter all do the same thing: toggle the checkbox and run the action.
|
|
5638
|
+
// Without selection react-aria handles the action itself (see the Tree props).
|
|
5639
|
+
React.useEffect(function () {
|
|
5640
|
+
var node = treeRef.current;
|
|
5641
|
+
if (!node || !onAction || selectionMode === 'none')
|
|
5642
|
+
return;
|
|
5643
|
+
var rowKey = function (target) {
|
|
5644
|
+
var _a;
|
|
5645
|
+
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]');
|
|
5646
|
+
if (!row || row.getAttribute('aria-disabled') === 'true')
|
|
5647
|
+
return null;
|
|
5648
|
+
return row.getAttribute('data-key');
|
|
5649
|
+
};
|
|
5650
|
+
var handleKeyDown = function (event) {
|
|
5651
|
+
if (event.key !== 'Enter' && event.key !== ' ')
|
|
5652
|
+
return;
|
|
5653
|
+
if (event.repeat || event.defaultPrevented)
|
|
5654
|
+
return;
|
|
5655
|
+
var key = rowKey(event.target);
|
|
5656
|
+
if (key)
|
|
5657
|
+
onAction(key);
|
|
5658
|
+
};
|
|
5659
|
+
var handleClick = function (event) {
|
|
5660
|
+
var _a;
|
|
5661
|
+
var target = event.target;
|
|
5662
|
+
// The chevron expands rather than activates, and a click on the
|
|
5663
|
+
// checkbox box or label is re-dispatched on the checkbox itself.
|
|
5664
|
+
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'))
|
|
5665
|
+
return;
|
|
5666
|
+
var key = rowKey(target);
|
|
5667
|
+
if (key)
|
|
5668
|
+
onAction(key);
|
|
5669
|
+
};
|
|
5670
|
+
node.addEventListener('keydown', handleKeyDown);
|
|
5671
|
+
node.addEventListener('click', handleClick);
|
|
5672
|
+
return function () {
|
|
5673
|
+
node.removeEventListener('keydown', handleKeyDown);
|
|
5674
|
+
node.removeEventListener('click', handleClick);
|
|
5675
|
+
};
|
|
5676
|
+
}, [onAction, selectionMode, virtualized]);
|
|
5710
5677
|
// Disabled nodes are non-selectable; react-aria disables them via disabledKeys.
|
|
5711
5678
|
var disabledKeys = React.useMemo(function () { return collectDisabledKeys(items); }, [items]);
|
|
5712
|
-
//
|
|
5713
|
-
//
|
|
5714
|
-
|
|
5679
|
+
// Always control selection: react-aria's own state is lost if the tree
|
|
5680
|
+
// remounts (which toggling `virtualized` does), taking the user's checkboxes
|
|
5681
|
+
// with it.
|
|
5682
|
+
var selectionProps = selectionMode !== 'none'
|
|
5715
5683
|
? { selectedKeys: selectedKeys, onSelectionChange: handleSelectionChange }
|
|
5716
5684
|
: {};
|
|
5717
|
-
|
|
5685
|
+
// The `height` prop outranks `style.height`, but only when it is actually
|
|
5686
|
+
// set — spreading an undefined `height` would wipe the caller's own.
|
|
5687
|
+
var mergedStyle = virtualized && height !== undefined ? tslib.__assign(tslib.__assign({}, style), { height: height }) : style;
|
|
5688
|
+
var tree = (React__default["default"].createElement(reactAriaComponents.Tree, tslib.__assign({ ref: treeRef, className: classNames__default["default"]('TreeView', className, {
|
|
5689
|
+
'TreeView--virtualized': virtualized
|
|
5690
|
+
}), selectionMode: selectionMode, defaultExpandedKeys: defaultExpandedKeys }, (disabledKeys.length > 0 ? { disabledKeys: disabledKeys } : {}), (onAction && selectionMode === 'none'
|
|
5691
|
+
? { onAction: function (key) { return onAction(String(key)); } }
|
|
5692
|
+
: {}), selectionProps, other, { style: mergedStyle }), items.map(function (item) { return (React__default["default"].createElement(TreeViewItem, tslib.__assign({ key: item.id }, item))); })));
|
|
5693
|
+
// Rows are absolutely positioned here, so the list layout owns their spacing
|
|
5694
|
+
// rather than `.TreeView`'s flex `gap`/`padding`.
|
|
5695
|
+
if (virtualized) {
|
|
5696
|
+
return (React__default["default"].createElement(reactAriaComponents.Virtualizer, { layout: reactAriaComponents.ListLayout, layoutOptions: {
|
|
5697
|
+
estimatedRowHeight: ESTIMATED_ROW_HEIGHT,
|
|
5698
|
+
gap: ROW_GAP,
|
|
5699
|
+
padding: LIST_PADDING
|
|
5700
|
+
} }, tree));
|
|
5701
|
+
}
|
|
5702
|
+
return tree;
|
|
5718
5703
|
});
|
|
5719
5704
|
TreeView.displayName = 'TreeView';
|
|
5720
5705
|
|
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.c59590bf",
|
|
4
4
|
"license": "MPL-2.0",
|
|
5
5
|
"description": "Fully accessible react components library for Deque Cauldron",
|
|
6
6
|
"homepage": "https://cauldron.dequelabs.com/",
|
|
@@ -14,12 +14,12 @@
|
|
|
14
14
|
"lib/"
|
|
15
15
|
],
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@floating-ui/dom": "^1.
|
|
17
|
+
"@floating-ui/dom": "^1.8.0",
|
|
18
18
|
"@floating-ui/react-dom": "^2.1.2",
|
|
19
19
|
"classnames": "^2.2.6",
|
|
20
20
|
"focusable": "^2.3.0",
|
|
21
21
|
"keyname": "^0.1.0",
|
|
22
|
-
"react-aria-components": "^1.
|
|
22
|
+
"react-aria-components": "^1.21.1",
|
|
23
23
|
"react-id-generator": "^3.0.1",
|
|
24
24
|
"react-syntax-highlighter": "^16.1.1",
|
|
25
25
|
"tslib": "^2.4.0"
|
|
@@ -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",
|