@workday/canvas-kit-react 11.2.1 → 11.2.3
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/common/lib/utils/elements.ts +32 -10
- package/dist/commonjs/common/lib/utils/elements.d.ts +11 -1
- package/dist/commonjs/common/lib/utils/elements.d.ts.map +1 -1
- package/dist/commonjs/common/lib/utils/elements.js +30 -11
- package/dist/commonjs/popup/lib/hooks/useReturnFocus.d.ts.map +1 -1
- package/dist/commonjs/popup/lib/hooks/useReturnFocus.js +2 -1
- package/dist/commonjs/select/lib/Select.d.ts +114 -57
- package/dist/commonjs/select/lib/Select.d.ts.map +1 -1
- package/dist/commonjs/select/lib/Select.js +2 -2
- package/dist/es6/common/lib/utils/elements.d.ts +11 -1
- package/dist/es6/common/lib/utils/elements.d.ts.map +1 -1
- package/dist/es6/common/lib/utils/elements.js +28 -9
- package/dist/es6/popup/lib/hooks/useReturnFocus.d.ts.map +1 -1
- package/dist/es6/popup/lib/hooks/useReturnFocus.js +2 -1
- package/dist/es6/select/lib/Select.d.ts +114 -57
- package/dist/es6/select/lib/Select.d.ts.map +1 -1
- package/dist/es6/select/lib/Select.js +2 -2
- package/package.json +4 -4
- package/popup/lib/hooks/useReturnFocus.tsx +6 -1
- package/select/lib/Select.tsx +0 -1
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
* Is an element focusable? This function performs various tests to see if the element in question
|
|
3
|
-
* can receive focus. Should skip disabled elements as they are not focusable.
|
|
4
|
-
*/
|
|
5
|
-
export const isFocusable = (element: Element): boolean => {
|
|
1
|
+
const isBaseFocusable = (element: Element): boolean => {
|
|
6
2
|
if (element.hasAttribute('disabled')) {
|
|
7
3
|
return false;
|
|
8
4
|
}
|
|
@@ -12,9 +8,15 @@ export const isFocusable = (element: Element): boolean => {
|
|
|
12
8
|
const validAnchor = nodeName === 'a' && element.hasAttribute('href');
|
|
13
9
|
const validAudioVideo = ['audio', 'video'].includes(nodeName) && element.hasAttribute('controls');
|
|
14
10
|
const validImgObject = ['img', 'object'].includes(nodeName) && element.hasAttribute('usemap');
|
|
15
|
-
const validNativelyFocusable =
|
|
16
|
-
|
|
17
|
-
|
|
11
|
+
const validNativelyFocusable = [
|
|
12
|
+
'button',
|
|
13
|
+
'details',
|
|
14
|
+
'embed',
|
|
15
|
+
'iframe',
|
|
16
|
+
'select',
|
|
17
|
+
'textarea',
|
|
18
|
+
].includes(nodeName);
|
|
19
|
+
|
|
18
20
|
const hasTabIndex = element.getAttribute('tabindex') === '0';
|
|
19
21
|
|
|
20
22
|
return (
|
|
@@ -27,6 +29,26 @@ export const isFocusable = (element: Element): boolean => {
|
|
|
27
29
|
);
|
|
28
30
|
};
|
|
29
31
|
|
|
32
|
+
/**
|
|
33
|
+
* Is an element focusable? This function performs various tests to see if the element in question
|
|
34
|
+
* can receive focus via a pointer. Should skip disabled elements as they are not focusable.
|
|
35
|
+
*/
|
|
36
|
+
export const isMouseFocusable = isBaseFocusable;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Is an element focusable? This function performs various tests to see if the element in question
|
|
40
|
+
* can receive focus via the keyboard. Should skip disabled elements as they are not focusable.
|
|
41
|
+
*/
|
|
42
|
+
export const isKeyboardFocusable = (element: Element): boolean => {
|
|
43
|
+
return isBaseFocusable(element) && element.getAttribute('tabindex') !== '-1';
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* @deprecated Use `isMouseFocusable` for mouse events and `isKeyboardFocusable` for keyboard
|
|
48
|
+
* events. `isFocusable` is an alias to `isKeyboardFocusable`
|
|
49
|
+
*/
|
|
50
|
+
export const isFocusable = isKeyboardFocusable;
|
|
51
|
+
|
|
30
52
|
/**
|
|
31
53
|
* Get the first focusable element in a container.
|
|
32
54
|
*
|
|
@@ -39,7 +61,7 @@ export const getFirstFocusableElement = (
|
|
|
39
61
|
|
|
40
62
|
for (let i = 0; i < elements.length; i++) {
|
|
41
63
|
const element = elements.item(i);
|
|
42
|
-
if (element &&
|
|
64
|
+
if (element && isKeyboardFocusable(element) && element.getAttribute('tabindex') !== '-1') {
|
|
43
65
|
if (isRadioInput(element)) {
|
|
44
66
|
const radioGroup = getRadioGroup(container, element);
|
|
45
67
|
|
|
@@ -73,7 +95,7 @@ export const getLastFocusableElement = (container: HTMLElement): Element[] | Ele
|
|
|
73
95
|
|
|
74
96
|
for (let i = elements.length - 1; i >= 0; i--) {
|
|
75
97
|
const element = elements.item(i);
|
|
76
|
-
if (element &&
|
|
98
|
+
if (element && isKeyboardFocusable(element) && element.getAttribute('tabindex') !== '-1') {
|
|
77
99
|
if (isRadioInput(element)) {
|
|
78
100
|
const radioGroup = getRadioGroup(container, element);
|
|
79
101
|
|
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Is an element focusable? This function performs various tests to see if the element in question
|
|
3
|
-
* can receive focus. Should skip disabled elements as they are not focusable.
|
|
3
|
+
* can receive focus via a pointer. Should skip disabled elements as they are not focusable.
|
|
4
|
+
*/
|
|
5
|
+
export declare const isMouseFocusable: (element: Element) => boolean;
|
|
6
|
+
/**
|
|
7
|
+
* Is an element focusable? This function performs various tests to see if the element in question
|
|
8
|
+
* can receive focus via the keyboard. Should skip disabled elements as they are not focusable.
|
|
9
|
+
*/
|
|
10
|
+
export declare const isKeyboardFocusable: (element: Element) => boolean;
|
|
11
|
+
/**
|
|
12
|
+
* @deprecated Use `isMouseFocusable` for mouse events and `isKeyboardFocusable` for keyboard
|
|
13
|
+
* events. `isFocusable` is an alias to `isKeyboardFocusable`
|
|
4
14
|
*/
|
|
5
15
|
export declare const isFocusable: (element: Element) => boolean;
|
|
6
16
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"elements.d.ts","sourceRoot":"","sources":["../../../../../common/lib/utils/elements.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"elements.d.ts","sourceRoot":"","sources":["../../../../../common/lib/utils/elements.ts"],"names":[],"mappings":"AA+BA;;;GAGG;AACH,eAAO,MAAM,gBAAgB,YAnCK,OAAO,KAAG,OAmCG,CAAC;AAEhD;;;GAGG;AACH,eAAO,MAAM,mBAAmB,YAAa,OAAO,KAAG,OAEtD,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,WAAW,YARqB,OAAO,KAAG,OAQT,CAAC;AAE/C;;;;GAIG;AACH,eAAO,MAAM,wBAAwB,cACxB,WAAW,KACrB,OAAO,EAAE,GAAG,WAAW,GAAG,IAgB5B,CAAC;AAaF;;;;GAIG;AACH,eAAO,MAAM,uBAAuB,cAAe,WAAW,KAAG,OAAO,EAAE,GAAG,OAAO,GAAG,IAgBtF,CAAC"}
|
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getLastFocusableElement = exports.getFirstFocusableElement = exports.isFocusable = void 0;
|
|
4
|
-
|
|
5
|
-
* Is an element focusable? This function performs various tests to see if the element in question
|
|
6
|
-
* can receive focus. Should skip disabled elements as they are not focusable.
|
|
7
|
-
*/
|
|
8
|
-
const isFocusable = (element) => {
|
|
3
|
+
exports.getLastFocusableElement = exports.getFirstFocusableElement = exports.isFocusable = exports.isKeyboardFocusable = exports.isMouseFocusable = void 0;
|
|
4
|
+
const isBaseFocusable = (element) => {
|
|
9
5
|
if (element.hasAttribute('disabled')) {
|
|
10
6
|
return false;
|
|
11
7
|
}
|
|
@@ -14,8 +10,14 @@ const isFocusable = (element) => {
|
|
|
14
10
|
const validAnchor = nodeName === 'a' && element.hasAttribute('href');
|
|
15
11
|
const validAudioVideo = ['audio', 'video'].includes(nodeName) && element.hasAttribute('controls');
|
|
16
12
|
const validImgObject = ['img', 'object'].includes(nodeName) && element.hasAttribute('usemap');
|
|
17
|
-
const validNativelyFocusable = [
|
|
18
|
-
|
|
13
|
+
const validNativelyFocusable = [
|
|
14
|
+
'button',
|
|
15
|
+
'details',
|
|
16
|
+
'embed',
|
|
17
|
+
'iframe',
|
|
18
|
+
'select',
|
|
19
|
+
'textarea',
|
|
20
|
+
].includes(nodeName);
|
|
19
21
|
const hasTabIndex = element.getAttribute('tabindex') === '0';
|
|
20
22
|
return (validInput ||
|
|
21
23
|
validAnchor ||
|
|
@@ -24,7 +26,24 @@ const isFocusable = (element) => {
|
|
|
24
26
|
validNativelyFocusable ||
|
|
25
27
|
hasTabIndex);
|
|
26
28
|
};
|
|
27
|
-
|
|
29
|
+
/**
|
|
30
|
+
* Is an element focusable? This function performs various tests to see if the element in question
|
|
31
|
+
* can receive focus via a pointer. Should skip disabled elements as they are not focusable.
|
|
32
|
+
*/
|
|
33
|
+
exports.isMouseFocusable = isBaseFocusable;
|
|
34
|
+
/**
|
|
35
|
+
* Is an element focusable? This function performs various tests to see if the element in question
|
|
36
|
+
* can receive focus via the keyboard. Should skip disabled elements as they are not focusable.
|
|
37
|
+
*/
|
|
38
|
+
const isKeyboardFocusable = (element) => {
|
|
39
|
+
return isBaseFocusable(element) && element.getAttribute('tabindex') !== '-1';
|
|
40
|
+
};
|
|
41
|
+
exports.isKeyboardFocusable = isKeyboardFocusable;
|
|
42
|
+
/**
|
|
43
|
+
* @deprecated Use `isMouseFocusable` for mouse events and `isKeyboardFocusable` for keyboard
|
|
44
|
+
* events. `isFocusable` is an alias to `isKeyboardFocusable`
|
|
45
|
+
*/
|
|
46
|
+
exports.isFocusable = exports.isKeyboardFocusable;
|
|
28
47
|
/**
|
|
29
48
|
* Get the first focusable element in a container.
|
|
30
49
|
*
|
|
@@ -34,7 +53,7 @@ const getFirstFocusableElement = (container) => {
|
|
|
34
53
|
const elements = container.querySelectorAll('*');
|
|
35
54
|
for (let i = 0; i < elements.length; i++) {
|
|
36
55
|
const element = elements.item(i);
|
|
37
|
-
if (element && exports.
|
|
56
|
+
if (element && exports.isKeyboardFocusable(element) && element.getAttribute('tabindex') !== '-1') {
|
|
38
57
|
if (isRadioInput(element)) {
|
|
39
58
|
const radioGroup = getRadioGroup(container, element);
|
|
40
59
|
return radioGroup.length > 1 ? Array.from(radioGroup) : element;
|
|
@@ -60,7 +79,7 @@ const getLastFocusableElement = (container) => {
|
|
|
60
79
|
const elements = container.querySelectorAll('*');
|
|
61
80
|
for (let i = elements.length - 1; i >= 0; i--) {
|
|
62
81
|
const element = elements.item(i);
|
|
63
|
-
if (element && exports.
|
|
82
|
+
if (element && exports.isKeyboardFocusable(element) && element.getAttribute('tabindex') !== '-1') {
|
|
64
83
|
if (isRadioInput(element)) {
|
|
65
84
|
const radioGroup = getRadioGroup(container, element);
|
|
66
85
|
return radioGroup.length > 1 ? Array.from(radioGroup) : element;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useReturnFocus.d.ts","sourceRoot":"","sources":["../../../../../popup/lib/hooks/useReturnFocus.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"useReturnFocus.d.ts","sourceRoot":"","sources":["../../../../../popup/lib/hooks/useReturnFocus.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAuD1B;;;;;;GAMG;AACH,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;MA2GzB,CAAC"}
|
|
@@ -25,7 +25,8 @@ function getFocusableElement(element) {
|
|
|
25
25
|
if (element === null || element === document.body || !element.parentElement) {
|
|
26
26
|
return null;
|
|
27
27
|
}
|
|
28
|
-
else if (common_1.isFocusable(element)
|
|
28
|
+
else if (common_1.isFocusable(element) ||
|
|
29
|
+
['button', 'details', 'embed', 'iframe', 'select', 'textarea'].includes(element.nodeName.toLowerCase())) {
|
|
29
30
|
return element;
|
|
30
31
|
}
|
|
31
32
|
return getFocusableElement(element.parentElement);
|