@rainbow-oh/yee-c 0.8.0 → 0.8.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/LICENSE +1 -1
- package/README.md +40 -25
- package/dist/cjs/Card/card.js +7 -3
- package/dist/cjs/Carousel/carousel-item.js +7 -2
- package/dist/cjs/Carousel/carousel.js +31 -4
- package/dist/cjs/Cascader/cascader.js +1 -1
- package/dist/cjs/Cascader/column.js +1 -1
- package/dist/cjs/Cascader/node.js +16 -4
- package/dist/cjs/Cascader/search-list.js +13 -4
- package/dist/cjs/Checkbox/checkbox-group.js +1 -1
- package/dist/cjs/Checkbox/checkbox.js +6 -3
- package/dist/cjs/Collapse/panel.js +10 -1
- package/dist/cjs/Dialog/dialog.js +22 -7
- package/dist/cjs/Drawer/drawer.js +14 -5
- package/dist/cjs/Menu/menu-item.js +14 -5
- package/dist/cjs/Menu/menu.js +10 -2
- package/dist/cjs/Pagination/items.js +10 -5
- package/dist/cjs/Pagination/pagination.js +9 -3
- package/dist/cjs/Radio/radio-group.js +6 -5
- package/dist/cjs/Radio/radio.js +39 -29
- package/dist/cjs/Rate/rate.js +6 -1
- package/dist/cjs/Rate/star.js +7 -3
- package/dist/cjs/Steps/step.js +7 -5
- package/dist/cjs/Steps/steps.js +1 -1
- package/dist/cjs/Tabs/tab-content.js +3 -1
- package/dist/cjs/Tabs/tab-header/index.js +3 -1
- package/dist/cjs/Tabs/tab-header/tab-header-title.js +3 -1
- package/dist/cjs/hooks/useDelayState.js +3 -2
- package/dist/cjs/hooks/useFocusManage.d.ts +1 -1
- package/dist/cjs/hooks/useFocusManage.js +27 -22
- package/dist/cjs/style/themes.css +1 -1
- package/dist/cjs/style/variables.css +1 -1
- package/dist/cjs/utils/focusStack.d.ts +6 -2
- package/dist/cjs/utils/focusStack.js +40 -11
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/esm/Card/card.js +7 -3
- package/dist/esm/Carousel/carousel-item.js +7 -2
- package/dist/esm/Carousel/carousel.js +31 -4
- package/dist/esm/Cascader/cascader.js +3 -1
- package/dist/esm/Cascader/column.js +2 -1
- package/dist/esm/Cascader/node.js +18 -4
- package/dist/esm/Cascader/search-list.js +18 -4
- package/dist/esm/Checkbox/checkbox-group.js +3 -1
- package/dist/esm/Checkbox/checkbox.js +6 -3
- package/dist/esm/Collapse/panel.js +11 -2
- package/dist/esm/Dialog/dialog.js +26 -9
- package/dist/esm/Drawer/drawer.js +16 -7
- package/dist/esm/Menu/menu-item.js +16 -5
- package/dist/esm/Menu/menu.js +11 -5
- package/dist/esm/Pagination/items.js +14 -5
- package/dist/esm/Pagination/pagination.js +16 -4
- package/dist/esm/Radio/radio-group.js +5 -4
- package/dist/esm/Radio/radio.js +5 -4
- package/dist/esm/Rate/rate.js +6 -1
- package/dist/esm/Rate/star.js +12 -4
- package/dist/esm/Steps/step.js +12 -6
- package/dist/esm/Steps/steps.js +3 -1
- package/dist/esm/Tabs/tab-content.js +3 -1
- package/dist/esm/Tabs/tab-header/index.js +3 -1
- package/dist/esm/Tabs/tab-header/tab-header-title.js +3 -1
- package/dist/esm/hooks/useDelayState.js +5 -2
- package/dist/esm/hooks/useFocusManage.d.ts +1 -1
- package/dist/esm/hooks/useFocusManage.js +31 -13
- package/dist/esm/style/themes.css +1 -1
- package/dist/esm/style/variables.css +1 -1
- package/dist/esm/utils/focusStack.d.ts +6 -2
- package/dist/esm/utils/focusStack.js +37 -14
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/umd/yee-c.min.js +1 -1
- package/package.json +10 -6
- package/src/Card/card.tsx +5 -1
- package/src/Carousel/carousel-item.tsx +7 -1
- package/src/Carousel/carousel.tsx +30 -3
- package/src/Cascader/cascader.tsx +1 -1
- package/src/Cascader/column.tsx +1 -1
- package/src/Cascader/node.tsx +14 -2
- package/src/Cascader/search-list.tsx +11 -2
- package/src/Checkbox/checkbox-group.tsx +1 -1
- package/src/Checkbox/checkbox.tsx +3 -0
- package/src/Collapse/panel.tsx +11 -1
- package/src/Dialog/dialog.tsx +31 -6
- package/src/Drawer/drawer.tsx +12 -3
- package/src/Menu/menu-item.tsx +12 -3
- package/src/Menu/menu.tsx +11 -5
- package/src/Pagination/items.tsx +9 -4
- package/src/Pagination/pagination.tsx +10 -4
- package/src/Radio/radio-group.tsx +2 -1
- package/src/Radio/radio.tsx +7 -2
- package/src/Rate/rate.tsx +5 -0
- package/src/Rate/star.tsx +8 -4
- package/src/Steps/step.tsx +15 -5
- package/src/Steps/steps.tsx +1 -1
- package/src/Tabs/tab-content.tsx +2 -0
- package/src/Tabs/tab-header/index.tsx +2 -0
- package/src/Tabs/tab-header/tab-header-title.tsx +3 -1
- package/src/hooks/useDelayState.ts +4 -2
- package/src/hooks/useFocusManage.ts +33 -17
- package/src/utils/focusStack.ts +55 -12
- package/src/version.ts +1 -1
package/dist/esm/Radio/radio.js
CHANGED
|
@@ -70,7 +70,8 @@ var Radio = /*#__PURE__*/React.forwardRef(function (baseprops, ref) {
|
|
|
70
70
|
return /*#__PURE__*/React.createElement("label", {
|
|
71
71
|
className: cls,
|
|
72
72
|
style: style,
|
|
73
|
-
onClick: handleClick
|
|
73
|
+
onClick: handleClick,
|
|
74
|
+
"aria-disabled": disabled || undefined
|
|
74
75
|
}, /*#__PURE__*/React.createElement("span", {
|
|
75
76
|
className: clsx(prefixCls, _defineProperty({}, "".concat(prefixCls, "-disabled"), disabled))
|
|
76
77
|
}, /*#__PURE__*/React.createElement("input", _extends({}, rest, {
|
|
@@ -81,11 +82,11 @@ var Radio = /*#__PURE__*/React.forwardRef(function (baseprops, ref) {
|
|
|
81
82
|
value: value,
|
|
82
83
|
checked: mergedChecked,
|
|
83
84
|
disabled: disabled,
|
|
84
|
-
onChange: handleChange
|
|
85
|
-
"aria-checked": mergedChecked
|
|
85
|
+
onChange: handleChange
|
|
86
86
|
})), !buttonStyle && /*#__PURE__*/React.createElement("span", {
|
|
87
87
|
className: clsx("".concat(prefixCls, "-inner"), classNames === null || classNames === void 0 ? void 0 : classNames.inner),
|
|
88
|
-
style: styles === null || styles === void 0 ? void 0 : styles.inner
|
|
88
|
+
style: styles === null || styles === void 0 ? void 0 : styles.inner,
|
|
89
|
+
"aria-hidden": "true"
|
|
89
90
|
})), /*#__PURE__*/React.createElement("span", {
|
|
90
91
|
className: clsx("".concat(prefixCls, "-label"), classNames === null || classNames === void 0 ? void 0 : classNames.label),
|
|
91
92
|
style: styles === null || styles === void 0 ? void 0 : styles.label
|
package/dist/esm/Rate/rate.js
CHANGED
|
@@ -107,7 +107,12 @@ var Rate = /*#__PURE__*/React.forwardRef(function (baseprops, ref) {
|
|
|
107
107
|
onMouseLeave: onLeave,
|
|
108
108
|
ref: componentRef,
|
|
109
109
|
role: "radiogroup",
|
|
110
|
-
"aria-label": "Rating"
|
|
110
|
+
"aria-label": "Rating",
|
|
111
|
+
"aria-disabled": disabled || undefined,
|
|
112
|
+
"aria-valuemin": 0,
|
|
113
|
+
"aria-valuemax": count,
|
|
114
|
+
"aria-valuenow": mergedValue,
|
|
115
|
+
"aria-valuetext": "".concat(mergedValue, " out of ").concat(count, " stars")
|
|
111
116
|
}), Array(count).fill(0).map(function (_, index) {
|
|
112
117
|
var cls = clsx("".concat(prefixCls, "-star"), _defineProperty(_defineProperty({}, "".concat(prefixCls, "-star-full"), index < mergedValue), "".concat(prefixCls, "-star-half-active"), allowHalf && index + 0.5 === mergedValue));
|
|
113
118
|
return /*#__PURE__*/React.createElement(Star, {
|
package/dist/esm/Rate/star.js
CHANGED
|
@@ -35,6 +35,7 @@ var Star = function Star(props) {
|
|
|
35
35
|
"aria-checked": active,
|
|
36
36
|
"aria-posinset": index + 1,
|
|
37
37
|
"aria-setsize": count,
|
|
38
|
+
"aria-label": "".concat(index + 1, " ").concat(index + 1 === 1 ? 'star' : 'stars'),
|
|
38
39
|
key: 'star-' + index
|
|
39
40
|
}, /*#__PURE__*/React.createElement("div", {
|
|
40
41
|
className: "".concat(prefixCls, "-star-first"),
|
|
@@ -48,11 +49,13 @@ var Star = function Star(props) {
|
|
|
48
49
|
}
|
|
49
50
|
},
|
|
50
51
|
tabIndex: 0,
|
|
52
|
+
"aria-label": "".concat(index + 0.5, " stars"),
|
|
51
53
|
key: 'star-' + index + 'left'
|
|
52
54
|
}, character ? /*#__PURE__*/React.createElement("span", {
|
|
53
55
|
className: "".concat(prefixCls, "-character")
|
|
54
56
|
}, renderCharacter()) : /*#__PURE__*/React.createElement(StarHalf, {
|
|
55
|
-
className: "".concat(prefixCls, "-star-half")
|
|
57
|
+
className: "".concat(prefixCls, "-star-half"),
|
|
58
|
+
"aria-hidden": "true"
|
|
56
59
|
})), /*#__PURE__*/React.createElement("div", {
|
|
57
60
|
className: "".concat(prefixCls, "-star-second"),
|
|
58
61
|
onMouseMove: onSecondHover,
|
|
@@ -65,11 +68,13 @@ var Star = function Star(props) {
|
|
|
65
68
|
}
|
|
66
69
|
},
|
|
67
70
|
tabIndex: 0,
|
|
71
|
+
"aria-label": "".concat(index + 1, " ").concat(index + 1 === 1 ? 'star' : 'stars'),
|
|
68
72
|
key: 'star-' + index + 'right'
|
|
69
73
|
}, character ? /*#__PURE__*/React.createElement("span", {
|
|
70
74
|
className: "".concat(prefixCls, "-character")
|
|
71
75
|
}, renderCharacter()) : /*#__PURE__*/React.createElement(StarFull, {
|
|
72
|
-
className: "".concat(prefixCls, "-star-full")
|
|
76
|
+
className: "".concat(prefixCls, "-star-full"),
|
|
77
|
+
"aria-hidden": "true"
|
|
73
78
|
}))) : /*#__PURE__*/React.createElement("li", {
|
|
74
79
|
className: className,
|
|
75
80
|
onClick: function onClick() {
|
|
@@ -88,13 +93,16 @@ var Star = function Star(props) {
|
|
|
88
93
|
"aria-checked": active,
|
|
89
94
|
"aria-posinset": index + 1,
|
|
90
95
|
"aria-setsize": count,
|
|
96
|
+
"aria-label": "".concat(index + 1, " ").concat(index + 1 === 1 ? 'star' : 'stars'),
|
|
91
97
|
key: 'star-' + index
|
|
92
98
|
}, character ? /*#__PURE__*/React.createElement("span", {
|
|
93
99
|
className: "".concat(prefixCls, "-character")
|
|
94
100
|
}, renderCharacter()) : active ? /*#__PURE__*/React.createElement(StarFull, {
|
|
95
|
-
className: "".concat(prefixCls, "-star-active")
|
|
101
|
+
className: "".concat(prefixCls, "-star-active"),
|
|
102
|
+
"aria-hidden": "true"
|
|
96
103
|
}) : /*#__PURE__*/React.createElement(StarFull, {
|
|
97
|
-
className: "".concat(prefixCls, "-star-inactive")
|
|
104
|
+
className: "".concat(prefixCls, "-star-inactive"),
|
|
105
|
+
"aria-hidden": "true"
|
|
98
106
|
})), children ? /*#__PURE__*/React.createElement(Tooltip, {
|
|
99
107
|
title: value,
|
|
100
108
|
placement: "top"
|
package/dist/esm/Steps/step.js
CHANGED
|
@@ -37,6 +37,7 @@ var Step = function Step(props) {
|
|
|
37
37
|
}
|
|
38
38
|
};
|
|
39
39
|
var mergedStatus = (_ref = itemStatus !== null && itemStatus !== void 0 ? itemStatus : status) !== null && _ref !== void 0 ? _ref : index < current ? 'finish' : index === current ? 'process' : 'wait';
|
|
40
|
+
var statusLabel = mergedStatus === 'finish' ? 'completed' : mergedStatus === 'process' ? 'in progress' : mergedStatus === 'error' ? 'error' : 'pending';
|
|
40
41
|
var renderIcon = useMemo(function () {
|
|
41
42
|
if (dot) return /*#__PURE__*/React.createElement("span", {
|
|
42
43
|
className: "".concat(prefixCls, "-item-dot")
|
|
@@ -64,18 +65,21 @@ var Step = function Step(props) {
|
|
|
64
65
|
var cls = clsx("".concat(prefixCls, "-item"), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, "".concat(prefixCls, "-item-").concat(mergedStatus), mergedStatus), "".concat(prefixCls, "-item-active"), index === current), "".concat(prefixCls, "-item-click"), onChange), "".concat(prefixCls, "-item-disabled"), disabled), "".concat(prefixCls, "-item-has-cus-icon"), icon), className);
|
|
65
66
|
var ribbonStatus = index < current ? 'done' : index === current ? 'doing' : 'undo';
|
|
66
67
|
return /*#__PURE__*/React.createElement(React.Fragment, null, type === 'ribbon' && /*#__PURE__*/React.createElement("div", {
|
|
67
|
-
className: "".concat(prefixCls, "-item-ribbon-end ").concat(ribbonStatus)
|
|
68
|
+
className: "".concat(prefixCls, "-item-ribbon-end ").concat(ribbonStatus),
|
|
69
|
+
"aria-hidden": "true"
|
|
68
70
|
}), /*#__PURE__*/React.createElement("div", {
|
|
69
71
|
className: cls,
|
|
70
72
|
style: style,
|
|
71
73
|
onClick: handleClick,
|
|
72
74
|
onKeyDown: handleKeyDown,
|
|
73
75
|
tabIndex: disabled ? -1 : onChange ? 0 : undefined,
|
|
74
|
-
role: onChange ? 'button' :
|
|
76
|
+
role: onChange ? 'button' : 'listitem',
|
|
75
77
|
"aria-disabled": disabled,
|
|
76
|
-
"aria-current": index === current ? 'step' : undefined
|
|
78
|
+
"aria-current": index === current ? 'step' : undefined,
|
|
79
|
+
"aria-label": "Step ".concat(index + 1).concat(typeof title === 'string' ? ": ".concat(title) : '', ", ").concat(statusLabel)
|
|
77
80
|
}, /*#__PURE__*/React.createElement("div", {
|
|
78
|
-
className: "".concat(prefixCls, "-item-icon")
|
|
81
|
+
className: "".concat(prefixCls, "-item-icon"),
|
|
82
|
+
"aria-hidden": "true"
|
|
79
83
|
}, renderIcon), /*#__PURE__*/React.createElement("div", {
|
|
80
84
|
className: "".concat(prefixCls, "-item-content")
|
|
81
85
|
}, /*#__PURE__*/React.createElement("div", {
|
|
@@ -87,9 +91,11 @@ var Step = function Step(props) {
|
|
|
87
91
|
}, subTitle)), type !== 'ribbon' && description && /*#__PURE__*/React.createElement("div", {
|
|
88
92
|
className: "".concat(prefixCls, "-item-description")
|
|
89
93
|
}, description))), type === 'navigation' && /*#__PURE__*/React.createElement("div", {
|
|
90
|
-
className: "".concat(prefixCls, "-item-navi-arrow")
|
|
94
|
+
className: "".concat(prefixCls, "-item-navi-arrow"),
|
|
95
|
+
"aria-hidden": "true"
|
|
91
96
|
}, /*#__PURE__*/React.createElement(ChevronRight, null)), type === 'ribbon' && /*#__PURE__*/React.createElement("div", {
|
|
92
|
-
className: "".concat(prefixCls, "-item-ribbon-head ").concat(ribbonStatus)
|
|
97
|
+
className: "".concat(prefixCls, "-item-ribbon-head ").concat(ribbonStatus),
|
|
98
|
+
"aria-hidden": "true"
|
|
93
99
|
}));
|
|
94
100
|
};
|
|
95
101
|
export default Step;
|
package/dist/esm/Steps/steps.js
CHANGED
|
@@ -64,7 +64,9 @@ var Steps = /*#__PURE__*/forwardRef(function (baseprops, ref) {
|
|
|
64
64
|
return /*#__PURE__*/React.createElement("div", _extends({}, rest, {
|
|
65
65
|
className: cls,
|
|
66
66
|
style: style,
|
|
67
|
-
ref: ref
|
|
67
|
+
ref: ref,
|
|
68
|
+
role: "list",
|
|
69
|
+
"aria-label": "Steps"
|
|
68
70
|
}), /*#__PURE__*/React.createElement(StepsContext.Provider, {
|
|
69
71
|
value: contextValue
|
|
70
72
|
}, renderSteps()));
|
|
@@ -73,9 +73,11 @@ var TabContent = function TabContent(_ref) {
|
|
|
73
73
|
display: activeKey === key ? 'block' : 'none'
|
|
74
74
|
},
|
|
75
75
|
key: key,
|
|
76
|
+
id: "tabpanel-".concat(key),
|
|
76
77
|
role: "tabpanel",
|
|
77
78
|
"aria-labelledby": "tab-".concat(key),
|
|
78
|
-
"aria-hidden": activeKey !== key
|
|
79
|
+
"aria-hidden": activeKey !== key,
|
|
80
|
+
tabIndex: activeKey === key ? 0 : -1
|
|
79
81
|
}, children);
|
|
80
82
|
}));
|
|
81
83
|
};
|
|
@@ -129,7 +129,9 @@ var TabHeader = function TabHeader(props) {
|
|
|
129
129
|
}, /*#__PURE__*/React.createElement("div", {
|
|
130
130
|
className: clsx("".concat(prefixCls, "-nav-list"), classNames === null || classNames === void 0 ? void 0 : classNames.list),
|
|
131
131
|
style: styles === null || styles === void 0 ? void 0 : styles.list,
|
|
132
|
-
ref: navList
|
|
132
|
+
ref: navList,
|
|
133
|
+
role: "tablist",
|
|
134
|
+
"aria-orientation": direction
|
|
133
135
|
}, items === null || items === void 0 ? void 0 : items.map(function (item, index) {
|
|
134
136
|
return /*#__PURE__*/React.createElement(TabHeaderTitle, _extends({}, item, {
|
|
135
137
|
$key: item.key,
|
|
@@ -149,10 +149,12 @@ var TabHeaderTitle = function TabHeaderTitle(props) {
|
|
|
149
149
|
return /*#__PURE__*/React.createElement("div", _extends({}, rest, {
|
|
150
150
|
ref: tabRef,
|
|
151
151
|
role: "tab",
|
|
152
|
+
id: "tab-".concat($key),
|
|
152
153
|
"aria-selected": activeKey === $key,
|
|
153
154
|
"aria-disabled": disabled,
|
|
155
|
+
"aria-controls": "tabpanel-".concat($key),
|
|
154
156
|
className: cls,
|
|
155
|
-
tabIndex: disabled ? -1 : 0,
|
|
157
|
+
tabIndex: disabled ? -1 : activeKey === $key ? 0 : -1,
|
|
156
158
|
onClick: handleTabClick,
|
|
157
159
|
onKeyDown: handleKeyDown
|
|
158
160
|
}), icon && /*#__PURE__*/React.createElement("span", {
|
|
@@ -12,9 +12,12 @@ export default function useDelayState(state) {
|
|
|
12
12
|
delayState = _useState2[0],
|
|
13
13
|
setDelayState = _useState2[1];
|
|
14
14
|
useEffect(function () {
|
|
15
|
-
setTimeout(function () {
|
|
15
|
+
var timer = window.setTimeout(function () {
|
|
16
16
|
setDelayState(state);
|
|
17
17
|
}, delay * 1000);
|
|
18
|
-
|
|
18
|
+
return function () {
|
|
19
|
+
return window.clearTimeout(timer);
|
|
20
|
+
};
|
|
21
|
+
}, [delay, state]);
|
|
19
22
|
return delayState;
|
|
20
23
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export default function useFocusManage(
|
|
1
|
+
export default function useFocusManage(element: HTMLElement | null, open: boolean): void;
|
|
@@ -1,17 +1,35 @@
|
|
|
1
|
-
import { useEffect } from 'react';
|
|
1
|
+
import { useEffect, useRef } from 'react';
|
|
2
2
|
import { popFocus, pushFocus } from "../utils/focusStack";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var
|
|
3
|
+
export default function useFocusManage(element, open) {
|
|
4
|
+
var entryRef = useRef(null);
|
|
5
|
+
var previousFocusRef = useRef(null);
|
|
6
|
+
var openCycleRef = useRef(false);
|
|
7
|
+
var releaseEntry = function releaseEntry() {
|
|
8
|
+
if (entryRef.current) {
|
|
9
|
+
popFocus(entryRef.current);
|
|
10
|
+
entryRef.current = null;
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
var endOpenCycle = function endOpenCycle() {
|
|
14
|
+
releaseEntry();
|
|
15
|
+
previousFocusRef.current = null;
|
|
16
|
+
openCycleRef.current = false;
|
|
17
|
+
};
|
|
18
|
+
useEffect(function () {
|
|
19
|
+
if (open && !openCycleRef.current) {
|
|
20
|
+
openCycleRef.current = true;
|
|
21
|
+
previousFocusRef.current = document.activeElement;
|
|
22
|
+
} else if (!open && openCycleRef.current) {
|
|
23
|
+
endOpenCycle();
|
|
24
|
+
}
|
|
25
|
+
}, [open]);
|
|
6
26
|
useEffect(function () {
|
|
7
|
-
if (!
|
|
8
|
-
|
|
9
|
-
pushFocus(ele);
|
|
10
|
-
} else {
|
|
11
|
-
popFocus();
|
|
27
|
+
if (!open || !openCycleRef.current || !element || entryRef.current) {
|
|
28
|
+
return;
|
|
12
29
|
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
30
|
+
entryRef.current = pushFocus(element, previousFocusRef.current);
|
|
31
|
+
}, [element, open]);
|
|
32
|
+
useEffect(function () {
|
|
33
|
+
return releaseEntry;
|
|
34
|
+
}, []);
|
|
17
35
|
}
|
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
type Focusable = HTMLElement | null;
|
|
2
|
-
export
|
|
3
|
-
|
|
2
|
+
export interface FocusStackEntry {
|
|
3
|
+
container: HTMLElement;
|
|
4
|
+
previous: Focusable;
|
|
5
|
+
}
|
|
6
|
+
export declare const pushFocus: (container: HTMLElement, previous?: Focusable) => FocusStackEntry;
|
|
7
|
+
export declare const popFocus: (entry: FocusStackEntry) => void;
|
|
4
8
|
export {};
|
|
@@ -1,20 +1,43 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
var focusableSelector = ['a[href]', 'button:not([disabled])', 'textarea:not([disabled])', 'input:not([disabled])', 'select:not([disabled])', 'details', '[tabindex]:not([tabindex="-1"])'].join(',');
|
|
3
2
|
var stack = [];
|
|
4
3
|
var raf = 0;
|
|
5
|
-
var schedule = function schedule(
|
|
4
|
+
var schedule = function schedule(callback) {
|
|
6
5
|
cancelAnimationFrame(raf);
|
|
7
|
-
raf = requestAnimationFrame(
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
raf = requestAnimationFrame(callback);
|
|
7
|
+
};
|
|
8
|
+
var focusInitialElement = function focusInitialElement(entry) {
|
|
9
|
+
if (stack[stack.length - 1] !== entry || !entry.container.isConnected) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
var activeElement = document.activeElement;
|
|
13
|
+
if (activeElement && entry.container.contains(activeElement)) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
var firstFocusable = entry.container.querySelector(focusableSelector);
|
|
17
|
+
(firstFocusable !== null && firstFocusable !== void 0 ? firstFocusable : entry.container).focus();
|
|
10
18
|
};
|
|
11
|
-
export var pushFocus = function pushFocus(
|
|
12
|
-
var
|
|
13
|
-
|
|
14
|
-
|
|
19
|
+
export var pushFocus = function pushFocus(container) {
|
|
20
|
+
var previous = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : document.activeElement;
|
|
21
|
+
var entry = {
|
|
22
|
+
container: container,
|
|
23
|
+
previous: previous
|
|
24
|
+
};
|
|
25
|
+
stack.push(entry);
|
|
26
|
+
schedule(function () {
|
|
27
|
+
return focusInitialElement(entry);
|
|
28
|
+
});
|
|
29
|
+
return entry;
|
|
15
30
|
};
|
|
16
|
-
export var popFocus = function popFocus() {
|
|
17
|
-
var
|
|
18
|
-
if (
|
|
19
|
-
|
|
31
|
+
export var popFocus = function popFocus(entry) {
|
|
32
|
+
var index = stack.lastIndexOf(entry);
|
|
33
|
+
if (index === -1) return;
|
|
34
|
+
var isTopEntry = index === stack.length - 1;
|
|
35
|
+
stack.splice(index, 1);
|
|
36
|
+
if (!isTopEntry) return;
|
|
37
|
+
schedule(function () {
|
|
38
|
+
var _entry$previous;
|
|
39
|
+
if ((_entry$previous = entry.previous) !== null && _entry$previous !== void 0 && _entry$previous.isConnected) {
|
|
40
|
+
entry.previous.focus();
|
|
41
|
+
}
|
|
42
|
+
});
|
|
20
43
|
};
|
package/dist/esm/version.d.ts
CHANGED
package/dist/esm/version.js
CHANGED