@workday/canvas-kit-react 7.3.11 → 7.3.12
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/dist/commonjs/popup/lib/hooks/useReturnFocus.d.ts.map +1 -1
- package/dist/commonjs/popup/lib/hooks/useReturnFocus.js +31 -2
- package/dist/es6/popup/lib/hooks/useReturnFocus.d.ts.map +1 -1
- package/dist/es6/popup/lib/hooks/useReturnFocus.js +31 -2
- package/package.json +3 -3
- package/popup/lib/hooks/useReturnFocus.tsx +37 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useReturnFocus.d.ts","sourceRoot":"","sources":["../../../../../popup/lib/hooks/useReturnFocus.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAM1B;;;;;;GAMG;AACH,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"useReturnFocus.d.ts","sourceRoot":"","sources":["../../../../../popup/lib/hooks/useReturnFocus.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAM1B;;;;;;GAMG;AACH,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;OAiDzB,CAAC"}
|
|
@@ -16,15 +16,44 @@ var usePopupModel_1 = require("./usePopupModel");
|
|
|
16
16
|
*/
|
|
17
17
|
exports.useReturnFocus = common_1.createElemPropsHook(usePopupModel_1.usePopupModel)(function (model) {
|
|
18
18
|
var visible = model.state.visibility !== 'hidden';
|
|
19
|
+
// This boolean tracks keyboard-driven focus changes. This is required for `useFocusRedirect` as
|
|
20
|
+
// focus redirection needs synchronous focus management and everything else needs asynchronous
|
|
21
|
+
// focus management.
|
|
22
|
+
var requiresFocusChangeRef = react_1.default.useRef(false);
|
|
23
|
+
var onKeyDown = react_1.default.useCallback(function (event) {
|
|
24
|
+
// The tab key changes focus
|
|
25
|
+
if (event.key === 'Tab') {
|
|
26
|
+
requiresFocusChangeRef.current = true;
|
|
27
|
+
}
|
|
28
|
+
}, []);
|
|
29
|
+
var onKeyUp = react_1.default.useCallback(function (event) {
|
|
30
|
+
requiresFocusChangeRef.current = false;
|
|
31
|
+
}, []);
|
|
19
32
|
react_1.default.useLayoutEffect(function () {
|
|
20
33
|
if (!visible) {
|
|
21
34
|
return;
|
|
22
35
|
}
|
|
23
36
|
// capture the element here. The refs will be null by the time the cleanup function is called
|
|
24
37
|
var element = (model.state.returnFocusRef || model.state.targetRef).current;
|
|
38
|
+
document.addEventListener('keydown', onKeyDown, true);
|
|
39
|
+
document.addEventListener('keyup', onKeyUp, true);
|
|
25
40
|
return function () {
|
|
26
|
-
|
|
41
|
+
document.removeEventListener('keydown', onKeyDown, true);
|
|
42
|
+
document.removeEventListener('keyup', onKeyUp, true);
|
|
43
|
+
if (requiresFocusChangeRef.current) {
|
|
44
|
+
// We need to change focus _before_ the browser process the default action of picking a new
|
|
45
|
+
// focus target. Doing this immediately prevents the `focus` event from firing on `element`,
|
|
46
|
+
// but that's okay because the browser will change focus anyways.
|
|
47
|
+
common_1.changeFocus(element);
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
// We wait a frame for the current event to process, allowing the browser to fire default
|
|
51
|
+
// actions. This delay allows the focus change to trigger a `focus` event on `element`.
|
|
52
|
+
requestAnimationFrame(function () {
|
|
53
|
+
common_1.changeFocus(element);
|
|
54
|
+
});
|
|
55
|
+
}
|
|
27
56
|
};
|
|
28
|
-
}, [model.state.returnFocusRef, model.state.targetRef, visible]);
|
|
57
|
+
}, [model.state.returnFocusRef, model.state.targetRef, visible, onKeyDown, onKeyUp]);
|
|
29
58
|
return {};
|
|
30
59
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useReturnFocus.d.ts","sourceRoot":"","sources":["../../../../../popup/lib/hooks/useReturnFocus.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAM1B;;;;;;GAMG;AACH,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"useReturnFocus.d.ts","sourceRoot":"","sources":["../../../../../popup/lib/hooks/useReturnFocus.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAM1B;;;;;;GAMG;AACH,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;OAiDzB,CAAC"}
|
|
@@ -10,15 +10,44 @@ import { usePopupModel } from './usePopupModel';
|
|
|
10
10
|
*/
|
|
11
11
|
export var useReturnFocus = createElemPropsHook(usePopupModel)(function (model) {
|
|
12
12
|
var visible = model.state.visibility !== 'hidden';
|
|
13
|
+
// This boolean tracks keyboard-driven focus changes. This is required for `useFocusRedirect` as
|
|
14
|
+
// focus redirection needs synchronous focus management and everything else needs asynchronous
|
|
15
|
+
// focus management.
|
|
16
|
+
var requiresFocusChangeRef = React.useRef(false);
|
|
17
|
+
var onKeyDown = React.useCallback(function (event) {
|
|
18
|
+
// The tab key changes focus
|
|
19
|
+
if (event.key === 'Tab') {
|
|
20
|
+
requiresFocusChangeRef.current = true;
|
|
21
|
+
}
|
|
22
|
+
}, []);
|
|
23
|
+
var onKeyUp = React.useCallback(function (event) {
|
|
24
|
+
requiresFocusChangeRef.current = false;
|
|
25
|
+
}, []);
|
|
13
26
|
React.useLayoutEffect(function () {
|
|
14
27
|
if (!visible) {
|
|
15
28
|
return;
|
|
16
29
|
}
|
|
17
30
|
// capture the element here. The refs will be null by the time the cleanup function is called
|
|
18
31
|
var element = (model.state.returnFocusRef || model.state.targetRef).current;
|
|
32
|
+
document.addEventListener('keydown', onKeyDown, true);
|
|
33
|
+
document.addEventListener('keyup', onKeyUp, true);
|
|
19
34
|
return function () {
|
|
20
|
-
|
|
35
|
+
document.removeEventListener('keydown', onKeyDown, true);
|
|
36
|
+
document.removeEventListener('keyup', onKeyUp, true);
|
|
37
|
+
if (requiresFocusChangeRef.current) {
|
|
38
|
+
// We need to change focus _before_ the browser process the default action of picking a new
|
|
39
|
+
// focus target. Doing this immediately prevents the `focus` event from firing on `element`,
|
|
40
|
+
// but that's okay because the browser will change focus anyways.
|
|
41
|
+
changeFocus(element);
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
// We wait a frame for the current event to process, allowing the browser to fire default
|
|
45
|
+
// actions. This delay allows the focus change to trigger a `focus` event on `element`.
|
|
46
|
+
requestAnimationFrame(function () {
|
|
47
|
+
changeFocus(element);
|
|
48
|
+
});
|
|
49
|
+
}
|
|
21
50
|
};
|
|
22
|
-
}, [model.state.returnFocusRef, model.state.targetRef, visible]);
|
|
51
|
+
}, [model.state.returnFocusRef, model.state.targetRef, visible, onKeyDown, onKeyUp]);
|
|
23
52
|
return {};
|
|
24
53
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@workday/canvas-kit-react",
|
|
3
|
-
"version": "7.3.
|
|
3
|
+
"version": "7.3.12",
|
|
4
4
|
"description": "The parent module that contains all Workday Canvas Kit React components",
|
|
5
5
|
"author": "Workday, Inc. (https://www.workday.com)",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"@emotion/styled": "^11.6.0",
|
|
50
50
|
"@popperjs/core": "^2.5.4",
|
|
51
51
|
"@workday/canvas-colors-web": "^2.0.0",
|
|
52
|
-
"@workday/canvas-kit-popup-stack": "^7.3.
|
|
52
|
+
"@workday/canvas-kit-popup-stack": "^7.3.12",
|
|
53
53
|
"@workday/canvas-system-icons-web": "^3.0.0",
|
|
54
54
|
"@workday/design-assets-types": "^0.2.8",
|
|
55
55
|
"chroma-js": "^2.1.0",
|
|
@@ -68,5 +68,5 @@
|
|
|
68
68
|
"@workday/canvas-accent-icons-web": "^3.0.0",
|
|
69
69
|
"@workday/canvas-applet-icons-web": "^2.0.0"
|
|
70
70
|
},
|
|
71
|
-
"gitHead": "
|
|
71
|
+
"gitHead": "b9c928b833e0e0e56493c9329dca77191645ab3d"
|
|
72
72
|
}
|
|
@@ -14,16 +14,50 @@ import {usePopupModel} from './usePopupModel';
|
|
|
14
14
|
export const useReturnFocus = createElemPropsHook(usePopupModel)(model => {
|
|
15
15
|
const visible = model.state.visibility !== 'hidden';
|
|
16
16
|
|
|
17
|
+
// This boolean tracks keyboard-driven focus changes. This is required for `useFocusRedirect` as
|
|
18
|
+
// focus redirection needs synchronous focus management and everything else needs asynchronous
|
|
19
|
+
// focus management.
|
|
20
|
+
const requiresFocusChangeRef = React.useRef(false);
|
|
21
|
+
|
|
22
|
+
const onKeyDown = React.useCallback((event: KeyboardEvent) => {
|
|
23
|
+
// The tab key changes focus
|
|
24
|
+
if (event.key === 'Tab') {
|
|
25
|
+
requiresFocusChangeRef.current = true;
|
|
26
|
+
}
|
|
27
|
+
}, []);
|
|
28
|
+
|
|
29
|
+
const onKeyUp = React.useCallback((event: KeyboardEvent) => {
|
|
30
|
+
requiresFocusChangeRef.current = false;
|
|
31
|
+
}, []);
|
|
32
|
+
|
|
17
33
|
React.useLayoutEffect(() => {
|
|
18
34
|
if (!visible) {
|
|
19
35
|
return;
|
|
20
36
|
}
|
|
21
37
|
// capture the element here. The refs will be null by the time the cleanup function is called
|
|
22
|
-
const element = (model.state.returnFocusRef || model.state.targetRef).current;
|
|
38
|
+
const element = (model.state.returnFocusRef || model.state.targetRef).current as HTMLElement;
|
|
39
|
+
|
|
40
|
+
document.addEventListener('keydown', onKeyDown, true);
|
|
41
|
+
document.addEventListener('keyup', onKeyUp, true);
|
|
42
|
+
|
|
23
43
|
return () => {
|
|
24
|
-
|
|
44
|
+
document.removeEventListener('keydown', onKeyDown, true);
|
|
45
|
+
document.removeEventListener('keyup', onKeyUp, true);
|
|
46
|
+
|
|
47
|
+
if (requiresFocusChangeRef.current) {
|
|
48
|
+
// We need to change focus _before_ the browser process the default action of picking a new
|
|
49
|
+
// focus target. Doing this immediately prevents the `focus` event from firing on `element`,
|
|
50
|
+
// but that's okay because the browser will change focus anyways.
|
|
51
|
+
changeFocus(element);
|
|
52
|
+
} else {
|
|
53
|
+
// We wait a frame for the current event to process, allowing the browser to fire default
|
|
54
|
+
// actions. This delay allows the focus change to trigger a `focus` event on `element`.
|
|
55
|
+
requestAnimationFrame(() => {
|
|
56
|
+
changeFocus(element);
|
|
57
|
+
});
|
|
58
|
+
}
|
|
25
59
|
};
|
|
26
|
-
}, [model.state.returnFocusRef, model.state.targetRef, visible]);
|
|
60
|
+
}, [model.state.returnFocusRef, model.state.targetRef, visible, onKeyDown, onKeyUp]);
|
|
27
61
|
|
|
28
62
|
return {};
|
|
29
63
|
});
|