UNPKG

1.47 kBJavaScriptView Raw
1define(["require", "exports", "./dom/getWindow"], function (require, exports, getWindow_1) {
2 "use strict";
3 Object.defineProperty(exports, "__esModule", { value: true });
4 exports.IsFocusVisibleClassName = 'ms-Fabric--isFocusVisible';
5 exports.IsFocusHiddenClassName = 'ms-Fabric--isFocusHidden';
6 /**
7 * Sets the visibility of focus styling.
8 *
9 * By default, focus styles (the box surrounding a focused Button, for example) only show up when navigational
10 * keypresses occur (through Tab, arrows, PgUp/PgDn, Home and End), and are hidden when mouse interactions occur.
11 * This API provides an imperative way to turn them on/off.
12 *
13 * A use case might be when you have a keypress like ctrl-f6 navigate to a particular region on the page,
14 * and want focus to show up.
15 *
16 * @param enabled - whether to remove or add focus
17 * @param target - optional target
18 */
19 function setFocusVisibility(enabled, target) {
20 var win = target ? getWindow_1.getWindow(target) : getWindow_1.getWindow();
21 if (win) {
22 var classList = win.document.body.classList;
23 classList.add(enabled ? exports.IsFocusVisibleClassName : exports.IsFocusHiddenClassName);
24 classList.remove(enabled ? exports.IsFocusHiddenClassName : exports.IsFocusVisibleClassName);
25 }
26 }
27 exports.setFocusVisibility = setFocusVisibility;
28});
29//# sourceMappingURL=setFocusVisibility.js.map
\No newline at end of file