@fluentui/react-tabster 9.7.4 → 9.7.5
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 +36 -1
- package/CHANGELOG.md +13 -2
- package/dist/index.d.ts +1 -1
- package/lib/focus/constants.js +4 -7
- package/lib/focus/constants.js.map +1 -1
- package/lib/focus/createCustomFocusIndicatorStyle.js +9 -13
- package/lib/focus/createCustomFocusIndicatorStyle.js.map +1 -1
- package/lib/focus/createFocusOutlineStyle.js +49 -52
- package/lib/focus/createFocusOutlineStyle.js.map +1 -1
- package/lib/focus/focusVisiblePolyfill.js +56 -58
- package/lib/focus/focusVisiblePolyfill.js.map +1 -1
- package/lib/focus/focusWithinPolyfill.js +36 -38
- package/lib/focus/focusWithinPolyfill.js.map +1 -1
- package/lib/focus/index.js +0 -1
- package/lib/focus/index.js.map +1 -1
- package/lib/hooks/index.js +0 -1
- package/lib/hooks/index.js.map +1 -1
- package/lib/hooks/useArrowNavigationGroup.js +32 -41
- package/lib/hooks/useArrowNavigationGroup.js.map +1 -1
- package/lib/hooks/useFocusFinders.js +59 -55
- package/lib/hooks/useFocusFinders.js.map +1 -1
- package/lib/hooks/useFocusVisible.js +13 -11
- package/lib/hooks/useFocusVisible.js.map +1 -1
- package/lib/hooks/useFocusWithin.js +12 -13
- package/lib/hooks/useFocusWithin.js.map +1 -1
- package/lib/hooks/useFocusableGroup.js +20 -22
- package/lib/hooks/useFocusableGroup.js.map +1 -1
- package/lib/hooks/useKeyboardNavAttribute.js +27 -27
- package/lib/hooks/useKeyboardNavAttribute.js.map +1 -1
- package/lib/hooks/useModalAttributes.js +24 -30
- package/lib/hooks/useModalAttributes.js.map +1 -1
- package/lib/hooks/useTabster.js +24 -24
- package/lib/hooks/useTabster.js.map +1 -1
- package/lib/hooks/useTabsterAttributes.js +5 -7
- package/lib/hooks/useTabsterAttributes.js.map +1 -1
- package/lib/index.js +0 -1
- package/lib/index.js.map +1 -1
- package/lib-commonjs/focus/constants.js +1 -3
- package/lib-commonjs/focus/constants.js.map +1 -1
- package/lib-commonjs/focus/createCustomFocusIndicatorStyle.js +1 -3
- package/lib-commonjs/focus/createCustomFocusIndicatorStyle.js.map +1 -1
- package/lib-commonjs/focus/createFocusOutlineStyle.js +19 -12
- package/lib-commonjs/focus/createFocusOutlineStyle.js.map +1 -1
- package/lib-commonjs/focus/focusVisiblePolyfill.js +1 -3
- package/lib-commonjs/focus/focusVisiblePolyfill.js.map +1 -1
- package/lib-commonjs/focus/focusWithinPolyfill.js +1 -3
- package/lib-commonjs/focus/focusWithinPolyfill.js.map +1 -1
- package/lib-commonjs/focus/index.js +0 -3
- package/lib-commonjs/focus/index.js.map +1 -1
- package/lib-commonjs/hooks/index.js +0 -3
- package/lib-commonjs/hooks/index.js.map +1 -1
- package/lib-commonjs/hooks/useArrowNavigationGroup.js +2 -5
- package/lib-commonjs/hooks/useArrowNavigationGroup.js.map +1 -1
- package/lib-commonjs/hooks/useFocusFinders.js +1 -3
- package/lib-commonjs/hooks/useFocusFinders.js.map +1 -1
- package/lib-commonjs/hooks/useFocusVisible.js +1 -3
- package/lib-commonjs/hooks/useFocusVisible.js.map +1 -1
- package/lib-commonjs/hooks/useFocusWithin.js +1 -3
- package/lib-commonjs/hooks/useFocusWithin.js.map +1 -1
- package/lib-commonjs/hooks/useFocusableGroup.js +1 -3
- package/lib-commonjs/hooks/useFocusableGroup.js.map +1 -1
- package/lib-commonjs/hooks/useKeyboardNavAttribute.js +1 -3
- package/lib-commonjs/hooks/useKeyboardNavAttribute.js.map +1 -1
- package/lib-commonjs/hooks/useModalAttributes.js +1 -3
- package/lib-commonjs/hooks/useModalAttributes.js.map +1 -1
- package/lib-commonjs/hooks/useTabster.js +1 -3
- package/lib-commonjs/hooks/useTabster.js.map +1 -1
- package/lib-commonjs/hooks/useTabsterAttributes.js +1 -3
- package/lib-commonjs/hooks/useTabsterAttributes.js.map +1 -1
- package/lib-commonjs/index.js +0 -3
- package/lib-commonjs/index.js.map +1 -1
- package/package.json +3 -3
@@ -4,47 +4,38 @@ import { useTabster } from './useTabster';
|
|
4
4
|
/**
|
5
5
|
* A hook that returns the necessary tabster attributes to support arrow key navigation
|
6
6
|
* @param options - Options to configure keyboard navigation
|
7
|
-
*/
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
hasDefault: unstable_hasDefault
|
29
|
-
},
|
30
|
-
...(ignoreDefaultKeydown && {
|
31
|
-
focusable: {
|
32
|
-
ignoreKeydown: ignoreDefaultKeydown
|
33
|
-
}
|
34
|
-
})
|
35
|
-
});
|
7
|
+
*/ export const useArrowNavigationGroup = (options = {})=>{
|
8
|
+
const { circular , axis , memorizeCurrent , tabbable , ignoreDefaultKeydown , // eslint-disable-next-line @typescript-eslint/naming-convention
|
9
|
+
unstable_hasDefault } = options;
|
10
|
+
const tabster = useTabster();
|
11
|
+
if (tabster) {
|
12
|
+
getMover(tabster);
|
13
|
+
}
|
14
|
+
return useTabsterAttributes({
|
15
|
+
mover: {
|
16
|
+
cyclic: !!circular,
|
17
|
+
direction: axisToMoverDirection(axis !== null && axis !== void 0 ? axis : 'vertical'),
|
18
|
+
memorizeCurrent,
|
19
|
+
tabbable,
|
20
|
+
hasDefault: unstable_hasDefault
|
21
|
+
},
|
22
|
+
...ignoreDefaultKeydown && {
|
23
|
+
focusable: {
|
24
|
+
ignoreKeydown: ignoreDefaultKeydown
|
25
|
+
}
|
26
|
+
}
|
27
|
+
});
|
36
28
|
};
|
37
29
|
function axisToMoverDirection(axis) {
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
30
|
+
switch(axis){
|
31
|
+
case 'horizontal':
|
32
|
+
return Types.MoverDirections.Horizontal;
|
33
|
+
case 'grid':
|
34
|
+
return Types.MoverDirections.Grid;
|
35
|
+
case 'both':
|
36
|
+
return Types.MoverDirections.Both;
|
37
|
+
case 'vertical':
|
38
|
+
default:
|
39
|
+
return Types.MoverDirections.Vertical;
|
40
|
+
}
|
49
41
|
}
|
50
|
-
//# sourceMappingURL=useArrowNavigationGroup.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"sources":["useArrowNavigationGroup.ts"],"sourcesContent":["import { Types, getMover } from 'tabster';\nimport { useTabsterAttributes } from './useTabsterAttributes';\nimport { useTabster } from './useTabster';\n\nexport interface UseArrowNavigationGroupOptions {\n /**\n * Focus will navigate vertically, horizontally or in both directions (grid), defaults to horizontally\n * @defaultValue vertical\n */\n axis?: 'vertical' | 'horizontal' | 'grid' | 'both';\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 * Allow tabbing within the arrow navigation group items.\n */\n tabbable?: boolean;\n /**\n * Tabster should ignore default handling of keydown events\n */\n ignoreDefaultKeydown?: Types.FocusableProps['ignoreKeydown'];\n /**\n * The default focusable item in the group will be an element with Focusable.isDefault property.\n * Note that there is no way in \\@fluentui/react-tabster to set default focusable element,\n * and this option is currently for internal testing purposes only.\n */\n // eslint-disable-next-line @typescript-eslint/naming-convention\n unstable_hasDefault?: 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 = {}): Types.TabsterDOMAttribute => {\n const {\n circular,\n axis,\n memorizeCurrent,\n tabbable,\n ignoreDefaultKeydown,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n unstable_hasDefault,\n } = options;\n const tabster = useTabster();\n\n if (tabster) {\n getMover(tabster);\n }\n\n return useTabsterAttributes({\n mover: {\n cyclic: !!circular,\n direction: axisToMoverDirection(axis ?? 'vertical'),\n memorizeCurrent,\n tabbable,\n hasDefault: unstable_hasDefault,\n },\n ...(ignoreDefaultKeydown && {\n focusable: {\n ignoreKeydown: ignoreDefaultKeydown,\n },\n }),\n });\n};\n\nfunction axisToMoverDirection(axis: UseArrowNavigationGroupOptions['axis']): Types.MoverDirection {\n switch (axis) {\n case 'horizontal':\n return Types.MoverDirections.Horizontal;\n case 'grid':\n return Types.MoverDirections.Grid;\n case 'both':\n return Types.MoverDirections.Both;\n\n case 'vertical':\n default:\n return Types.MoverDirections.Vertical;\n }\n}\n"],"names":["Types","getMover","useTabsterAttributes","useTabster","useArrowNavigationGroup","options","circular","axis","memorizeCurrent","tabbable","ignoreDefaultKeydown","unstable_hasDefault","tabster","mover","cyclic","direction","axisToMoverDirection","hasDefault","focusable","ignoreKeydown","MoverDirections","Horizontal","Grid","Both","Vertical"],"mappings":"AAAA,SAASA,KAAK,EAAEC,QAAQ,QAAQ,UAAU;AAC1C,SAASC,oBAAoB,QAAQ,yBAAyB;AAC9D,SAASC,UAAU,QAAQ,eAAe;AAkC1C;;;CAGC,GACD,OAAO,MAAMC,0BAA0B,CAACC,UAA0C,CAAC,CAAC,GAAgC;IAClH,MAAM,EACJC,SAAQ,EACRC,KAAI,EACJC,gBAAe,EACfC,SAAQ,EACRC,qBAAoB,EACpB,gEAAgE;IAChEC,oBAAmB,EACpB,GAAGN;IACJ,MAAMO,UAAUT;IAEhB,IAAIS,SAAS;QACXX,SAASW;IACX,CAAC;IAED,OAAOV,qBAAqB;QAC1BW,OAAO;YACLC,QAAQ,CAAC,CAACR;YACVS,WAAWC,qBAAqBT,iBAAAA,kBAAAA,OAAQ,UAAU;YAClDC;YACAC;YACAQ,YAAYN;QACd;QACA,GAAID,wBAAwB;YAC1BQ,WAAW;gBACTC,eAAeT;YACjB;QACF,CAAC;IACH;AACF,EAAE;AAEF,SAASM,qBAAqBT,IAA4C,EAAwB;IAChG,OAAQA;QACN,KAAK;YACH,OAAOP,MAAMoB,eAAe,CAACC,UAAU;QACzC,KAAK;YACH,OAAOrB,MAAMoB,eAAe,CAACE,IAAI;QACnC,KAAK;YACH,OAAOtB,MAAMoB,eAAe,CAACG,IAAI;QAEnC,KAAK;QACL;YACE,OAAOvB,MAAMoB,eAAe,CAACI,QAAQ;IACzC;AACF"}
|
@@ -3,59 +3,63 @@ import { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts
|
|
3
3
|
import { useTabster } from './useTabster';
|
4
4
|
/**
|
5
5
|
* Returns a set of helper functions that will traverse focusable elements in the context of a root DOM element
|
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
|
-
const {
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
6
|
+
*/ export const useFocusFinders = ()=>{
|
7
|
+
const tabster = useTabster();
|
8
|
+
const { targetDocument } = useFluent();
|
9
|
+
// Narrow props for now and let need dictate additional props in the future
|
10
|
+
const findAllFocusable = React.useCallback((container, acceptCondition)=>{
|
11
|
+
return (tabster === null || tabster === void 0 ? void 0 : tabster.focusable.findAll({
|
12
|
+
container,
|
13
|
+
acceptCondition
|
14
|
+
})) || [];
|
15
|
+
}, [
|
16
|
+
tabster
|
17
|
+
]);
|
18
|
+
const findFirstFocusable = React.useCallback((container)=>{
|
19
|
+
return tabster === null || tabster === void 0 ? void 0 : tabster.focusable.findFirst({
|
20
|
+
container
|
21
|
+
});
|
22
|
+
}, [
|
23
|
+
tabster
|
24
|
+
]);
|
25
|
+
const findLastFocusable = React.useCallback((container)=>{
|
26
|
+
return tabster === null || tabster === void 0 ? void 0 : tabster.focusable.findLast({
|
27
|
+
container
|
28
|
+
});
|
29
|
+
}, [
|
30
|
+
tabster
|
31
|
+
]);
|
32
|
+
const findNextFocusable = React.useCallback((currentElement, options = {})=>{
|
33
|
+
if (!tabster || !targetDocument) {
|
34
|
+
return null;
|
35
|
+
}
|
36
|
+
const { container =targetDocument.body } = options;
|
37
|
+
return tabster.focusable.findNext({
|
38
|
+
currentElement,
|
39
|
+
container
|
40
|
+
});
|
41
|
+
}, [
|
42
|
+
tabster,
|
43
|
+
targetDocument
|
44
|
+
]);
|
45
|
+
const findPrevFocusable = React.useCallback((currentElement, options = {})=>{
|
46
|
+
if (!tabster || !targetDocument) {
|
47
|
+
return null;
|
48
|
+
}
|
49
|
+
const { container =targetDocument.body } = options;
|
50
|
+
return tabster.focusable.findPrev({
|
51
|
+
currentElement,
|
52
|
+
container
|
53
|
+
});
|
54
|
+
}, [
|
55
|
+
tabster,
|
56
|
+
targetDocument
|
57
|
+
]);
|
58
|
+
return {
|
59
|
+
findAllFocusable,
|
60
|
+
findFirstFocusable,
|
61
|
+
findLastFocusable,
|
62
|
+
findNextFocusable,
|
63
|
+
findPrevFocusable
|
64
|
+
};
|
60
65
|
};
|
61
|
-
//# sourceMappingURL=useFocusFinders.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"sources":["useFocusFinders.ts"],"sourcesContent":["import * as React from 'react';\nimport { Types as TabsterTypes } from 'tabster';\nimport { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\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 const { targetDocument } = useFluent();\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(\n (container: HTMLElement) => tabster?.focusable.findLast({ container }),\n [tabster],\n );\n\n const findNextFocusable = React.useCallback(\n (currentElement: HTMLElement, options: Pick<Partial<TabsterTypes.FindNextProps>, 'container'> = {}) => {\n if (!tabster || !targetDocument) {\n return null;\n }\n\n const { container = targetDocument.body } = options;\n\n return tabster.focusable.findNext({ currentElement, container });\n },\n [tabster, targetDocument],\n );\n\n const findPrevFocusable = React.useCallback(\n (currentElement: HTMLElement, options: Pick<Partial<TabsterTypes.FindNextProps>, 'container'> = {}) => {\n if (!tabster || !targetDocument) {\n return null;\n }\n\n const { container = targetDocument.body } = options;\n\n return tabster.focusable.findPrev({ currentElement, container });\n },\n [tabster, targetDocument],\n );\n\n return {\n findAllFocusable,\n findFirstFocusable,\n findLastFocusable,\n findNextFocusable,\n findPrevFocusable,\n };\n};\n"],"names":["React","useFluent_unstable","useFluent","useTabster","useFocusFinders","tabster","targetDocument","findAllFocusable","useCallback","container","acceptCondition","focusable","findAll","findFirstFocusable","findFirst","findLastFocusable","findLast","findNextFocusable","currentElement","options","body","findNext","findPrevFocusable","findPrev"],"mappings":"AAAA,YAAYA,WAAW,QAAQ;AAE/B,SAASC,sBAAsBC,SAAS,QAAQ,kCAAkC;AAClF,SAASC,UAAU,QAAQ,eAAe;AAE1C;;CAEC,GACD,OAAO,MAAMC,kBAAkB,IAAM;IACnC,MAAMC,UAAUF;IAChB,MAAM,EAAEG,eAAc,EAAE,GAAGJ;IAE3B,2EAA2E;IAC3E,MAAMK,mBAAmBP,MAAMQ,WAAW,CACxC,CAACC,WAAwBC;QACvBL,OAAAA,CAAAA,oBAAAA,qBAAAA,KAAAA,IAAAA,QAASM,SAAS,CAACC,OAAO,CAAC;YAAEH;YAAWC;QAAgB,EAAE,AAAD,KAAK,EAAE;OAClE;QAACL;KAAQ;IAGX,MAAMQ,qBAAqBb,MAAMQ,WAAW,CAC1C,CAACC;QAA2BJ,OAAAA,oBAAAA,qBAAAA,KAAAA,IAAAA,QAASM,SAAS,CAACG,SAAS,CAAC;YAAEL;QAAU,EAAE;OACvE;QAACJ;KAAQ;IAGX,MAAMU,oBAAoBf,MAAMQ,WAAW,CACzC,CAACC;QAA2BJ,OAAAA,oBAAAA,qBAAAA,KAAAA,IAAAA,QAASM,SAAS,CAACK,QAAQ,CAAC;YAAEP;QAAU,EAAE;OACtE;QAACJ;KAAQ;IAGX,MAAMY,oBAAoBjB,MAAMQ,WAAW,CACzC,CAACU,gBAA6BC,UAAkE,CAAC,CAAC,GAAK;QACrG,IAAI,CAACd,WAAW,CAACC,gBAAgB;YAC/B,OAAO,IAAI;QACb,CAAC;QAED,MAAM,EAAEG,WAAYH,eAAec,IAAI,CAAA,EAAE,GAAGD;QAE5C,OAAOd,QAAQM,SAAS,CAACU,QAAQ,CAAC;YAAEH;YAAgBT;QAAU;IAChE,GACA;QAACJ;QAASC;KAAe;IAG3B,MAAMgB,oBAAoBtB,MAAMQ,WAAW,CACzC,CAACU,gBAA6BC,UAAkE,CAAC,CAAC,GAAK;QACrG,IAAI,CAACd,WAAW,CAACC,gBAAgB;YAC/B,OAAO,IAAI;QACb,CAAC;QAED,MAAM,EAAEG,WAAYH,eAAec,IAAI,CAAA,EAAE,GAAGD;QAE5C,OAAOd,QAAQM,SAAS,CAACY,QAAQ,CAAC;YAAEL;YAAgBT;QAAU;IAChE,GACA;QAACJ;QAASC;KAAe;IAG3B,OAAO;QACLC;QACAM;QACAE;QACAE;QACAK;IACF;AACF,EAAE"}
|
@@ -2,15 +2,17 @@ import * as React from 'react';
|
|
2
2
|
import { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';
|
3
3
|
import { applyFocusVisiblePolyfill } from '../focus/focusVisiblePolyfill';
|
4
4
|
export function useFocusVisible(options = {}) {
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
5
|
+
const contentValue = useFluent();
|
6
|
+
const scopeRef = React.useRef(null);
|
7
|
+
var _options_targetDocument;
|
8
|
+
const targetDocument = (_options_targetDocument = options.targetDocument) !== null && _options_targetDocument !== void 0 ? _options_targetDocument : contentValue.targetDocument;
|
9
|
+
React.useEffect(()=>{
|
10
|
+
if ((targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.defaultView) && scopeRef.current) {
|
11
|
+
return applyFocusVisiblePolyfill(scopeRef.current, targetDocument.defaultView);
|
12
|
+
}
|
13
|
+
}, [
|
14
|
+
scopeRef,
|
15
|
+
targetDocument
|
16
|
+
]);
|
17
|
+
return scopeRef;
|
15
18
|
}
|
16
|
-
//# sourceMappingURL=useFocusVisible.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"sources":["useFocusVisible.ts"],"sourcesContent":["import * as React from 'react';\nimport { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\n\nimport { applyFocusVisiblePolyfill } from '../focus/focusVisiblePolyfill';\n\ntype UseFocusVisibleOptions = {\n targetDocument?: Document;\n};\n\nexport function useFocusVisible<TElement extends HTMLElement = HTMLElement>(options: UseFocusVisibleOptions = {}) {\n const contentValue = useFluent();\n const scopeRef = React.useRef<TElement>(null);\n\n const targetDocument = options.targetDocument ?? contentValue.targetDocument;\n\n React.useEffect(() => {\n if (targetDocument?.defaultView && scopeRef.current) {\n return applyFocusVisiblePolyfill(scopeRef.current, targetDocument.defaultView);\n }\n }, [scopeRef, targetDocument]);\n\n return scopeRef;\n}\n"],"names":["React","useFluent_unstable","useFluent","applyFocusVisiblePolyfill","useFocusVisible","options","contentValue","scopeRef","useRef","targetDocument","useEffect","defaultView","current"],"mappings":"AAAA,YAAYA,WAAW,QAAQ;AAC/B,SAASC,sBAAsBC,SAAS,QAAQ,kCAAkC;AAElF,SAASC,yBAAyB,QAAQ,gCAAgC;AAM1E,OAAO,SAASC,gBAA4DC,UAAkC,CAAC,CAAC,EAAE;IAChH,MAAMC,eAAeJ;IACrB,MAAMK,WAAWP,MAAMQ,MAAM,CAAW,IAAI;QAErBH;IAAvB,MAAMI,iBAAiBJ,CAAAA,0BAAAA,QAAQI,cAAc,cAAtBJ,qCAAAA,0BAA0BC,aAAaG,cAAc;IAE5ET,MAAMU,SAAS,CAAC,IAAM;QACpB,IAAID,CAAAA,2BAAAA,4BAAAA,KAAAA,IAAAA,eAAgBE,WAAW,AAAD,KAAKJ,SAASK,OAAO,EAAE;YACnD,OAAOT,0BAA0BI,SAASK,OAAO,EAAEH,eAAeE,WAAW;QAC/E,CAAC;IACH,GAAG;QAACJ;QAAUE;KAAe;IAE7B,OAAOF;AACT,CAAC"}
|
@@ -5,17 +5,16 @@ import { applyFocusWithinPolyfill } from '../focus/focusWithinPolyfill';
|
|
5
5
|
* A ponyfill that allows `:focus-within` to support visibility based on keyboard/mouse navigation
|
6
6
|
* like `:focus-visible` https://github.com/WICG/focus-visible/issues/151
|
7
7
|
* @returns ref to the element that uses `:focus-within` styles
|
8
|
-
*/
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
8
|
+
*/ export function useFocusWithin() {
|
9
|
+
const { targetDocument } = useFluent();
|
10
|
+
const elementRef = React.useRef(null);
|
11
|
+
React.useEffect(()=>{
|
12
|
+
if ((targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.defaultView) && elementRef.current) {
|
13
|
+
return applyFocusWithinPolyfill(elementRef.current, targetDocument.defaultView);
|
14
|
+
}
|
15
|
+
}, [
|
16
|
+
elementRef,
|
17
|
+
targetDocument
|
18
|
+
]);
|
19
|
+
return elementRef;
|
20
20
|
}
|
21
|
-
//# sourceMappingURL=useFocusWithin.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"sources":["useFocusWithin.ts"],"sourcesContent":["import * as React from 'react';\nimport { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\nimport { applyFocusWithinPolyfill } from '../focus/focusWithinPolyfill';\n\n/**\n * A ponyfill that allows `:focus-within` to support visibility based on keyboard/mouse navigation\n * like `:focus-visible` https://github.com/WICG/focus-visible/issues/151\n * @returns ref to the element that uses `:focus-within` styles\n */\nexport function useFocusWithin<TElement extends HTMLElement = HTMLElement>() {\n const { targetDocument } = useFluent();\n const elementRef = React.useRef<TElement>(null);\n\n React.useEffect(() => {\n if (targetDocument?.defaultView && elementRef.current) {\n return applyFocusWithinPolyfill(elementRef.current, targetDocument.defaultView);\n }\n }, [elementRef, targetDocument]);\n\n return elementRef;\n}\n"],"names":["React","useFluent_unstable","useFluent","applyFocusWithinPolyfill","useFocusWithin","targetDocument","elementRef","useRef","useEffect","defaultView","current"],"mappings":"AAAA,YAAYA,WAAW,QAAQ;AAC/B,SAASC,sBAAsBC,SAAS,QAAQ,kCAAkC;AAClF,SAASC,wBAAwB,QAAQ,+BAA+B;AAExE;;;;CAIC,GACD,OAAO,SAASC,iBAA6D;IAC3E,MAAM,EAAEC,eAAc,EAAE,GAAGH;IAC3B,MAAMI,aAAaN,MAAMO,MAAM,CAAW,IAAI;IAE9CP,MAAMQ,SAAS,CAAC,IAAM;QACpB,IAAIH,CAAAA,2BAAAA,4BAAAA,KAAAA,IAAAA,eAAgBI,WAAW,AAAD,KAAKH,WAAWI,OAAO,EAAE;YACrD,OAAOP,yBAAyBG,WAAWI,OAAO,EAAEL,eAAeI,WAAW;QAChF,CAAC;IACH,GAAG;QAACH;QAAYD;KAAe;IAE/B,OAAOC;AACT,CAAC"}
|
@@ -4,28 +4,26 @@ import { useTabster } from './useTabster';
|
|
4
4
|
/**
|
5
5
|
* A hook that returns the necessary tabster attributes to support groupping.
|
6
6
|
* @param options - Options to configure keyboard navigation
|
7
|
-
*/
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
getGroupper(tabster);
|
12
|
-
}
|
13
|
-
return useTabsterAttributes({
|
14
|
-
groupper: {
|
15
|
-
tabbability: getTabbability(options === null || options === void 0 ? void 0 : options.tabBehavior)
|
7
|
+
*/ export const useFocusableGroup = (options)=>{
|
8
|
+
const tabster = useTabster();
|
9
|
+
if (tabster) {
|
10
|
+
getGroupper(tabster);
|
16
11
|
}
|
17
|
-
|
12
|
+
return useTabsterAttributes({
|
13
|
+
groupper: {
|
14
|
+
tabbability: getTabbability(options === null || options === void 0 ? void 0 : options.tabBehavior)
|
15
|
+
}
|
16
|
+
});
|
18
17
|
};
|
19
|
-
const getTabbability = tabBehavior
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
18
|
+
const getTabbability = (tabBehavior)=>{
|
19
|
+
switch(tabBehavior){
|
20
|
+
case 'unlimited':
|
21
|
+
return Types.GroupperTabbabilities.Unlimited;
|
22
|
+
case 'limited':
|
23
|
+
return Types.GroupperTabbabilities.Limited;
|
24
|
+
case 'limited-trap-focus':
|
25
|
+
return Types.GroupperTabbabilities.LimitedTrapFocus;
|
26
|
+
default:
|
27
|
+
return undefined;
|
28
|
+
}
|
30
29
|
};
|
31
|
-
//# sourceMappingURL=useFocusableGroup.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"sources":["useFocusableGroup.ts"],"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' | 'limited-trap-focus';\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): Types.TabsterDOMAttribute => {\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 'limited-trap-focus':\n return Types.GroupperTabbabilities.LimitedTrapFocus;\n default:\n return undefined;\n }\n};\n"],"names":["Types","getGroupper","useTabsterAttributes","useTabster","useFocusableGroup","options","tabster","groupper","tabbability","getTabbability","tabBehavior","GroupperTabbabilities","Unlimited","Limited","LimitedTrapFocus","undefined"],"mappings":"AAAA,SAASA,KAAK,EAAEC,WAAW,QAAQ,UAAU;AAC7C,SAASC,oBAAoB,QAAQ,yBAAyB;AAC9D,SAASC,UAAU,QAAQ,eAAe;AAS1C;;;CAGC,GACD,OAAO,MAAMC,oBAAoB,CAACC,UAAkE;IAClG,MAAMC,UAAUH;IAEhB,IAAIG,SAAS;QACXL,YAAYK;IACd,CAAC;IAED,OAAOJ,qBAAqB;QAC1BK,UAAU;YACRC,aAAaC,eAAeJ,oBAAAA,qBAAAA,KAAAA,IAAAA,QAASK,WAAW;QAClD;IACF;AACF,EAAE;AAEF,MAAMD,iBAAiB,CACrBC,cAC0C;IAC1C,OAAQA;QACN,KAAK;YACH,OAAOV,MAAMW,qBAAqB,CAACC,SAAS;QAC9C,KAAK;YACH,OAAOZ,MAAMW,qBAAqB,CAACE,OAAO;QAC5C,KAAK;YACH,OAAOb,MAAMW,qBAAqB,CAACG,gBAAgB;QACrD;YACE,OAAOC;IACX;AACF"}
|
@@ -6,33 +6,33 @@ import { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts
|
|
6
6
|
* Instantiates [keyborg](https://github.com/microsoft/keyborg) and adds `data-keyboard-nav`
|
7
7
|
* attribute to a referenced element to ensure keyboard navigation awareness
|
8
8
|
* synced to keyborg logic without having to cause a re-render on react tree.
|
9
|
-
*/
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
}
|
25
|
-
|
26
|
-
|
9
|
+
*/ export function useKeyboardNavAttribute() {
|
10
|
+
const { targetDocument } = useFluent();
|
11
|
+
const keyborg = useMemo(()=>targetDocument && createKeyborg(targetDocument.defaultView), [
|
12
|
+
targetDocument
|
13
|
+
]);
|
14
|
+
const ref = useRef(null);
|
15
|
+
useEffect(()=>{
|
16
|
+
if (keyborg) {
|
17
|
+
setBooleanAttribute(ref, KEYBOARD_NAV_ATTRIBUTE, keyborg.isNavigatingWithKeyboard());
|
18
|
+
const cb = (next)=>{
|
19
|
+
setBooleanAttribute(ref, KEYBOARD_NAV_ATTRIBUTE, next);
|
20
|
+
};
|
21
|
+
keyborg.subscribe(cb);
|
22
|
+
return ()=>keyborg.unsubscribe(cb);
|
23
|
+
}
|
24
|
+
}, [
|
25
|
+
keyborg
|
26
|
+
]);
|
27
|
+
return ref;
|
27
28
|
}
|
28
29
|
function setBooleanAttribute(elementRef, attribute, value) {
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
30
|
+
if (!elementRef.current) {
|
31
|
+
return;
|
32
|
+
}
|
33
|
+
if (value) {
|
34
|
+
elementRef.current.setAttribute(attribute, '');
|
35
|
+
} else {
|
36
|
+
elementRef.current.removeAttribute(attribute);
|
37
|
+
}
|
37
38
|
}
|
38
|
-
//# sourceMappingURL=useKeyboardNavAttribute.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"sources":["useKeyboardNavAttribute.ts"],"sourcesContent":["import { createKeyborg } from 'keyborg';\nimport { useEffect, useMemo, useRef } from 'react';\nimport { KEYBOARD_NAV_ATTRIBUTE } from '../focus/constants';\nimport { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\nimport type { KeyborgCallback } from 'keyborg';\nimport type { RefObject } from 'react';\n\n/**\n * Instantiates [keyborg](https://github.com/microsoft/keyborg) and adds `data-keyboard-nav`\n * attribute to a referenced element to ensure keyboard navigation awareness\n * synced to keyborg logic without having to cause a re-render on react tree.\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"],"names":["createKeyborg","useEffect","useMemo","useRef","KEYBOARD_NAV_ATTRIBUTE","useFluent_unstable","useFluent","useKeyboardNavAttribute","targetDocument","keyborg","defaultView","ref","setBooleanAttribute","isNavigatingWithKeyboard","cb","next","subscribe","unsubscribe","elementRef","attribute","value","current","setAttribute","removeAttribute"],"mappings":"AAAA,SAASA,aAAa,QAAQ,UAAU;AACxC,SAASC,SAAS,EAAEC,OAAO,EAAEC,MAAM,QAAQ,QAAQ;AACnD,SAASC,sBAAsB,QAAQ,qBAAqB;AAC5D,SAASC,sBAAsBC,SAAS,QAAQ,kCAAkC;AAIlF;;;;CAIC,GACD,OAAO,SAASC,0BAAiD;IAC/D,MAAM,EAAEC,eAAc,EAAE,GAAGF;IAC3B,MAAMG,UAAUP,QAAQ,IAAMM,kBAAkBR,cAAcQ,eAAeE,WAAW,GAAI;QAACF;KAAe;IAC5G,MAAMG,MAAMR,OAAU,IAAI;IAC1BF,UAAU,IAAM;QACd,IAAIQ,SAAS;YACXG,oBAAoBD,KAAKP,wBAAwBK,QAAQI,wBAAwB;YACjF,MAAMC,KAAsBC,CAAAA,OAAQ;gBAClCH,oBAAoBD,KAAKP,wBAAwBW;YACnD;YACAN,QAAQO,SAAS,CAACF;YAClB,OAAO,IAAML,QAAQQ,WAAW,CAACH;QACnC,CAAC;IACH,GAAG;QAACL;KAAQ;IACZ,OAAOE;AACT,CAAC;AAED,SAASC,oBAAoBM,UAAkC,EAAEC,SAAiB,EAAEC,KAAc,EAAE;IAClG,IAAI,CAACF,WAAWG,OAAO,EAAE;QACvB;IACF,CAAC;IACD,IAAID,OAAO;QACTF,WAAWG,OAAO,CAACC,YAAY,CAACH,WAAW;IAC7C,OAAO;QACLD,WAAWG,OAAO,CAACE,eAAe,CAACJ;IACrC,CAAC;AACH"}
|
@@ -8,35 +8,29 @@ import { useTabster } from './useTabster';
|
|
8
8
|
* The trigger element will be focused if focus is lost after the modal element is removed
|
9
9
|
*
|
10
10
|
* @returns DOM attributes to apply to the modal element and its trigger
|
11
|
-
*/
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
const tabster = useTabster();
|
19
|
-
// Initializes the modalizer and deloser APIs
|
20
|
-
if (tabster) {
|
21
|
-
getModalizer(tabster);
|
22
|
-
getDeloser(tabster);
|
23
|
-
}
|
24
|
-
const id = useId('modal-', options.id);
|
25
|
-
const modalAttributes = useTabsterAttributes({
|
26
|
-
deloser: {},
|
27
|
-
modalizer: {
|
28
|
-
id,
|
29
|
-
isOthersAccessible: !trapFocus,
|
30
|
-
isAlwaysAccessible: alwaysFocusable,
|
31
|
-
isTrapped: legacyTrapFocus && trapFocus
|
11
|
+
*/ export const useModalAttributes = (options = {})=>{
|
12
|
+
const { trapFocus , alwaysFocusable , legacyTrapFocus } = options;
|
13
|
+
const tabster = useTabster();
|
14
|
+
// Initializes the modalizer and deloser APIs
|
15
|
+
if (tabster) {
|
16
|
+
getModalizer(tabster);
|
17
|
+
getDeloser(tabster);
|
32
18
|
}
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
19
|
+
const id = useId('modal-', options.id);
|
20
|
+
const modalAttributes = useTabsterAttributes({
|
21
|
+
deloser: {},
|
22
|
+
modalizer: {
|
23
|
+
id,
|
24
|
+
isOthersAccessible: !trapFocus,
|
25
|
+
isAlwaysAccessible: alwaysFocusable,
|
26
|
+
isTrapped: legacyTrapFocus && trapFocus
|
27
|
+
}
|
28
|
+
});
|
29
|
+
const triggerAttributes = useTabsterAttributes({
|
30
|
+
deloser: {}
|
31
|
+
});
|
32
|
+
return {
|
33
|
+
modalAttributes,
|
34
|
+
triggerAttributes
|
35
|
+
};
|
41
36
|
};
|
42
|
-
//# sourceMappingURL=useModalAttributes.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"sources":["useModalAttributes.ts"],"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 * Prefer this to `legacyTrapFocus`\n * it forbids users to tab out of the focus trap into the actual browser.\n */\n trapFocus?: boolean;\n\n /**\n * Traps focus inside the elements the attributes are applied.\n * This prop enables legacy behavior to match previous versions of Fluent and is not\n * recommended for general use.\n * Enabling `legacyTrapFocus` prevents users from tabbing out of the focus trap and into\n * the actual browser. Prefer using `trapFocus` instead of this prop.\n */\n legacyTrapFocus?: boolean;\n\n /**\n * Always reachabled in Tab order\n */\n alwaysFocusable?: boolean;\n\n /**\n * Id to use for the modalizer. An id will be generated if not provided.\n */\n id?: string;\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, legacyTrapFocus } = 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-', options.id);\n const modalAttributes = useTabsterAttributes({\n deloser: {},\n modalizer: {\n id,\n isOthersAccessible: !trapFocus,\n isAlwaysAccessible: alwaysFocusable,\n isTrapped: legacyTrapFocus && trapFocus,\n },\n });\n\n const triggerAttributes = useTabsterAttributes({\n deloser: {},\n });\n\n return { modalAttributes, triggerAttributes };\n};\n"],"names":["useId","useTabsterAttributes","getDeloser","getModalizer","useTabster","useModalAttributes","options","trapFocus","alwaysFocusable","legacyTrapFocus","tabster","id","modalAttributes","deloser","modalizer","isOthersAccessible","isAlwaysAccessible","isTrapped","triggerAttributes"],"mappings":"AAAA,SAASA,KAAK,QAAQ,4BAA4B;AAClD,SAASC,oBAAoB,QAAQ,yBAAyB;AAC9D,SAASC,UAAU,EAAEC,YAAY,QAA+B,UAAU;AAC1E,SAASC,UAAU,QAAQ,eAAe;AA8B1C;;;;;;CAMC,GACD,OAAO,MAAMC,qBAAqB,CAChCC,UAAqC,CAAC,CAAC,GACwE;IAC/G,MAAM,EAAEC,UAAS,EAAEC,gBAAe,EAAEC,gBAAe,EAAE,GAAGH;IACxD,MAAMI,UAAUN;IAChB,6CAA6C;IAC7C,IAAIM,SAAS;QACXP,aAAaO;QACbR,WAAWQ;IACb,CAAC;IAED,MAAMC,KAAKX,MAAM,UAAUM,QAAQK,EAAE;IACrC,MAAMC,kBAAkBX,qBAAqB;QAC3CY,SAAS,CAAC;QACVC,WAAW;YACTH;YACAI,oBAAoB,CAACR;YACrBS,oBAAoBR;YACpBS,WAAWR,mBAAmBF;QAChC;IACF;IAEA,MAAMW,oBAAoBjB,qBAAqB;QAC7CY,SAAS,CAAC;IACZ;IAEA,OAAO;QAAED;QAAiBM;IAAkB;AAC9C,EAAE"}
|