@fluentui/react-tabster 0.0.0-nightly-20220302-0405.1
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/CHANGELOG.json +1981 -0
- package/CHANGELOG.md +821 -0
- package/LICENSE +15 -0
- package/README.md +42 -0
- package/dist/react-tabster.d.ts +122 -0
- package/lib/hooks/index.d.ts +7 -0
- package/lib/hooks/index.js +8 -0
- package/lib/hooks/index.js.map +1 -0
- package/lib/hooks/useArrowNavigationGroup.d.ts +22 -0
- package/lib/hooks/useArrowNavigationGroup.js +37 -0
- package/lib/hooks/useArrowNavigationGroup.js.map +1 -0
- package/lib/hooks/useFocusFinders.d.ts +11 -0
- package/lib/hooks/useFocusFinders.js +36 -0
- package/lib/hooks/useFocusFinders.js.map +1 -0
- package/lib/hooks/useFocusIndicatorStyle.d.ts +33 -0
- package/lib/hooks/useFocusIndicatorStyle.js +84 -0
- package/lib/hooks/useFocusIndicatorStyle.js.map +1 -0
- package/lib/hooks/useFocusableGroup.d.ts +12 -0
- package/lib/hooks/useFocusableGroup.js +38 -0
- package/lib/hooks/useFocusableGroup.js.map +1 -0
- package/lib/hooks/useKeyboardNavAttribute.d.ts +5 -0
- package/lib/hooks/useKeyboardNavAttribute.js +41 -0
- package/lib/hooks/useKeyboardNavAttribute.js.map +1 -0
- package/lib/hooks/useModalAttributes.d.ts +22 -0
- package/lib/hooks/useModalAttributes.js +42 -0
- package/lib/hooks/useModalAttributes.js.map +1 -0
- package/lib/hooks/useTabster.d.ts +9 -0
- package/lib/hooks/useTabster.js +30 -0
- package/lib/hooks/useTabster.js.map +1 -0
- package/lib/hooks/useTabsterAttributes.d.ts +5 -0
- package/lib/hooks/useTabsterAttributes.js +13 -0
- package/lib/hooks/useTabsterAttributes.js.map +1 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +2 -0
- package/lib/index.js.map +1 -0
- package/lib/symbols.d.ts +2 -0
- package/lib/symbols.js +3 -0
- package/lib/symbols.js.map +1 -0
- package/lib/tsdoc-metadata.json +11 -0
- package/lib-commonjs/hooks/index.d.ts +7 -0
- package/lib-commonjs/hooks/index.js +22 -0
- package/lib-commonjs/hooks/index.js.map +1 -0
- package/lib-commonjs/hooks/useArrowNavigationGroup.d.ts +22 -0
- package/lib-commonjs/hooks/useArrowNavigationGroup.js +49 -0
- package/lib-commonjs/hooks/useArrowNavigationGroup.js.map +1 -0
- package/lib-commonjs/hooks/useFocusFinders.d.ts +11 -0
- package/lib-commonjs/hooks/useFocusFinders.js +47 -0
- package/lib-commonjs/hooks/useFocusFinders.js.map +1 -0
- package/lib-commonjs/hooks/useFocusIndicatorStyle.d.ts +33 -0
- package/lib-commonjs/hooks/useFocusIndicatorStyle.js +97 -0
- package/lib-commonjs/hooks/useFocusIndicatorStyle.js.map +1 -0
- package/lib-commonjs/hooks/useFocusableGroup.d.ts +12 -0
- package/lib-commonjs/hooks/useFocusableGroup.js +50 -0
- package/lib-commonjs/hooks/useFocusableGroup.js.map +1 -0
- package/lib-commonjs/hooks/useKeyboardNavAttribute.d.ts +5 -0
- package/lib-commonjs/hooks/useKeyboardNavAttribute.js +54 -0
- package/lib-commonjs/hooks/useKeyboardNavAttribute.js.map +1 -0
- package/lib-commonjs/hooks/useModalAttributes.d.ts +22 -0
- package/lib-commonjs/hooks/useModalAttributes.js +55 -0
- package/lib-commonjs/hooks/useModalAttributes.js.map +1 -0
- package/lib-commonjs/hooks/useTabster.d.ts +9 -0
- package/lib-commonjs/hooks/useTabster.js +41 -0
- package/lib-commonjs/hooks/useTabster.js.map +1 -0
- package/lib-commonjs/hooks/useTabsterAttributes.d.ts +5 -0
- package/lib-commonjs/hooks/useTabsterAttributes.js +24 -0
- package/lib-commonjs/hooks/useTabsterAttributes.js.map +1 -0
- package/lib-commonjs/index.d.ts +1 -0
- package/lib-commonjs/index.js +10 -0
- package/lib-commonjs/index.js.map +1 -0
- package/lib-commonjs/symbols.d.ts +2 -0
- package/lib-commonjs/symbols.js +9 -0
- package/lib-commonjs/symbols.js.map +1 -0
- package/package.json +59 -0
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["hooks/useModalAttributes.ts"],"names":[],"mappings":"AAAA,SAAS,KAAT,QAAsB,2BAAtB;AACA,SAAS,oBAAT,QAAqC,wBAArC;AACA,SAAS,UAAT,EAAqB,YAArB,QAAgE,SAAhE;AACA,SAAS,UAAT,QAA2B,cAA3B;AAcA;;;;;;AAMG;;AACH,OAAO,MAAM,kBAAkB,GAAG,CAChC,OAAA,GAAqC,EADL,KAE8E;AAC9G,QAAM;AAAE,IAAA,SAAF;AAAa,IAAA;AAAb,MAAiC,OAAvC;AACA,QAAM,OAAO,GAAG,UAAU,EAA1B,CAF8G,CAG9G;;AACA,MAAI,OAAJ,EAAa;AACX,IAAA,YAAY,CAAC,OAAD,CAAZ;AACA,IAAA,UAAU,CAAC,OAAD,CAAV;AACD;;AAED,QAAM,EAAE,GAAG,KAAK,CAAC,QAAD,CAAhB;AACA,QAAM,eAAe,GAAG,oBAAoB,CAAC;AAC3C,IAAA,OAAO,EAAE,EADkC;AAE3C,IAAA,SAAS,EAAE;AAAE,MAAA,EAAF;AAAM,MAAA,kBAAkB,EAAE,CAAC,SAA3B;AAAsC,MAAA,kBAAkB,EAAE;AAA1D;AAFgC,GAAD,CAA5C;AAKA,QAAM,iBAAiB,GAAG,oBAAoB,CAAC;AAC7C,IAAA,OAAO,EAAE;AADoC,GAAD,CAA9C;AAIA,SAAO;AAAE,IAAA,eAAF;AAAmB,IAAA;AAAnB,GAAP;AACD,CAtBM","sourcesContent":["import { useId } from '@fluentui/react-utilities';\nimport { useTabsterAttributes } from './useTabsterAttributes';\nimport { getDeloser, getModalizer, Types as TabsterTypes } from 'tabster';\nimport { useTabster } from './useTabster';\n\nexport interface UseModalAttributesOptions {\n /**\n * Traps focus inside the elements the attributes are applied\n */\n trapFocus?: boolean;\n\n /**\n * Always reachabled in Tab order\n */\n alwaysFocusable?: boolean;\n}\n\n/**\n * Applies modal dialog behaviour through DOM attributes\n * Modal element will focus trap and hide other content on the page\n * The trigger element will be focused if focus is lost after the modal element is removed\n *\n * @returns DOM attributes to apply to the modal element and its trigger\n */\nexport const useModalAttributes = (\n options: UseModalAttributesOptions = {},\n): { modalAttributes: TabsterTypes.TabsterDOMAttribute; triggerAttributes: TabsterTypes.TabsterDOMAttribute } => {\n const { trapFocus, alwaysFocusable } = options;\n const tabster = useTabster();\n // Initializes the modalizer and deloser APIs\n if (tabster) {\n getModalizer(tabster);\n getDeloser(tabster);\n }\n\n const id = useId('modal-');\n const modalAttributes = useTabsterAttributes({\n deloser: {},\n modalizer: { id, isOthersAccessible: !trapFocus, isAlwaysAccessible: alwaysFocusable },\n });\n\n const triggerAttributes = useTabsterAttributes({\n deloser: {},\n });\n\n return { modalAttributes, triggerAttributes };\n};\n"],"sourceRoot":"../src/"}
|
@@ -0,0 +1,9 @@
|
|
1
|
+
import { Types as TabsterTypes } from 'tabster';
|
2
|
+
/**
|
3
|
+
* Tries to get a tabster instance on the current window or creates a new one
|
4
|
+
* Since Tabster is single instance only, feel free to call this hook to ensure Tabster exists if necessary
|
5
|
+
*
|
6
|
+
* @internal
|
7
|
+
* @returns Tabster core instance
|
8
|
+
*/
|
9
|
+
export declare const useTabster: () => TabsterTypes.TabsterCore | null;
|
@@ -0,0 +1,30 @@
|
|
1
|
+
import { useFluent } from '@fluentui/react-shared-contexts';
|
2
|
+
import { getCurrentTabster, createTabster } from 'tabster';
|
3
|
+
/**
|
4
|
+
* Tries to get a tabster instance on the current window or creates a new one
|
5
|
+
* Since Tabster is single instance only, feel free to call this hook to ensure Tabster exists if necessary
|
6
|
+
*
|
7
|
+
* @internal
|
8
|
+
* @returns Tabster core instance
|
9
|
+
*/
|
10
|
+
|
11
|
+
export const useTabster = () => {
|
12
|
+
var _a;
|
13
|
+
|
14
|
+
const {
|
15
|
+
targetDocument
|
16
|
+
} = useFluent();
|
17
|
+
const defaultView = (targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.defaultView) || undefined;
|
18
|
+
const tabsterOptions = {
|
19
|
+
autoRoot: {},
|
20
|
+
controlTab: false
|
21
|
+
};
|
22
|
+
|
23
|
+
if (!defaultView) {
|
24
|
+
return null;
|
25
|
+
} // TODO: worth memoizing once more tabster options are used
|
26
|
+
|
27
|
+
|
28
|
+
return (_a = getCurrentTabster(defaultView)) !== null && _a !== void 0 ? _a : createTabster(defaultView, tabsterOptions);
|
29
|
+
};
|
30
|
+
//# sourceMappingURL=useTabster.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["hooks/useTabster.ts"],"names":[],"mappings":"AAAA,SAAS,SAAT,QAA0B,iCAA1B;AACA,SAAS,iBAAT,EAA4B,aAA5B,QAAwE,SAAxE;AAEA;;;;;;AAMG;;AACH,OAAO,MAAM,UAAU,GAAG,MAAsC;;;AAC9D,QAAM;AAAE,IAAA;AAAF,MAAqB,SAAS,EAApC;AAEA,QAAM,WAAW,GAAG,CAAA,cAAc,KAAA,IAAd,IAAA,cAAc,KAAA,KAAA,CAAd,GAAc,KAAA,CAAd,GAAA,cAAc,CAAE,WAAhB,KAA+B,SAAnD;AACA,QAAM,cAAc,GAAkC;AAAE,IAAA,QAAQ,EAAE,EAAZ;AAAgB,IAAA,UAAU,EAAE;AAA5B,GAAtD;;AAEA,MAAI,CAAC,WAAL,EAAkB;AAChB,WAAO,IAAP;AACD,GAR6D,CAU9D;;;AACA,SAAO,CAAA,EAAA,GAAA,iBAAiB,CAAC,WAAD,CAAjB,MAA8B,IAA9B,IAA8B,EAAA,KAAA,KAAA,CAA9B,GAA8B,EAA9B,GAAkC,aAAa,CAAC,WAAD,EAAc,cAAd,CAAtD;AACD,CAZM","sourcesContent":["import { useFluent } from '@fluentui/react-shared-contexts';\nimport { getCurrentTabster, createTabster, Types as TabsterTypes } from 'tabster';\n\n/**\n * Tries to get a tabster instance on the current window or creates a new one\n * Since Tabster is single instance only, feel free to call this hook to ensure Tabster exists if necessary\n *\n * @internal\n * @returns Tabster core instance\n */\nexport const useTabster = (): TabsterTypes.TabsterCore | null => {\n const { targetDocument } = useFluent();\n\n const defaultView = targetDocument?.defaultView || undefined;\n const tabsterOptions: TabsterTypes.TabsterCoreProps = { autoRoot: {}, controlTab: false };\n\n if (!defaultView) {\n return null;\n }\n\n // TODO: worth memoizing once more tabster options are used\n return getCurrentTabster(defaultView) ?? createTabster(defaultView, tabsterOptions);\n};\n"],"sourceRoot":"../src/"}
|
@@ -0,0 +1,13 @@
|
|
1
|
+
import { getTabsterAttribute } from 'tabster';
|
2
|
+
import { useTabster } from './useTabster';
|
3
|
+
/**
|
4
|
+
* Hook that returns tabster attributes while ensuring tabster exists
|
5
|
+
*/
|
6
|
+
|
7
|
+
export const useTabsterAttributes = props => {
|
8
|
+
// A tabster instance is not necessary to generate tabster attributes
|
9
|
+
// but calling the hook will ensure that a tabster instance exists internally and avoids consumers doing the same
|
10
|
+
useTabster();
|
11
|
+
return getTabsterAttribute(props);
|
12
|
+
};
|
13
|
+
//# sourceMappingURL=useTabsterAttributes.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["hooks/useTabsterAttributes.ts"],"names":[],"mappings":"AAAA,SAAS,mBAAT,QAA2D,SAA3D;AACA,SAAS,UAAT,QAA2B,cAA3B;AAEA;;AAEG;;AACH,OAAO,MAAM,oBAAoB,GAAI,KAAD,IAAgF;AAClH;AACA;AACA,EAAA,UAAU;AAEV,SAAO,mBAAmB,CAAC,KAAD,CAA1B;AACD,CANM","sourcesContent":["import { getTabsterAttribute, Types as TabsterTypes } from 'tabster';\nimport { useTabster } from './useTabster';\n\n/**\n * Hook that returns tabster attributes while ensuring tabster exists\n */\nexport const useTabsterAttributes = (props: TabsterTypes.TabsterAttributeProps): TabsterTypes.TabsterDOMAttribute => {\n // A tabster instance is not necessary to generate tabster attributes\n // but calling the hook will ensure that a tabster instance exists internally and avoids consumers doing the same\n useTabster();\n\n return getTabsterAttribute(props);\n};\n"],"sourceRoot":"../src/"}
|
package/lib/index.d.ts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
export * from './hooks/index';
|
package/lib/index.js
ADDED
package/lib/index.js.map
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"../src/","sources":["index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC","sourcesContent":["export * from './hooks/index';\n"]}
|
package/lib/symbols.d.ts
ADDED
package/lib/symbols.js
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"symbols.js","sourceRoot":"../src/","sources":["symbols.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,sBAAsB,GAAG,mBAA4B,CAAC;AACnE,MAAM,CAAC,MAAM,qBAAqB,GAAG,YAAY,sBAAsB,IAAa,CAAC","sourcesContent":["export const KEYBOARD_NAV_ATTRIBUTE = 'data-keyboard-nav' as const;\nexport const KEYBOARD_NAV_SELECTOR = `:global([${KEYBOARD_NAV_ATTRIBUTE}])` as const;\n"]}
|
@@ -0,0 +1,11 @@
|
|
1
|
+
// This file is read by tools that parse documentation comments conforming to the TSDoc standard.
|
2
|
+
// It should be published with your NPM package. It should not be tracked by Git.
|
3
|
+
{
|
4
|
+
"tsdocVersion": "0.12",
|
5
|
+
"toolPackages": [
|
6
|
+
{
|
7
|
+
"packageName": "@microsoft/api-extractor",
|
8
|
+
"packageVersion": "7.18.1"
|
9
|
+
}
|
10
|
+
]
|
11
|
+
}
|
@@ -0,0 +1,7 @@
|
|
1
|
+
export * from './useArrowNavigationGroup';
|
2
|
+
export * from './useFocusFinders';
|
3
|
+
export * from './useModalAttributes';
|
4
|
+
export * from './useTabsterAttributes';
|
5
|
+
export * from './useFocusIndicatorStyle';
|
6
|
+
export * from './useKeyboardNavAttribute';
|
7
|
+
export * from './useFocusableGroup';
|
@@ -0,0 +1,22 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
|
7
|
+
const tslib_1 = /*#__PURE__*/require("tslib");
|
8
|
+
|
9
|
+
tslib_1.__exportStar(require("./useArrowNavigationGroup"), exports);
|
10
|
+
|
11
|
+
tslib_1.__exportStar(require("./useFocusFinders"), exports);
|
12
|
+
|
13
|
+
tslib_1.__exportStar(require("./useModalAttributes"), exports);
|
14
|
+
|
15
|
+
tslib_1.__exportStar(require("./useTabsterAttributes"), exports);
|
16
|
+
|
17
|
+
tslib_1.__exportStar(require("./useFocusIndicatorStyle"), exports);
|
18
|
+
|
19
|
+
tslib_1.__exportStar(require("./useKeyboardNavAttribute"), exports);
|
20
|
+
|
21
|
+
tslib_1.__exportStar(require("./useFocusableGroup"), exports);
|
22
|
+
//# sourceMappingURL=index.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["hooks/index.ts"],"names":[],"mappings":";;;;;;;;AAAA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,2BAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,mBAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,sBAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,wBAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,0BAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,2BAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,qBAAA,CAAA,EAAA,OAAA","sourcesContent":["export * from './useArrowNavigationGroup';\nexport * from './useFocusFinders';\nexport * from './useModalAttributes';\nexport * from './useTabsterAttributes';\nexport * from './useFocusIndicatorStyle';\nexport * from './useKeyboardNavAttribute';\nexport * from './useFocusableGroup';\n"],"sourceRoot":"../src/"}
|
@@ -0,0 +1,22 @@
|
|
1
|
+
import { Types } from 'tabster';
|
2
|
+
export interface UseArrowNavigationGroupOptions {
|
3
|
+
/**
|
4
|
+
* Focus will navigate vertically or horizontally, defaults to horizontally
|
5
|
+
* @defaultValue vertical
|
6
|
+
*/
|
7
|
+
axis?: 'vertical' | 'horizontal';
|
8
|
+
/**
|
9
|
+
* Focus will cycle to the first/last elements of the group without stopping
|
10
|
+
*/
|
11
|
+
circular?: boolean;
|
12
|
+
/**
|
13
|
+
* Last focused element in the group will be remembered and focused (if still
|
14
|
+
* available) when tabbing from outside of the group
|
15
|
+
*/
|
16
|
+
memorizeCurrent?: boolean;
|
17
|
+
}
|
18
|
+
/**
|
19
|
+
* A hook that returns the necessary tabster attributes to support arrow key navigation
|
20
|
+
* @param options - Options to configure keyboard navigation
|
21
|
+
*/
|
22
|
+
export declare const useArrowNavigationGroup: (options?: UseArrowNavigationGroupOptions | undefined) => Types.TabsterDOMAttribute;
|
@@ -0,0 +1,49 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.useArrowNavigationGroup = void 0;
|
7
|
+
|
8
|
+
const tabster_1 = /*#__PURE__*/require("tabster");
|
9
|
+
|
10
|
+
const useTabsterAttributes_1 = /*#__PURE__*/require("./useTabsterAttributes");
|
11
|
+
|
12
|
+
const useTabster_1 = /*#__PURE__*/require("./useTabster");
|
13
|
+
/**
|
14
|
+
* A hook that returns the necessary tabster attributes to support arrow key navigation
|
15
|
+
* @param options - Options to configure keyboard navigation
|
16
|
+
*/
|
17
|
+
|
18
|
+
|
19
|
+
const useArrowNavigationGroup = options => {
|
20
|
+
var _a;
|
21
|
+
|
22
|
+
const tabster = useTabster_1.useTabster();
|
23
|
+
|
24
|
+
if (tabster) {
|
25
|
+
tabster_1.getMover(tabster);
|
26
|
+
}
|
27
|
+
|
28
|
+
return useTabsterAttributes_1.useTabsterAttributes({
|
29
|
+
mover: {
|
30
|
+
cyclic: !!(options === null || options === void 0 ? void 0 : options.circular),
|
31
|
+
direction: axisToMoverDirection((_a = options === null || options === void 0 ? void 0 : options.axis) !== null && _a !== void 0 ? _a : 'vertical'),
|
32
|
+
memorizeCurrent: options === null || options === void 0 ? void 0 : options.memorizeCurrent
|
33
|
+
}
|
34
|
+
});
|
35
|
+
};
|
36
|
+
|
37
|
+
exports.useArrowNavigationGroup = useArrowNavigationGroup;
|
38
|
+
|
39
|
+
function axisToMoverDirection(axis) {
|
40
|
+
switch (axis) {
|
41
|
+
case 'horizontal':
|
42
|
+
return tabster_1.Types.MoverDirections.Horizontal;
|
43
|
+
|
44
|
+
case 'vertical':
|
45
|
+
default:
|
46
|
+
return tabster_1.Types.MoverDirections.Vertical;
|
47
|
+
}
|
48
|
+
}
|
49
|
+
//# sourceMappingURL=useArrowNavigationGroup.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["hooks/useArrowNavigationGroup.ts"],"names":[],"mappings":";;;;;;;AAAA,MAAA,SAAA,gBAAA,OAAA,CAAA,SAAA,CAAA;;AACA,MAAA,sBAAA,gBAAA,OAAA,CAAA,wBAAA,CAAA;;AACA,MAAA,YAAA,gBAAA,OAAA,CAAA,cAAA,CAAA;AAmBA;;;AAGG;;;AACI,MAAM,uBAAuB,GAAI,OAAD,IAA6C;;;AAClF,QAAM,OAAO,GAAG,YAAA,CAAA,UAAA,EAAhB;;AAEA,MAAI,OAAJ,EAAa;AACX,IAAA,SAAA,CAAA,QAAA,CAAS,OAAT;AACD;;AAED,SAAO,sBAAA,CAAA,oBAAA,CAAqB;AAC1B,IAAA,KAAK,EAAE;AACL,MAAA,MAAM,EAAE,CAAC,EAAC,OAAO,KAAA,IAAP,IAAA,OAAO,KAAA,KAAA,CAAP,GAAO,KAAA,CAAP,GAAA,OAAO,CAAE,QAAV,CADJ;AAEL,MAAA,SAAS,EAAE,oBAAoB,CAAC,CAAA,EAAA,GAAA,OAAO,KAAA,IAAP,IAAA,OAAO,KAAA,KAAA,CAAP,GAAO,KAAA,CAAP,GAAA,OAAO,CAAE,IAAT,MAAa,IAAb,IAAa,EAAA,KAAA,KAAA,CAAb,GAAa,EAAb,GAAiB,UAAlB,CAF1B;AAGL,MAAA,eAAe,EAAE,OAAO,KAAA,IAAP,IAAA,OAAO,KAAA,KAAA,CAAP,GAAO,KAAA,CAAP,GAAA,OAAO,CAAE;AAHrB;AADmB,GAArB,CAAP;AAOD,CAdM;;AAAM,OAAA,CAAA,uBAAA,GAAuB,uBAAvB;;AAgBb,SAAS,oBAAT,CAA8B,IAA9B,EAA0E;AACxE,UAAQ,IAAR;AACE,SAAK,YAAL;AACE,aAAO,SAAA,CAAA,KAAA,CAAM,eAAN,CAAsB,UAA7B;;AAEF,SAAK,UAAL;AACA;AACE,aAAO,SAAA,CAAA,KAAA,CAAM,eAAN,CAAsB,QAA7B;AANJ;AAQD","sourcesContent":["import { Types, getMover } from 'tabster';\nimport { useTabsterAttributes } from './useTabsterAttributes';\nimport { useTabster } from './useTabster';\n\nexport interface UseArrowNavigationGroupOptions {\n /**\n * Focus will navigate vertically or horizontally, defaults to horizontally\n * @defaultValue vertical\n */\n axis?: 'vertical' | 'horizontal';\n /**\n * Focus will cycle to the first/last elements of the group without stopping\n */\n circular?: boolean;\n /**\n * Last focused element in the group will be remembered and focused (if still\n * available) when tabbing from outside of the group\n */\n memorizeCurrent?: boolean;\n}\n\n/**\n * A hook that returns the necessary tabster attributes to support arrow key navigation\n * @param options - Options to configure keyboard navigation\n */\nexport const useArrowNavigationGroup = (options?: UseArrowNavigationGroupOptions) => {\n const tabster = useTabster();\n\n if (tabster) {\n getMover(tabster);\n }\n\n return useTabsterAttributes({\n mover: {\n cyclic: !!options?.circular,\n direction: axisToMoverDirection(options?.axis ?? 'vertical'),\n memorizeCurrent: options?.memorizeCurrent,\n },\n });\n};\n\nfunction axisToMoverDirection(axis: UseArrowNavigationGroupOptions['axis']): Types.MoverDirection {\n switch (axis) {\n case 'horizontal':\n return Types.MoverDirections.Horizontal;\n\n case 'vertical':\n default:\n return Types.MoverDirections.Vertical;\n }\n}\n"],"sourceRoot":"../src/"}
|
@@ -0,0 +1,11 @@
|
|
1
|
+
import { Types as TabsterTypes } from 'tabster';
|
2
|
+
/**
|
3
|
+
* Returns a set of helper functions that will traverse focusable elements in the context of a root DOM element
|
4
|
+
*/
|
5
|
+
export declare const useFocusFinders: () => {
|
6
|
+
findAllFocusable: (container: HTMLElement, acceptCondition: (el: HTMLElement) => boolean) => HTMLElement[];
|
7
|
+
findFirstFocusable: (container: HTMLElement) => HTMLElement | null | undefined;
|
8
|
+
findLastFocusable: (container: HTMLElement) => HTMLElement | null | undefined;
|
9
|
+
findNextFocusable: (currentElement: HTMLElement, options?: Pick<TabsterTypes.FindNextProps, 'container'>) => HTMLElement | null | undefined;
|
10
|
+
findPrevFocusable: (currentElement: HTMLElement, options?: Pick<TabsterTypes.FindNextProps, 'container'>) => HTMLElement | null | undefined;
|
11
|
+
};
|
@@ -0,0 +1,47 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.useFocusFinders = void 0;
|
7
|
+
|
8
|
+
const React = /*#__PURE__*/require("react");
|
9
|
+
|
10
|
+
const useTabster_1 = /*#__PURE__*/require("./useTabster");
|
11
|
+
/**
|
12
|
+
* Returns a set of helper functions that will traverse focusable elements in the context of a root DOM element
|
13
|
+
*/
|
14
|
+
|
15
|
+
|
16
|
+
const useFocusFinders = () => {
|
17
|
+
const tabster = useTabster_1.useTabster(); // Narrow props for now and let need dictate additional props in the future
|
18
|
+
|
19
|
+
const findAllFocusable = React.useCallback((container, acceptCondition) => (tabster === null || tabster === void 0 ? void 0 : tabster.focusable.findAll({
|
20
|
+
container,
|
21
|
+
acceptCondition
|
22
|
+
})) || [], [tabster]);
|
23
|
+
const findFirstFocusable = React.useCallback(container => tabster === null || tabster === void 0 ? void 0 : tabster.focusable.findFirst({
|
24
|
+
container
|
25
|
+
}), [tabster]);
|
26
|
+
const findLastFocusable = React.useCallback(container => tabster === null || tabster === void 0 ? void 0 : tabster.focusable.findLast({
|
27
|
+
container
|
28
|
+
}), [tabster]);
|
29
|
+
const findNextFocusable = React.useCallback((currentElement, options = {}) => tabster === null || tabster === void 0 ? void 0 : tabster.focusable.findNext({
|
30
|
+
currentElement,
|
31
|
+
...options
|
32
|
+
}), [tabster]);
|
33
|
+
const findPrevFocusable = React.useCallback((currentElement, options = {}) => tabster === null || tabster === void 0 ? void 0 : tabster.focusable.findPrev({
|
34
|
+
currentElement,
|
35
|
+
...options
|
36
|
+
}), [tabster]);
|
37
|
+
return {
|
38
|
+
findAllFocusable,
|
39
|
+
findFirstFocusable,
|
40
|
+
findLastFocusable,
|
41
|
+
findNextFocusable,
|
42
|
+
findPrevFocusable
|
43
|
+
};
|
44
|
+
};
|
45
|
+
|
46
|
+
exports.useFocusFinders = useFocusFinders;
|
47
|
+
//# sourceMappingURL=useFocusFinders.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["hooks/useFocusFinders.ts"],"names":[],"mappings":";;;;;;;AAAA,MAAA,KAAA,gBAAA,OAAA,CAAA,OAAA,CAAA;;AAEA,MAAA,YAAA,gBAAA,OAAA,CAAA,cAAA,CAAA;AAEA;;AAEG;;;AACI,MAAM,eAAe,GAAG,MAAK;AAClC,QAAM,OAAO,GAAG,YAAA,CAAA,UAAA,EAAhB,CADkC,CAGlC;;AACA,QAAM,gBAAgB,GAAG,KAAK,CAAC,WAAN,CACvB,CAAC,SAAD,EAAyB,eAAzB,KACE,CAAA,OAAO,KAAA,IAAP,IAAA,OAAO,KAAA,KAAA,CAAP,GAAO,KAAA,CAAP,GAAA,OAAO,CAAE,SAAT,CAAmB,OAAnB,CAA2B;AAAE,IAAA,SAAF;AAAa,IAAA;AAAb,GAA3B,CAAA,KAA8D,EAFzC,EAGvB,CAAC,OAAD,CAHuB,CAAzB;AAMA,QAAM,kBAAkB,GAAG,KAAK,CAAC,WAAN,CACxB,SAAD,IAA4B,OAAO,KAAA,IAAP,IAAA,OAAO,KAAA,KAAA,CAAP,GAAO,KAAA,CAAP,GAAA,OAAO,CAAE,SAAT,CAAmB,SAAnB,CAA6B;AAAE,IAAA;AAAF,GAA7B,CADH,EAEzB,CAAC,OAAD,CAFyB,CAA3B;AAKA,QAAM,iBAAiB,GAAG,KAAK,CAAC,WAAN,CAAmB,SAAD,IAA4B,OAAO,KAAA,IAAP,IAAA,OAAO,KAAA,KAAA,CAAP,GAAO,KAAA,CAAP,GAAA,OAAO,CAAE,SAAT,CAAmB,QAAnB,CAA4B;AAAE,IAAA;AAAF,GAA5B,CAA9C,EAA0F,CAClH,OADkH,CAA1F,CAA1B;AAIA,QAAM,iBAAiB,GAAG,KAAK,CAAC,WAAN,CACxB,CAAC,cAAD,EAA8B,OAAA,GAAyD,EAAvF,KACE,OAAO,KAAA,IAAP,IAAA,OAAO,KAAA,KAAA,CAAP,GAAO,KAAA,CAAP,GAAA,OAAO,CAAE,SAAT,CAAmB,QAAnB,CAA4B;AAAE,IAAA,cAAF;AAAkB,OAAG;AAArB,GAA5B,CAFsB,EAGxB,CAAC,OAAD,CAHwB,CAA1B;AAMA,QAAM,iBAAiB,GAAG,KAAK,CAAC,WAAN,CACxB,CAAC,cAAD,EAA8B,OAAA,GAAyD,EAAvF,KACE,OAAO,KAAA,IAAP,IAAA,OAAO,KAAA,KAAA,CAAP,GAAO,KAAA,CAAP,GAAA,OAAO,CAAE,SAAT,CAAmB,QAAnB,CAA4B;AAAE,IAAA,cAAF;AAAkB,OAAG;AAArB,GAA5B,CAFsB,EAGxB,CAAC,OAAD,CAHwB,CAA1B;AAMA,SAAO;AACL,IAAA,gBADK;AAEL,IAAA,kBAFK;AAGL,IAAA,iBAHK;AAIL,IAAA,iBAJK;AAKL,IAAA;AALK,GAAP;AAOD,CAtCM;;AAAM,OAAA,CAAA,eAAA,GAAe,eAAf","sourcesContent":["import * as React from 'react';\nimport { Types as TabsterTypes } from 'tabster';\nimport { useTabster } from './useTabster';\n\n/**\n * Returns a set of helper functions that will traverse focusable elements in the context of a root DOM element\n */\nexport const useFocusFinders = () => {\n const tabster = useTabster();\n\n // Narrow props for now and let need dictate additional props in the future\n const findAllFocusable = React.useCallback(\n (container: HTMLElement, acceptCondition: (el: HTMLElement) => boolean) =>\n tabster?.focusable.findAll({ container, acceptCondition }) || [],\n [tabster],\n );\n\n const findFirstFocusable = React.useCallback(\n (container: HTMLElement) => tabster?.focusable.findFirst({ container }),\n [tabster],\n );\n\n const findLastFocusable = React.useCallback((container: HTMLElement) => tabster?.focusable.findLast({ container }), [\n tabster,\n ]);\n\n const findNextFocusable = React.useCallback(\n (currentElement: HTMLElement, options: Pick<TabsterTypes.FindNextProps, 'container'> = {}) =>\n tabster?.focusable.findNext({ currentElement, ...options }),\n [tabster],\n );\n\n const findPrevFocusable = React.useCallback(\n (currentElement: HTMLElement, options: Pick<TabsterTypes.FindNextProps, 'container'> = {}) =>\n tabster?.focusable.findPrev({ currentElement, ...options }),\n [tabster],\n );\n\n return {\n findAllFocusable,\n findFirstFocusable,\n findLastFocusable,\n findNextFocusable,\n findPrevFocusable,\n };\n};\n"],"sourceRoot":"../src/"}
|
@@ -0,0 +1,33 @@
|
|
1
|
+
import type { GriffelStyle } from '@griffel/react';
|
2
|
+
export declare type FocusOutlineOffset = Record<'top' | 'bottom' | 'left' | 'right', string>;
|
3
|
+
export declare type FocusOutlineStyleOptions = {
|
4
|
+
/**
|
5
|
+
* Only property not supported by the native CSS `outline`, if this is no longer needed
|
6
|
+
* we can just go native instead
|
7
|
+
*/
|
8
|
+
outlineRadius: string;
|
9
|
+
outlineColor: string;
|
10
|
+
outlineWidth: string;
|
11
|
+
outlineOffset?: string | FocusOutlineOffset;
|
12
|
+
};
|
13
|
+
export interface CreateFocusIndicatorStyleRuleOptions {
|
14
|
+
selector?: 'focus' | 'focus-within';
|
15
|
+
}
|
16
|
+
/**
|
17
|
+
* NOTE: The element with the focus outline needs to have `position: relative` so that the
|
18
|
+
* pseudo element can be properly positioned.
|
19
|
+
*
|
20
|
+
* @param theme - Theme used in @see makeStyles
|
21
|
+
* @param options - Configure the style of the focus outline
|
22
|
+
* @returns focus outline styles object for @see makeStyles
|
23
|
+
*/
|
24
|
+
export declare const createFocusOutlineStyle: (options?: {
|
25
|
+
style: Partial<FocusOutlineStyleOptions>;
|
26
|
+
} & CreateFocusIndicatorStyleRuleOptions) => GriffelStyle;
|
27
|
+
/**
|
28
|
+
* Creates a style for @see makeStyles that includes the necessary selectors for focus.
|
29
|
+
* Should be used only when @see createFocusOutlineStyle does not fit requirements
|
30
|
+
*
|
31
|
+
* @param style - styling applied on focus, defaults to @see getDefaultFocusOutlineStyes
|
32
|
+
*/
|
33
|
+
export declare const createCustomFocusIndicatorStyle: (style: GriffelStyle, options?: CreateFocusIndicatorStyleRuleOptions) => GriffelStyle;
|
@@ -0,0 +1,97 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.createCustomFocusIndicatorStyle = exports.createFocusOutlineStyle = void 0;
|
7
|
+
|
8
|
+
const react_theme_1 = /*#__PURE__*/require("@fluentui/react-theme");
|
9
|
+
|
10
|
+
const symbols_1 = /*#__PURE__*/require("../symbols");
|
11
|
+
/**
|
12
|
+
* NOTE: the element with the focus outline needs to have `position: relative` so that the
|
13
|
+
* pseudo element can be properly positioned.
|
14
|
+
*
|
15
|
+
* @param options - Configures the style of the focus outline
|
16
|
+
* @returns focus outline styles object
|
17
|
+
*/
|
18
|
+
|
19
|
+
|
20
|
+
const getFocusOutlineStyles = options => {
|
21
|
+
var _a, _b, _c, _d;
|
22
|
+
|
23
|
+
const {
|
24
|
+
outlineRadius,
|
25
|
+
outlineColor,
|
26
|
+
outlineOffset,
|
27
|
+
outlineWidth
|
28
|
+
} = options;
|
29
|
+
const outlineOffsetTop = ((_a = outlineOffset) === null || _a === void 0 ? void 0 : _a.top) || outlineOffset;
|
30
|
+
const outlineOffsetBottom = ((_b = outlineOffset) === null || _b === void 0 ? void 0 : _b.bottom) || outlineOffset;
|
31
|
+
const outlineOffsetLeft = ((_c = outlineOffset) === null || _c === void 0 ? void 0 : _c.left) || outlineOffset;
|
32
|
+
const outlineOffsetRight = ((_d = outlineOffset) === null || _d === void 0 ? void 0 : _d.right) || outlineOffset;
|
33
|
+
return {
|
34
|
+
borderColor: 'transparent',
|
35
|
+
':after': {
|
36
|
+
content: '""',
|
37
|
+
position: 'absolute',
|
38
|
+
pointerEvents: 'none',
|
39
|
+
boxSizing: 'outline-box',
|
40
|
+
zIndex: 1,
|
41
|
+
borderStyle: 'solid',
|
42
|
+
borderWidth: outlineWidth,
|
43
|
+
borderRadius: outlineRadius,
|
44
|
+
borderColor: outlineColor,
|
45
|
+
top: !outlineOffset ? `-${outlineWidth}` : `calc(0px - ${outlineWidth} - ${outlineOffsetTop})`,
|
46
|
+
bottom: !outlineOffset ? `-${outlineWidth}` : `calc(0px - ${outlineWidth} - ${outlineOffsetBottom})`,
|
47
|
+
left: !outlineOffset ? `-${outlineWidth}` : `calc(0px - ${outlineWidth} - ${outlineOffsetLeft})`,
|
48
|
+
right: !outlineOffset ? `-${outlineWidth}` : `calc(0px - ${outlineWidth} - ${outlineOffsetRight})`
|
49
|
+
}
|
50
|
+
};
|
51
|
+
};
|
52
|
+
|
53
|
+
const defaultOptions = {
|
54
|
+
selector: 'focus'
|
55
|
+
};
|
56
|
+
/**
|
57
|
+
* NOTE: The element with the focus outline needs to have `position: relative` so that the
|
58
|
+
* pseudo element can be properly positioned.
|
59
|
+
*
|
60
|
+
* @param theme - Theme used in @see makeStyles
|
61
|
+
* @param options - Configure the style of the focus outline
|
62
|
+
* @returns focus outline styles object for @see makeStyles
|
63
|
+
*/
|
64
|
+
|
65
|
+
const createFocusOutlineStyle = (options = {
|
66
|
+
style: {},
|
67
|
+
...defaultOptions
|
68
|
+
}) => ({
|
69
|
+
':focus-visible': {
|
70
|
+
outlineStyle: 'none'
|
71
|
+
},
|
72
|
+
[`${symbols_1.KEYBOARD_NAV_SELECTOR} :${options.selector || defaultOptions.selector}`]: getFocusOutlineStyles({
|
73
|
+
outlineColor: react_theme_1.tokens.colorStrokeFocus2,
|
74
|
+
outlineRadius: react_theme_1.tokens.borderRadiusMedium,
|
75
|
+
// FIXME: tokens.strokeWidthThick causes some weird bugs
|
76
|
+
outlineWidth: '2px',
|
77
|
+
...options.style
|
78
|
+
})
|
79
|
+
});
|
80
|
+
|
81
|
+
exports.createFocusOutlineStyle = createFocusOutlineStyle;
|
82
|
+
/**
|
83
|
+
* Creates a style for @see makeStyles that includes the necessary selectors for focus.
|
84
|
+
* Should be used only when @see createFocusOutlineStyle does not fit requirements
|
85
|
+
*
|
86
|
+
* @param style - styling applied on focus, defaults to @see getDefaultFocusOutlineStyes
|
87
|
+
*/
|
88
|
+
|
89
|
+
const createCustomFocusIndicatorStyle = (style, options = defaultOptions) => ({
|
90
|
+
':focus-visible': {
|
91
|
+
outlineStyle: 'none'
|
92
|
+
},
|
93
|
+
[`${symbols_1.KEYBOARD_NAV_SELECTOR} :${options.selector || defaultOptions.selector}`]: style
|
94
|
+
});
|
95
|
+
|
96
|
+
exports.createCustomFocusIndicatorStyle = createCustomFocusIndicatorStyle;
|
97
|
+
//# sourceMappingURL=useFocusIndicatorStyle.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["hooks/useFocusIndicatorStyle.ts"],"names":[],"mappings":"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","sourcesContent":["import { tokens } from '@fluentui/react-theme';\nimport { KEYBOARD_NAV_SELECTOR } from '../symbols';\nimport type { GriffelStyle } from '@griffel/react';\n\nexport type FocusOutlineOffset = Record<'top' | 'bottom' | 'left' | 'right', string>;\nexport type FocusOutlineStyleOptions = {\n /**\n * Only property not supported by the native CSS `outline`, if this is no longer needed\n * we can just go native instead\n */\n outlineRadius: string;\n outlineColor: string;\n outlineWidth: string;\n outlineOffset?: string | FocusOutlineOffset;\n};\n\n/**\n * NOTE: the element with the focus outline needs to have `position: relative` so that the\n * pseudo element can be properly positioned.\n *\n * @param options - Configures the style of the focus outline\n * @returns focus outline styles object\n */\nconst getFocusOutlineStyles = (options: FocusOutlineStyleOptions) => {\n const { outlineRadius, outlineColor, outlineOffset, outlineWidth } = options;\n\n const outlineOffsetTop = (outlineOffset as FocusOutlineOffset)?.top || outlineOffset;\n const outlineOffsetBottom = (outlineOffset as FocusOutlineOffset)?.bottom || outlineOffset;\n const outlineOffsetLeft = (outlineOffset as FocusOutlineOffset)?.left || outlineOffset;\n const outlineOffsetRight = (outlineOffset as FocusOutlineOffset)?.right || outlineOffset;\n\n return {\n borderColor: 'transparent',\n ':after': {\n content: '\"\"',\n position: 'absolute',\n pointerEvents: 'none',\n boxSizing: 'outline-box',\n zIndex: 1,\n\n borderStyle: 'solid',\n borderWidth: outlineWidth,\n borderRadius: outlineRadius,\n borderColor: outlineColor,\n\n top: !outlineOffset ? `-${outlineWidth}` : `calc(0px - ${outlineWidth} - ${outlineOffsetTop})`,\n bottom: !outlineOffset ? `-${outlineWidth}` : `calc(0px - ${outlineWidth} - ${outlineOffsetBottom})`,\n left: !outlineOffset ? `-${outlineWidth}` : `calc(0px - ${outlineWidth} - ${outlineOffsetLeft})`,\n right: !outlineOffset ? `-${outlineWidth}` : `calc(0px - ${outlineWidth} - ${outlineOffsetRight})`,\n },\n };\n};\n\nexport interface CreateFocusIndicatorStyleRuleOptions {\n selector?: 'focus' | 'focus-within';\n}\n\nconst defaultOptions: CreateFocusIndicatorStyleRuleOptions = {\n selector: 'focus',\n};\n\n/**\n * NOTE: The element with the focus outline needs to have `position: relative` so that the\n * pseudo element can be properly positioned.\n *\n * @param theme - Theme used in @see makeStyles\n * @param options - Configure the style of the focus outline\n * @returns focus outline styles object for @see makeStyles\n */\nexport const createFocusOutlineStyle = (\n options: {\n style: Partial<FocusOutlineStyleOptions>;\n } & CreateFocusIndicatorStyleRuleOptions = { style: {}, ...defaultOptions },\n): GriffelStyle => ({\n ':focus-visible': {\n outlineStyle: 'none',\n },\n [`${KEYBOARD_NAV_SELECTOR} :${options.selector || defaultOptions.selector}`]: getFocusOutlineStyles({\n outlineColor: tokens.colorStrokeFocus2,\n outlineRadius: tokens.borderRadiusMedium,\n // FIXME: tokens.strokeWidthThick causes some weird bugs\n outlineWidth: '2px',\n ...options.style,\n }),\n});\n\n/**\n * Creates a style for @see makeStyles that includes the necessary selectors for focus.\n * Should be used only when @see createFocusOutlineStyle does not fit requirements\n *\n * @param style - styling applied on focus, defaults to @see getDefaultFocusOutlineStyes\n */\nexport const createCustomFocusIndicatorStyle = (\n style: GriffelStyle,\n options: CreateFocusIndicatorStyleRuleOptions = defaultOptions,\n): GriffelStyle => ({\n ':focus-visible': {\n outlineStyle: 'none',\n },\n [`${KEYBOARD_NAV_SELECTOR} :${options.selector || defaultOptions.selector}`]: style,\n});\n"],"sourceRoot":"../src/"}
|
@@ -0,0 +1,12 @@
|
|
1
|
+
import { Types } from 'tabster';
|
2
|
+
export interface UseFocusableGroupOptions {
|
3
|
+
/**
|
4
|
+
* Behavior for the Tab key.
|
5
|
+
*/
|
6
|
+
tabBehavior?: 'unlimited' | 'limited' | 'limitedTrapFocus';
|
7
|
+
}
|
8
|
+
/**
|
9
|
+
* A hook that returns the necessary tabster attributes to support groupping.
|
10
|
+
* @param options - Options to configure keyboard navigation
|
11
|
+
*/
|
12
|
+
export declare const useFocusableGroup: (options?: UseFocusableGroupOptions | undefined) => Types.TabsterDOMAttribute;
|
@@ -0,0 +1,50 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.useFocusableGroup = void 0;
|
7
|
+
|
8
|
+
const tabster_1 = /*#__PURE__*/require("tabster");
|
9
|
+
|
10
|
+
const useTabsterAttributes_1 = /*#__PURE__*/require("./useTabsterAttributes");
|
11
|
+
|
12
|
+
const useTabster_1 = /*#__PURE__*/require("./useTabster");
|
13
|
+
/**
|
14
|
+
* A hook that returns the necessary tabster attributes to support groupping.
|
15
|
+
* @param options - Options to configure keyboard navigation
|
16
|
+
*/
|
17
|
+
|
18
|
+
|
19
|
+
const useFocusableGroup = options => {
|
20
|
+
const tabster = useTabster_1.useTabster();
|
21
|
+
|
22
|
+
if (tabster) {
|
23
|
+
tabster_1.getGroupper(tabster);
|
24
|
+
}
|
25
|
+
|
26
|
+
return useTabsterAttributes_1.useTabsterAttributes({
|
27
|
+
groupper: {
|
28
|
+
tabbability: getTabbability(options === null || options === void 0 ? void 0 : options.tabBehavior)
|
29
|
+
}
|
30
|
+
});
|
31
|
+
};
|
32
|
+
|
33
|
+
exports.useFocusableGroup = useFocusableGroup;
|
34
|
+
|
35
|
+
const getTabbability = tabBehavior => {
|
36
|
+
switch (tabBehavior) {
|
37
|
+
case 'unlimited':
|
38
|
+
return tabster_1.Types.GroupperTabbabilities.Unlimited;
|
39
|
+
|
40
|
+
case 'limited':
|
41
|
+
return tabster_1.Types.GroupperTabbabilities.Limited;
|
42
|
+
|
43
|
+
case 'limitedTrapFocus':
|
44
|
+
return tabster_1.Types.GroupperTabbabilities.LimitedTrapFocus;
|
45
|
+
|
46
|
+
default:
|
47
|
+
return undefined;
|
48
|
+
}
|
49
|
+
};
|
50
|
+
//# sourceMappingURL=useFocusableGroup.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["hooks/useFocusableGroup.ts"],"names":[],"mappings":";;;;;;;AAAA,MAAA,SAAA,gBAAA,OAAA,CAAA,SAAA,CAAA;;AACA,MAAA,sBAAA,gBAAA,OAAA,CAAA,wBAAA,CAAA;;AACA,MAAA,YAAA,gBAAA,OAAA,CAAA,cAAA,CAAA;AASA;;;AAGG;;;AACI,MAAM,iBAAiB,GAAI,OAAD,IAAuC;AACtE,QAAM,OAAO,GAAG,YAAA,CAAA,UAAA,EAAhB;;AAEA,MAAI,OAAJ,EAAa;AACX,IAAA,SAAA,CAAA,WAAA,CAAY,OAAZ;AACD;;AAED,SAAO,sBAAA,CAAA,oBAAA,CAAqB;AAC1B,IAAA,QAAQ,EAAE;AACR,MAAA,WAAW,EAAE,cAAc,CAAC,OAAO,KAAA,IAAP,IAAA,OAAO,KAAA,KAAA,CAAP,GAAO,KAAA,CAAP,GAAA,OAAO,CAAE,WAAV;AADnB;AADgB,GAArB,CAAP;AAKD,CAZM;;AAAM,OAAA,CAAA,iBAAA,GAAiB,iBAAjB;;AAcb,MAAM,cAAc,GAClB,WADqB,IAEoB;AACzC,UAAQ,WAAR;AACE,SAAK,WAAL;AACE,aAAO,SAAA,CAAA,KAAA,CAAM,qBAAN,CAA4B,SAAnC;;AACF,SAAK,SAAL;AACE,aAAO,SAAA,CAAA,KAAA,CAAM,qBAAN,CAA4B,OAAnC;;AACF,SAAK,kBAAL;AACE,aAAO,SAAA,CAAA,KAAA,CAAM,qBAAN,CAA4B,gBAAnC;;AACF;AACE,aAAO,SAAP;AARJ;AAUD,CAbD","sourcesContent":["import { Types, getGroupper } from 'tabster';\nimport { useTabsterAttributes } from './useTabsterAttributes';\nimport { useTabster } from './useTabster';\n\nexport interface UseFocusableGroupOptions {\n /**\n * Behavior for the Tab key.\n */\n tabBehavior?: 'unlimited' | 'limited' | 'limitedTrapFocus';\n}\n\n/**\n * A hook that returns the necessary tabster attributes to support groupping.\n * @param options - Options to configure keyboard navigation\n */\nexport const useFocusableGroup = (options?: UseFocusableGroupOptions) => {\n const tabster = useTabster();\n\n if (tabster) {\n getGroupper(tabster);\n }\n\n return useTabsterAttributes({\n groupper: {\n tabbability: getTabbability(options?.tabBehavior),\n },\n });\n};\n\nconst getTabbability = (\n tabBehavior?: UseFocusableGroupOptions['tabBehavior'],\n): Types.GroupperTabbability | undefined => {\n switch (tabBehavior) {\n case 'unlimited':\n return Types.GroupperTabbabilities.Unlimited;\n case 'limited':\n return Types.GroupperTabbabilities.Limited;\n case 'limitedTrapFocus':\n return Types.GroupperTabbabilities.LimitedTrapFocus;\n default:\n return undefined;\n }\n};\n"],"sourceRoot":"../src/"}
|
@@ -0,0 +1,54 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.useKeyboardNavAttribute = void 0;
|
7
|
+
|
8
|
+
const keyborg_1 = /*#__PURE__*/require("keyborg");
|
9
|
+
|
10
|
+
const react_1 = /*#__PURE__*/require("react");
|
11
|
+
|
12
|
+
const symbols_1 = /*#__PURE__*/require("../symbols");
|
13
|
+
|
14
|
+
const react_shared_contexts_1 = /*#__PURE__*/require("@fluentui/react-shared-contexts");
|
15
|
+
/**
|
16
|
+
* instantiates keyborg and add attribute to ensure focus indicator synced to keyborg logic
|
17
|
+
*/
|
18
|
+
|
19
|
+
|
20
|
+
function useKeyboardNavAttribute() {
|
21
|
+
const {
|
22
|
+
targetDocument
|
23
|
+
} = react_shared_contexts_1.useFluent();
|
24
|
+
const keyborg = react_1.useMemo(() => targetDocument && keyborg_1.createKeyborg(targetDocument.defaultView), [targetDocument]);
|
25
|
+
const ref = react_1.useRef(null);
|
26
|
+
react_1.useEffect(() => {
|
27
|
+
if (keyborg) {
|
28
|
+
setBooleanAttribute(ref, symbols_1.KEYBOARD_NAV_ATTRIBUTE, keyborg.isNavigatingWithKeyboard());
|
29
|
+
|
30
|
+
const cb = next => {
|
31
|
+
setBooleanAttribute(ref, symbols_1.KEYBOARD_NAV_ATTRIBUTE, next);
|
32
|
+
};
|
33
|
+
|
34
|
+
keyborg.subscribe(cb);
|
35
|
+
return () => keyborg.unsubscribe(cb);
|
36
|
+
}
|
37
|
+
}, [keyborg]);
|
38
|
+
return ref;
|
39
|
+
}
|
40
|
+
|
41
|
+
exports.useKeyboardNavAttribute = useKeyboardNavAttribute;
|
42
|
+
|
43
|
+
function setBooleanAttribute(elementRef, attribute, value) {
|
44
|
+
if (!elementRef.current) {
|
45
|
+
return;
|
46
|
+
}
|
47
|
+
|
48
|
+
if (value) {
|
49
|
+
elementRef.current.setAttribute(attribute, '');
|
50
|
+
} else {
|
51
|
+
elementRef.current.removeAttribute(attribute);
|
52
|
+
}
|
53
|
+
}
|
54
|
+
//# sourceMappingURL=useKeyboardNavAttribute.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["hooks/useKeyboardNavAttribute.ts"],"names":[],"mappings":";;;;;;;AAAA,MAAA,SAAA,gBAAA,OAAA,CAAA,SAAA,CAAA;;AACA,MAAA,OAAA,gBAAA,OAAA,CAAA,OAAA,CAAA;;AACA,MAAA,SAAA,gBAAA,OAAA,CAAA,YAAA,CAAA;;AACA,MAAA,uBAAA,gBAAA,OAAA,CAAA,iCAAA,CAAA;AAIA;;AAEG;;;AACH,SAAgB,uBAAhB,GAAuC;AACrC,QAAM;AAAE,IAAA;AAAF,MAAqB,uBAAA,CAAA,SAAA,EAA3B;AACA,QAAM,OAAO,GAAG,OAAA,CAAA,OAAA,CAAQ,MAAM,cAAc,IAAI,SAAA,CAAA,aAAA,CAAc,cAAc,CAAC,WAA7B,CAAhC,EAA4E,CAAC,cAAD,CAA5E,CAAhB;AACA,QAAM,GAAG,GAAG,OAAA,CAAA,MAAA,CAAU,IAAV,CAAZ;AACA,EAAA,OAAA,CAAA,SAAA,CAAU,MAAK;AACb,QAAI,OAAJ,EAAa;AACX,MAAA,mBAAmB,CAAC,GAAD,EAAM,SAAA,CAAA,sBAAN,EAA8B,OAAO,CAAC,wBAAR,EAA9B,CAAnB;;AACA,YAAM,EAAE,GAAoB,IAAI,IAAG;AACjC,QAAA,mBAAmB,CAAC,GAAD,EAAM,SAAA,CAAA,sBAAN,EAA8B,IAA9B,CAAnB;AACD,OAFD;;AAGA,MAAA,OAAO,CAAC,SAAR,CAAkB,EAAlB;AACA,aAAO,MAAM,OAAO,CAAC,WAAR,CAAoB,EAApB,CAAb;AACD;AACF,GATD,EASG,CAAC,OAAD,CATH;AAUA,SAAO,GAAP;AACD;;AAfD,OAAA,CAAA,uBAAA,GAAA,uBAAA;;AAiBA,SAAS,mBAAT,CAA6B,UAA7B,EAAiE,SAAjE,EAAoF,KAApF,EAAkG;AAChG,MAAI,CAAC,UAAU,CAAC,OAAhB,EAAyB;AACvB;AACD;;AACD,MAAI,KAAJ,EAAW;AACT,IAAA,UAAU,CAAC,OAAX,CAAmB,YAAnB,CAAgC,SAAhC,EAA2C,EAA3C;AACD,GAFD,MAEO;AACL,IAAA,UAAU,CAAC,OAAX,CAAmB,eAAnB,CAAmC,SAAnC;AACD;AACF","sourcesContent":["import { createKeyborg } from 'keyborg';\nimport { useEffect, useMemo, useRef } from 'react';\nimport { KEYBOARD_NAV_ATTRIBUTE } from '../symbols';\nimport { useFluent } from '@fluentui/react-shared-contexts';\nimport type { KeyborgCallback } from 'keyborg/dist/Keyborg';\nimport type { RefObject } from 'react';\n\n/**\n * instantiates keyborg and add attribute to ensure focus indicator synced to keyborg logic\n */\nexport function useKeyboardNavAttribute<E extends HTMLElement>() {\n const { targetDocument } = useFluent();\n const keyborg = useMemo(() => targetDocument && createKeyborg(targetDocument.defaultView!), [targetDocument]);\n const ref = useRef<E>(null);\n useEffect(() => {\n if (keyborg) {\n setBooleanAttribute(ref, KEYBOARD_NAV_ATTRIBUTE, keyborg.isNavigatingWithKeyboard());\n const cb: KeyborgCallback = next => {\n setBooleanAttribute(ref, KEYBOARD_NAV_ATTRIBUTE, next);\n };\n keyborg.subscribe(cb);\n return () => keyborg.unsubscribe(cb);\n }\n }, [keyborg]);\n return ref;\n}\n\nfunction setBooleanAttribute(elementRef: RefObject<HTMLElement>, attribute: string, value: boolean) {\n if (!elementRef.current) {\n return;\n }\n if (value) {\n elementRef.current.setAttribute(attribute, '');\n } else {\n elementRef.current.removeAttribute(attribute);\n }\n}\n"],"sourceRoot":"../src/"}
|
@@ -0,0 +1,22 @@
|
|
1
|
+
import { Types as TabsterTypes } from 'tabster';
|
2
|
+
export interface UseModalAttributesOptions {
|
3
|
+
/**
|
4
|
+
* Traps focus inside the elements the attributes are applied
|
5
|
+
*/
|
6
|
+
trapFocus?: boolean;
|
7
|
+
/**
|
8
|
+
* Always reachabled in Tab order
|
9
|
+
*/
|
10
|
+
alwaysFocusable?: boolean;
|
11
|
+
}
|
12
|
+
/**
|
13
|
+
* Applies modal dialog behaviour through DOM attributes
|
14
|
+
* Modal element will focus trap and hide other content on the page
|
15
|
+
* The trigger element will be focused if focus is lost after the modal element is removed
|
16
|
+
*
|
17
|
+
* @returns DOM attributes to apply to the modal element and its trigger
|
18
|
+
*/
|
19
|
+
export declare const useModalAttributes: (options?: UseModalAttributesOptions) => {
|
20
|
+
modalAttributes: TabsterTypes.TabsterDOMAttribute;
|
21
|
+
triggerAttributes: TabsterTypes.TabsterDOMAttribute;
|
22
|
+
};
|