-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfocus-visible-15ada7f7-js-es2015.js
61 lines (54 loc) · 2.12 KB
/
focus-visible-15ada7f7-js-es2015.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
(window["webpackJsonp"] = window["webpackJsonp"] || []).push([["focus-visible-15ada7f7-js"],{
/***/ "./node_modules/@ionic/core/dist/esm/focus-visible-15ada7f7.js":
/*!*********************************************************************!*\
!*** ./node_modules/@ionic/core/dist/esm/focus-visible-15ada7f7.js ***!
\*********************************************************************/
/*! exports provided: startFocusVisible */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "startFocusVisible", function() { return startFocusVisible; });
const ION_FOCUSED = 'ion-focused';
const ION_FOCUSABLE = 'ion-focusable';
const FOCUS_KEYS = ['Tab', 'ArrowDown', 'Space', 'Escape', ' ', 'Shift', 'Enter', 'ArrowLeft', 'ArrowRight', 'ArrowUp'];
const startFocusVisible = () => {
let currentFocus = [];
let keyboardMode = true;
const doc = document;
const setFocus = (elements) => {
currentFocus.forEach(el => el.classList.remove(ION_FOCUSED));
elements.forEach(el => el.classList.add(ION_FOCUSED));
currentFocus = elements;
};
const pointerDown = () => {
keyboardMode = false;
setFocus([]);
};
doc.addEventListener('keydown', ev => {
keyboardMode = FOCUS_KEYS.includes(ev.key);
if (!keyboardMode) {
setFocus([]);
}
});
doc.addEventListener('focusin', ev => {
if (keyboardMode && ev.composedPath) {
const toFocus = ev.composedPath().filter((el) => {
if (el.classList) {
return el.classList.contains(ION_FOCUSABLE);
}
return false;
});
setFocus(toFocus);
}
});
doc.addEventListener('focusout', () => {
if (doc.activeElement === doc.body) {
setFocus([]);
}
});
doc.addEventListener('touchstart', pointerDown);
doc.addEventListener('mousedown', pointerDown);
};
/***/ })
}]);
//# sourceMappingURL=focus-visible-15ada7f7-js-es2015.js.map