1 | define(["require", "exports", "./dom/getWindow", "./keyboard", "./setFocusVisibility"], function (require, exports, getWindow_1, keyboard_1, setFocusVisibility_1) {
|
2 | ;
|
3 | Object.defineProperty(exports, "__esModule", { value: true });
|
4 | /**
|
5 | * Initializes the logic which:
|
6 | *
|
7 | * 1. Subscribes keydown and mousedown events. (It will only do it once per window,
|
8 | * so it's safe to call this method multiple times.)
|
9 | * 2. When the user presses directional keyboard keys, adds the 'ms-Fabric--isFocusVisible' classname
|
10 | * to the document body, removes the 'ms-Fabric-isFocusHidden' classname.
|
11 | * 3. When the user clicks a mouse button, adds the 'ms-Fabric-isFocusHidden' classname to the
|
12 | * document body, removes the 'ms-Fabric--isFocusVisible' classname.
|
13 | *
|
14 | * This logic allows components on the page to conditionally render focus treatments based on
|
15 | * the existence of global classnames, which simplifies logic overall.
|
16 | *
|
17 | * @param window - the window used to add the event listeners
|
18 | * @deprecated Use useFocusRects hook or FocusRects component instead.
|
19 | */
|
20 | function initializeFocusRects(window) {
|
21 | var _a;
|
22 | var win = (window || getWindow_1.getWindow());
|
23 | if (!win || ((_a = win.FabricConfig) === null || _a === void 0 ? void 0 : _a.disableFocusRects) === true) {
|
24 | return;
|
25 | }
|
26 | if (!win.__hasInitializeFocusRects__) {
|
27 | win.__hasInitializeFocusRects__ = true;
|
28 | win.addEventListener('mousedown', _onMouseDown, true);
|
29 | win.addEventListener('pointerdown', _onPointerDown, true);
|
30 | win.addEventListener('keydown', _onKeyDown, true);
|
31 | }
|
32 | }
|
33 | exports.initializeFocusRects = initializeFocusRects;
|
34 | function _onMouseDown(ev) {
|
35 | setFocusVisibility_1.setFocusVisibility(false, ev.target);
|
36 | }
|
37 | function _onPointerDown(ev) {
|
38 | if (ev.pointerType !== 'mouse') {
|
39 | setFocusVisibility_1.setFocusVisibility(false, ev.target);
|
40 | }
|
41 | }
|
42 | function _onKeyDown(ev) {
|
43 | // eslint-disable-next-line deprecation/deprecation
|
44 | keyboard_1.isDirectionalKeyCode(ev.which) && setFocusVisibility_1.setFocusVisibility(true, ev.target);
|
45 | }
|
46 | });
|
47 | //# sourceMappingURL=initializeFocusRects.js.map |
\ | No newline at end of file |