@fluentui/react-tabster 9.24.3 → 9.24.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.md +21 -2
- package/dist/index.d.ts +3 -2
- package/lib/hooks/useActivateModal.js +4 -4
- package/lib/hooks/useActivateModal.js.map +1 -1
- package/lib/hooks/useArrowNavigationGroup.js +1 -4
- package/lib/hooks/useArrowNavigationGroup.js.map +1 -1
- package/lib/hooks/useFocusFinders.js +25 -16
- package/lib/hooks/useFocusFinders.js.map +1 -1
- package/lib/hooks/useFocusObserved.js +8 -7
- package/lib/hooks/useFocusObserved.js.map +1 -1
- package/lib/hooks/useFocusableGroup.js +1 -4
- package/lib/hooks/useFocusableGroup.js.map +1 -1
- package/lib/hooks/useFocusedElementChange.js +14 -6
- package/lib/hooks/useFocusedElementChange.js.map +1 -1
- package/lib/hooks/useKeyborgRef.js +3 -2
- package/lib/hooks/useKeyborgRef.js.map +1 -1
- package/lib/hooks/useModalAttributes.js +5 -5
- package/lib/hooks/useModalAttributes.js.map +1 -1
- package/lib/hooks/useObservedElement.js +2 -5
- package/lib/hooks/useObservedElement.js.map +1 -1
- package/lib/hooks/useRestoreFocus.js +2 -8
- package/lib/hooks/useRestoreFocus.js.map +1 -1
- package/lib/hooks/useTabster.js +36 -23
- package/lib/hooks/useTabster.js.map +1 -1
- package/lib/index.js +1 -3
- package/lib/index.js.map +1 -1
- package/lib-commonjs/hooks/useActivateModal.js +4 -4
- package/lib-commonjs/hooks/useActivateModal.js.map +1 -1
- package/lib-commonjs/hooks/useArrowNavigationGroup.js +1 -4
- package/lib-commonjs/hooks/useArrowNavigationGroup.js.map +1 -1
- package/lib-commonjs/hooks/useFocusFinders.js +25 -16
- package/lib-commonjs/hooks/useFocusFinders.js.map +1 -1
- package/lib-commonjs/hooks/useFocusObserved.js +5 -5
- package/lib-commonjs/hooks/useFocusObserved.js.map +1 -1
- package/lib-commonjs/hooks/useFocusableGroup.js +1 -4
- package/lib-commonjs/hooks/useFocusableGroup.js.map +1 -1
- package/lib-commonjs/hooks/useFocusedElementChange.js +14 -6
- package/lib-commonjs/hooks/useFocusedElementChange.js.map +1 -1
- package/lib-commonjs/hooks/useKeyborgRef.js +3 -2
- package/lib-commonjs/hooks/useKeyborgRef.js.map +1 -1
- package/lib-commonjs/hooks/useModalAttributes.js +5 -5
- package/lib-commonjs/hooks/useModalAttributes.js.map +1 -1
- package/lib-commonjs/hooks/useObservedElement.js +2 -5
- package/lib-commonjs/hooks/useObservedElement.js.map +1 -1
- package/lib-commonjs/hooks/useRestoreFocus.js +2 -8
- package/lib-commonjs/hooks/useRestoreFocus.js.map +1 -1
- package/lib-commonjs/hooks/useTabster.js +44 -22
- package/lib-commonjs/hooks/useTabster.js.map +1 -1
- package/lib-commonjs/index.js +2 -4
- package/lib-commonjs/index.js.map +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
@@ -1,12 +1,31 @@
|
|
1
1
|
# Change Log - @fluentui/react-tabster
|
2
2
|
|
3
|
-
This log was last generated on
|
3
|
+
This log was last generated on Wed, 16 Apr 2025 19:37:27 GMT and should not be manually modified.
|
4
4
|
|
5
5
|
<!-- Start content -->
|
6
6
|
|
7
|
+
## [9.24.5](https://github.com/microsoft/fluentui/tree/@fluentui/react-tabster_v9.24.5)
|
8
|
+
|
9
|
+
Wed, 16 Apr 2025 19:37:27 GMT
|
10
|
+
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-tabster_v9.24.4..@fluentui/react-tabster_v9.24.5)
|
11
|
+
|
12
|
+
### Patches
|
13
|
+
|
14
|
+
- Bump @fluentui/react-utilities to v9.19.0 ([PR #34166](https://github.com/microsoft/fluentui/pull/34166) by beachball)
|
15
|
+
|
16
|
+
## [9.24.4](https://github.com/microsoft/fluentui/tree/@fluentui/react-tabster_v9.24.4)
|
17
|
+
|
18
|
+
Tue, 01 Apr 2025 15:08:01 GMT
|
19
|
+
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-tabster_v9.24.3..@fluentui/react-tabster_v9.24.4)
|
20
|
+
|
21
|
+
### Patches
|
22
|
+
|
23
|
+
- fix: improve support for concurrent mode ([PR #34113](https://github.com/microsoft/fluentui/pull/34113) by olfedias@microsoft.com)
|
24
|
+
- fix: don't pass `null` to `createKeyborg()` ([PR #34118](https://github.com/microsoft/fluentui/pull/34118) by olfedias@microsoft.com)
|
25
|
+
|
7
26
|
## [9.24.3](https://github.com/microsoft/fluentui/tree/@fluentui/react-tabster_v9.24.3)
|
8
27
|
|
9
|
-
Thu, 27 Mar 2025 21:
|
28
|
+
Thu, 27 Mar 2025 21:12:51 GMT
|
10
29
|
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-tabster_v9.24.2..@fluentui/react-tabster_v9.24.3)
|
11
30
|
|
12
31
|
### Patches
|
package/dist/index.d.ts
CHANGED
@@ -1425,9 +1425,10 @@ export declare const useFocusFinders: () => {
|
|
1425
1425
|
};
|
1426
1426
|
|
1427
1427
|
/**
|
1428
|
-
*
|
1429
1428
|
* @param name - The observed element to focus
|
1430
|
-
* @
|
1429
|
+
* @param options - Options for the focus observed
|
1430
|
+
*
|
1431
|
+
* @returns Function that will focus an element
|
1431
1432
|
*/
|
1432
1433
|
export declare function useFocusObserved(name: string, options?: UseFocusObservedOptions): () => Types.ObservedElementAsyncRequest<boolean>;
|
1433
1434
|
|
@@ -5,8 +5,7 @@ import { useTabster } from './useTabster';
|
|
5
5
|
/**
|
6
6
|
* Returns a function that activates a modal by element from the modal or modal container.
|
7
7
|
*/ export function useActivateModal() {
|
8
|
-
const
|
9
|
-
const modalizerAPI = tabster ? getModalizer(tabster) : undefined;
|
8
|
+
const modalizerRefAPI = useTabster(getModalizer);
|
10
9
|
const [setActivateModalTimeout] = useTimeout();
|
11
10
|
const activateModal = React.useCallback((elementFromModal)=>{
|
12
11
|
// We call the actual activation function on the next tick, because with the typical use case,
|
@@ -14,10 +13,11 @@ import { useTabster } from './useTabster';
|
|
14
13
|
// and on the current tick the element has just received the attributes, but Tabster has not
|
15
14
|
// instantiated the Modalizer yet.
|
16
15
|
setActivateModalTimeout(()=>{
|
17
|
-
|
16
|
+
var _modalizerRefAPI_current;
|
17
|
+
(_modalizerRefAPI_current = modalizerRefAPI.current) === null || _modalizerRefAPI_current === void 0 ? void 0 : _modalizerRefAPI_current.activate(elementFromModal);
|
18
18
|
}, 0);
|
19
19
|
}, [
|
20
|
-
|
20
|
+
modalizerRefAPI,
|
21
21
|
setActivateModalTimeout
|
22
22
|
]);
|
23
23
|
return activateModal;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/hooks/useActivateModal.ts"],"sourcesContent":["import * as React from 'react';\nimport { getModalizer } from 'tabster';\nimport { useTimeout } from '@fluentui/react-utilities';\nimport { useTabster } from './useTabster';\n\n/**\n * Returns a function that activates a modal by element from the modal or modal container.\n */\nexport function useActivateModal(): (elementFromModal: HTMLElement | undefined) => void {\n const
|
1
|
+
{"version":3,"sources":["../src/hooks/useActivateModal.ts"],"sourcesContent":["import * as React from 'react';\nimport { getModalizer } from 'tabster';\nimport { useTimeout } from '@fluentui/react-utilities';\nimport { useTabster } from './useTabster';\n\n/**\n * Returns a function that activates a modal by element from the modal or modal container.\n */\nexport function useActivateModal(): (elementFromModal: HTMLElement | undefined) => void {\n const modalizerRefAPI = useTabster(getModalizer);\n\n const [setActivateModalTimeout] = useTimeout();\n const activateModal = React.useCallback(\n (elementFromModal: HTMLElement | undefined) => {\n // We call the actual activation function on the next tick, because with the typical use case,\n // the hook will be called on the same tick when other Tabster attributes are being applied,\n // and on the current tick the element has just received the attributes, but Tabster has not\n // instantiated the Modalizer yet.\n setActivateModalTimeout(() => {\n modalizerRefAPI.current?.activate(elementFromModal);\n }, 0);\n },\n [modalizerRefAPI, setActivateModalTimeout],\n );\n\n return activateModal;\n}\n"],"names":["React","getModalizer","useTimeout","useTabster","useActivateModal","modalizerRefAPI","setActivateModalTimeout","activateModal","useCallback","elementFromModal","current","activate"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,YAAYA,WAAW,QAAQ;AAC/B,SAASC,YAAY,QAAQ,UAAU;AACvC,SAASC,UAAU,QAAQ,4BAA4B;AACvD,SAASC,UAAU,QAAQ,eAAe;AAE1C;;CAEC,GACD,OAAO,SAASC;IACd,MAAMC,kBAAkBF,WAAWF;IAEnC,MAAM,CAACK,wBAAwB,GAAGJ;IAClC,MAAMK,gBAAgBP,MAAMQ,WAAW,CACrC,CAACC;QACC,8FAA8F;QAC9F,4FAA4F;QAC5F,4FAA4F;QAC5F,kCAAkC;QAClCH,wBAAwB;gBACtBD;aAAAA,2BAAAA,gBAAgBK,OAAO,cAAvBL,+CAAAA,yBAAyBM,QAAQ,CAACF;QACpC,GAAG;IACL,GACA;QAACJ;QAAiBC;KAAwB;IAG5C,OAAOC;AACT"}
|
@@ -7,10 +7,7 @@ import { useTabster } from './useTabster';
|
|
7
7
|
*/ export const useArrowNavigationGroup = (options = {})=>{
|
8
8
|
const { circular, axis, memorizeCurrent = true, tabbable, ignoreDefaultKeydown, // eslint-disable-next-line @typescript-eslint/naming-convention
|
9
9
|
unstable_hasDefault } = options;
|
10
|
-
|
11
|
-
if (tabster) {
|
12
|
-
getMover(tabster);
|
13
|
-
}
|
10
|
+
useTabster(getMover);
|
14
11
|
return useTabsterAttributes({
|
15
12
|
mover: {
|
16
13
|
cyclic: !!circular,
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/hooks/useArrowNavigationGroup.ts"],"sourcesContent":["import { Types, getMover, MoverDirections } 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' | 'grid-linear' | '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 * @default true\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 = true,\n tabbable,\n ignoreDefaultKeydown,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n unstable_hasDefault,\n } = options;\n
|
1
|
+
{"version":3,"sources":["../src/hooks/useArrowNavigationGroup.ts"],"sourcesContent":["import { Types, getMover, MoverDirections } 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' | 'grid-linear' | '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 * @default true\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 = true,\n tabbable,\n ignoreDefaultKeydown,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n unstable_hasDefault,\n } = options;\n\n useTabster(getMover);\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 MoverDirections.Horizontal;\n case 'grid':\n return MoverDirections.Grid;\n case 'grid-linear':\n return MoverDirections.GridLinear;\n case 'both':\n return MoverDirections.Both;\n\n case 'vertical':\n default:\n return MoverDirections.Vertical;\n }\n}\n"],"names":["getMover","MoverDirections","useTabsterAttributes","useTabster","useArrowNavigationGroup","options","circular","axis","memorizeCurrent","tabbable","ignoreDefaultKeydown","unstable_hasDefault","mover","cyclic","direction","axisToMoverDirection","hasDefault","focusable","ignoreKeydown","Horizontal","Grid","GridLinear","Both","Vertical"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,SAAgBA,QAAQ,EAAEC,eAAe,QAAQ,UAAU;AAC3D,SAASC,oBAAoB,QAAQ,yBAAyB;AAC9D,SAASC,UAAU,QAAQ,eAAe;AAmC1C;;;CAGC,GACD,OAAO,MAAMC,0BAA0B,CAACC,UAA0C,CAAC,CAAC;IAClF,MAAM,EACJC,QAAQ,EACRC,IAAI,EACJC,kBAAkB,IAAI,EACtBC,QAAQ,EACRC,oBAAoB,EACpB,gEAAgE;IAChEC,mBAAmB,EACpB,GAAGN;IAEJF,WAAWH;IAEX,OAAOE,qBAAqB;QAC1BU,OAAO;YACLC,QAAQ,CAAC,CAACP;YACVQ,WAAWC,qBAAqBR,iBAAAA,kBAAAA,OAAQ;YACxCC;YACAC;YACAO,YAAYL;QACd;QACA,GAAID,wBAAwB;YAC1BO,WAAW;gBACTC,eAAeR;YACjB;QACF,CAAC;IACH;AACF,EAAE;AAEF,SAASK,qBAAqBR,IAA4C;IACxE,OAAQA;QACN,KAAK;YACH,OAAON,gBAAgBkB,UAAU;QACnC,KAAK;YACH,OAAOlB,gBAAgBmB,IAAI;QAC7B,KAAK;YACH,OAAOnB,gBAAgBoB,UAAU;QACnC,KAAK;YACH,OAAOpB,gBAAgBqB,IAAI;QAE7B,KAAK;QACL;YACE,OAAOrB,gBAAgBsB,QAAQ;IACnC;AACF"}
|
@@ -4,49 +4,58 @@ 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
6
|
*/ export const useFocusFinders = ()=>{
|
7
|
-
const
|
7
|
+
const tabsterRef = useTabster();
|
8
8
|
const { targetDocument } = useFluent();
|
9
9
|
// Narrow props for now and let need dictate additional props in the future
|
10
|
-
const findAllFocusable = React.useCallback((container, acceptCondition)=>
|
10
|
+
const findAllFocusable = React.useCallback((container, acceptCondition)=>{
|
11
|
+
var _tabsterRef_current;
|
12
|
+
return ((_tabsterRef_current = tabsterRef.current) === null || _tabsterRef_current === void 0 ? void 0 : _tabsterRef_current.focusable.findAll({
|
11
13
|
container,
|
12
14
|
acceptCondition
|
13
|
-
})) || []
|
14
|
-
|
15
|
+
})) || [];
|
16
|
+
}, [
|
17
|
+
tabsterRef
|
15
18
|
]);
|
16
|
-
const findFirstFocusable = React.useCallback((container)=>
|
19
|
+
const findFirstFocusable = React.useCallback((container)=>{
|
20
|
+
var _tabsterRef_current;
|
21
|
+
return (_tabsterRef_current = tabsterRef.current) === null || _tabsterRef_current === void 0 ? void 0 : _tabsterRef_current.focusable.findFirst({
|
17
22
|
container
|
18
|
-
})
|
19
|
-
|
23
|
+
});
|
24
|
+
}, [
|
25
|
+
tabsterRef
|
20
26
|
]);
|
21
|
-
const findLastFocusable = React.useCallback((container)=>
|
27
|
+
const findLastFocusable = React.useCallback((container)=>{
|
28
|
+
var _tabsterRef_current;
|
29
|
+
return (_tabsterRef_current = tabsterRef.current) === null || _tabsterRef_current === void 0 ? void 0 : _tabsterRef_current.focusable.findLast({
|
22
30
|
container
|
23
|
-
})
|
24
|
-
|
31
|
+
});
|
32
|
+
}, [
|
33
|
+
tabsterRef
|
25
34
|
]);
|
26
35
|
const findNextFocusable = React.useCallback((currentElement, options = {})=>{
|
27
|
-
if (!
|
36
|
+
if (!tabsterRef.current || !targetDocument) {
|
28
37
|
return null;
|
29
38
|
}
|
30
39
|
const { container = targetDocument.body } = options;
|
31
|
-
return
|
40
|
+
return tabsterRef.current.focusable.findNext({
|
32
41
|
currentElement,
|
33
42
|
container
|
34
43
|
});
|
35
44
|
}, [
|
36
|
-
|
45
|
+
tabsterRef,
|
37
46
|
targetDocument
|
38
47
|
]);
|
39
48
|
const findPrevFocusable = React.useCallback((currentElement, options = {})=>{
|
40
|
-
if (!
|
49
|
+
if (!tabsterRef.current || !targetDocument) {
|
41
50
|
return null;
|
42
51
|
}
|
43
52
|
const { container = targetDocument.body } = options;
|
44
|
-
return
|
53
|
+
return tabsterRef.current.focusable.findPrev({
|
45
54
|
currentElement,
|
46
55
|
container
|
47
56
|
});
|
48
57
|
}, [
|
49
|
-
|
58
|
+
tabsterRef,
|
50
59
|
targetDocument
|
51
60
|
]);
|
52
61
|
return {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/hooks/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
|
1
|
+
{"version":3,"sources":["../src/hooks/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 tabsterRef = 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 tabsterRef.current?.focusable.findAll({ container, acceptCondition }) || [],\n [tabsterRef],\n );\n\n const findFirstFocusable = React.useCallback(\n (container: HTMLElement) => tabsterRef.current?.focusable.findFirst({ container }),\n [tabsterRef],\n );\n\n const findLastFocusable = React.useCallback(\n (container: HTMLElement) => tabsterRef.current?.focusable.findLast({ container }),\n [tabsterRef],\n );\n\n const findNextFocusable = React.useCallback(\n (currentElement: HTMLElement, options: Pick<Partial<TabsterTypes.FindNextProps>, 'container'> = {}) => {\n if (!tabsterRef.current || !targetDocument) {\n return null;\n }\n\n const { container = targetDocument.body } = options;\n\n return tabsterRef.current.focusable.findNext({ currentElement, container });\n },\n [tabsterRef, targetDocument],\n );\n\n const findPrevFocusable = React.useCallback(\n (currentElement: HTMLElement, options: Pick<Partial<TabsterTypes.FindNextProps>, 'container'> = {}) => {\n if (!tabsterRef.current || !targetDocument) {\n return null;\n }\n\n const { container = targetDocument.body } = options;\n\n return tabsterRef.current.focusable.findPrev({ currentElement, container });\n },\n [tabsterRef, 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","tabsterRef","targetDocument","findAllFocusable","useCallback","container","acceptCondition","current","focusable","findAll","findFirstFocusable","findFirst","findLastFocusable","findLast","findNextFocusable","currentElement","options","body","findNext","findPrevFocusable","findPrev"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,YAAYA,WAAW,QAAQ;AAE/B,SAASC,sBAAsBC,SAAS,QAAQ,kCAAkC;AAClF,SAASC,UAAU,QAAQ,eAAe;AAE1C;;CAEC,GACD,OAAO,MAAMC,kBAAkB;IAC7B,MAAMC,aAAaF;IACnB,MAAM,EAAEG,cAAc,EAAE,GAAGJ;IAE3B,2EAA2E;IAC3E,MAAMK,mBAAmBP,MAAMQ,WAAW,CACxC,CAACC,WAAwBC;YACvBL;eAAAA,EAAAA,sBAAAA,WAAWM,OAAO,cAAlBN,0CAAAA,oBAAoBO,SAAS,CAACC,OAAO,CAAC;YAAEJ;YAAWC;QAAgB,OAAM,EAAE;OAC7E;QAACL;KAAW;IAGd,MAAMS,qBAAqBd,MAAMQ,WAAW,CAC1C,CAACC;YAA2BJ;gBAAAA,sBAAAA,WAAWM,OAAO,cAAlBN,0CAAAA,oBAAoBO,SAAS,CAACG,SAAS,CAAC;YAAEN;QAAU;OAChF;QAACJ;KAAW;IAGd,MAAMW,oBAAoBhB,MAAMQ,WAAW,CACzC,CAACC;YAA2BJ;gBAAAA,sBAAAA,WAAWM,OAAO,cAAlBN,0CAAAA,oBAAoBO,SAAS,CAACK,QAAQ,CAAC;YAAER;QAAU;OAC/E;QAACJ;KAAW;IAGd,MAAMa,oBAAoBlB,MAAMQ,WAAW,CACzC,CAACW,gBAA6BC,UAAkE,CAAC,CAAC;QAChG,IAAI,CAACf,WAAWM,OAAO,IAAI,CAACL,gBAAgB;YAC1C,OAAO;QACT;QAEA,MAAM,EAAEG,YAAYH,eAAee,IAAI,EAAE,GAAGD;QAE5C,OAAOf,WAAWM,OAAO,CAACC,SAAS,CAACU,QAAQ,CAAC;YAAEH;YAAgBV;QAAU;IAC3E,GACA;QAACJ;QAAYC;KAAe;IAG9B,MAAMiB,oBAAoBvB,MAAMQ,WAAW,CACzC,CAACW,gBAA6BC,UAAkE,CAAC,CAAC;QAChG,IAAI,CAACf,WAAWM,OAAO,IAAI,CAACL,gBAAgB;YAC1C,OAAO;QACT;QAEA,MAAM,EAAEG,YAAYH,eAAee,IAAI,EAAE,GAAGD;QAE5C,OAAOf,WAAWM,OAAO,CAACC,SAAS,CAACY,QAAQ,CAAC;YAAEL;YAAgBV;QAAU;IAC3E,GACA;QAACJ;QAAYC;KAAe;IAG9B,OAAO;QACLC;QACAO;QACAE;QACAE;QACAK;IACF;AACF,EAAE"}
|
@@ -2,23 +2,24 @@ import * as React from 'react';
|
|
2
2
|
import { getObservedElement } from 'tabster';
|
3
3
|
import { useTabster } from './useTabster';
|
4
4
|
/**
|
5
|
-
*
|
6
5
|
* @param name - The observed element to focus
|
7
|
-
* @
|
6
|
+
* @param options - Options for the focus observed
|
7
|
+
*
|
8
|
+
* @returns Function that will focus an element
|
8
9
|
*/ export function useFocusObserved(name, options = {}) {
|
9
10
|
const { timeout = 1000 } = options;
|
10
|
-
const
|
11
|
-
const observedAPI = tabster ? getObservedElement(tabster) : null;
|
11
|
+
const observedAPIRef = useTabster(getObservedElement);
|
12
12
|
return React.useCallback(()=>{
|
13
|
-
|
14
|
-
|
13
|
+
const observerAPI = observedAPIRef.current;
|
14
|
+
if (observerAPI) {
|
15
|
+
return observerAPI.requestFocus(name, timeout);
|
15
16
|
}
|
16
17
|
return {
|
17
18
|
result: Promise.resolve(false),
|
18
19
|
cancel: ()=>null
|
19
20
|
};
|
20
21
|
}, [
|
21
|
-
|
22
|
+
observedAPIRef,
|
22
23
|
name,
|
23
24
|
timeout
|
24
25
|
]);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/hooks/useFocusObserved.ts"],"sourcesContent":["import * as React from 'react';\nimport { getObservedElement, Types as TabsterTypes } from 'tabster';\nimport { useTabster } from './useTabster';\n\ninterface UseFocusObservedOptions {\n /**\n * After timeout the focus attempt fails\n */\n timeout?: number;\n}\n\n/**\n
|
1
|
+
{"version":3,"sources":["../src/hooks/useFocusObserved.ts"],"sourcesContent":["import * as React from 'react';\nimport { getObservedElement, Types as TabsterTypes } from 'tabster';\nimport { useTabster } from './useTabster';\n\ninterface UseFocusObservedOptions {\n /**\n * After timeout the focus attempt fails\n */\n timeout?: number;\n}\n\n/**\n * @param name - The observed element to focus\n * @param options - Options for the focus observed\n *\n * @returns Function that will focus an element\n */\nexport function useFocusObserved(\n name: string,\n options: UseFocusObservedOptions = {},\n): () => TabsterTypes.ObservedElementAsyncRequest<boolean> {\n const { timeout = 1000 } = options;\n const observedAPIRef = useTabster(getObservedElement);\n\n return React.useCallback(() => {\n const observerAPI = observedAPIRef.current;\n\n if (observerAPI) {\n return observerAPI.requestFocus(name, timeout);\n }\n\n return {\n result: Promise.resolve(false),\n cancel: () => null,\n };\n }, [observedAPIRef, name, timeout]);\n}\n"],"names":["React","getObservedElement","useTabster","useFocusObserved","name","options","timeout","observedAPIRef","useCallback","observerAPI","current","requestFocus","result","Promise","resolve","cancel"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,YAAYA,WAAW,QAAQ;AAC/B,SAASC,kBAAkB,QAA+B,UAAU;AACpE,SAASC,UAAU,QAAQ,eAAe;AAS1C;;;;;CAKC,GACD,OAAO,SAASC,iBACdC,IAAY,EACZC,UAAmC,CAAC,CAAC;IAErC,MAAM,EAAEC,UAAU,IAAI,EAAE,GAAGD;IAC3B,MAAME,iBAAiBL,WAAWD;IAElC,OAAOD,MAAMQ,WAAW,CAAC;QACvB,MAAMC,cAAcF,eAAeG,OAAO;QAE1C,IAAID,aAAa;YACf,OAAOA,YAAYE,YAAY,CAACP,MAAME;QACxC;QAEA,OAAO;YACLM,QAAQC,QAAQC,OAAO,CAAC;YACxBC,QAAQ,IAAM;QAChB;IACF,GAAG;QAACR;QAAgBH;QAAME;KAAQ;AACpC"}
|
@@ -5,10 +5,7 @@ import { useTabster } from './useTabster';
|
|
5
5
|
* A hook that returns the necessary tabster attributes to support groupping.
|
6
6
|
* @param options - Options to configure keyboard navigation
|
7
7
|
*/ export const useFocusableGroup = (options)=>{
|
8
|
-
|
9
|
-
if (tabster) {
|
10
|
-
getGroupper(tabster);
|
11
|
-
}
|
8
|
+
useTabster(getGroupper);
|
12
9
|
return useTabsterAttributes({
|
13
10
|
groupper: {
|
14
11
|
tabbability: getTabbability(options === null || options === void 0 ? void 0 : options.tabBehavior)
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/hooks/useFocusableGroup.ts"],"sourcesContent":["import { Types, getGroupper, GroupperTabbabilities } 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 * Tabster can ignore default handling of keydown events\n */\n ignoreDefaultKeydown?: Types.FocusableProps['ignoreKeydown'];\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
|
1
|
+
{"version":3,"sources":["../src/hooks/useFocusableGroup.ts"],"sourcesContent":["import { Types, getGroupper, GroupperTabbabilities } 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 * Tabster can ignore default handling of keydown events\n */\n ignoreDefaultKeydown?: Types.FocusableProps['ignoreKeydown'];\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 useTabster(getGroupper);\n\n return useTabsterAttributes({\n groupper: {\n tabbability: getTabbability(options?.tabBehavior),\n },\n focusable: {\n ignoreKeydown: options?.ignoreDefaultKeydown,\n },\n });\n};\n\nconst getTabbability = (\n tabBehavior?: UseFocusableGroupOptions['tabBehavior'],\n): Types.GroupperTabbability | undefined => {\n switch (tabBehavior) {\n case 'unlimited':\n return GroupperTabbabilities.Unlimited;\n case 'limited':\n return GroupperTabbabilities.Limited;\n case 'limited-trap-focus':\n return GroupperTabbabilities.LimitedTrapFocus;\n default:\n return undefined;\n }\n};\n"],"names":["getGroupper","GroupperTabbabilities","useTabsterAttributes","useTabster","useFocusableGroup","options","groupper","tabbability","getTabbability","tabBehavior","focusable","ignoreKeydown","ignoreDefaultKeydown","Unlimited","Limited","LimitedTrapFocus","undefined"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,SAAgBA,WAAW,EAAEC,qBAAqB,QAAQ,UAAU;AACpE,SAASC,oBAAoB,QAAQ,yBAAyB;AAC9D,SAASC,UAAU,QAAQ,eAAe;AAc1C;;;CAGC,GACD,OAAO,MAAMC,oBAAoB,CAACC;IAChCF,WAAWH;IAEX,OAAOE,qBAAqB;QAC1BI,UAAU;YACRC,aAAaC,eAAeH,oBAAAA,8BAAAA,QAASI,WAAW;QAClD;QACAC,WAAW;YACTC,aAAa,EAAEN,oBAAAA,8BAAAA,QAASO,oBAAoB;QAC9C;IACF;AACF,EAAE;AAEF,MAAMJ,iBAAiB,CACrBC;IAEA,OAAQA;QACN,KAAK;YACH,OAAOR,sBAAsBY,SAAS;QACxC,KAAK;YACH,OAAOZ,sBAAsBa,OAAO;QACtC,KAAK;YACH,OAAOb,sBAAsBc,gBAAgB;QAC/C;YACE,OAAOC;IACX;AACF"}
|
@@ -1,17 +1,25 @@
|
|
1
|
-
import {
|
1
|
+
import { disposeTabster } from 'tabster';
|
2
2
|
import * as React from 'react';
|
3
|
+
import { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';
|
4
|
+
import { useEventCallback } from '@fluentui/react-utilities';
|
5
|
+
import { createTabsterWithConfig } from './useTabster';
|
3
6
|
/**
|
4
7
|
* Subscribes to the tabster focused element. Calls the callback when the focused element changes.
|
5
8
|
* @param callback - Callback to subscribe to the focused element.
|
6
9
|
*/ export function useFocusedElementChange(callback) {
|
7
|
-
const
|
10
|
+
const { targetDocument } = useFluent();
|
11
|
+
const listener = useEventCallback(callback);
|
8
12
|
React.useEffect(()=>{
|
13
|
+
const tabster = createTabsterWithConfig(targetDocument);
|
9
14
|
if (tabster) {
|
10
|
-
tabster.focusedElement.subscribe(
|
11
|
-
return ()=>
|
15
|
+
tabster.focusedElement.subscribe(listener);
|
16
|
+
return ()=>{
|
17
|
+
tabster.focusedElement.unsubscribe(listener);
|
18
|
+
disposeTabster(tabster);
|
19
|
+
};
|
12
20
|
}
|
13
21
|
}, [
|
14
|
-
|
15
|
-
|
22
|
+
listener,
|
23
|
+
targetDocument
|
16
24
|
]);
|
17
25
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/hooks/useFocusedElementChange.ts"],"sourcesContent":["import type
|
1
|
+
{"version":3,"sources":["../src/hooks/useFocusedElementChange.ts"],"sourcesContent":["import { type Types as TabsterTypes, disposeTabster } from 'tabster';\nimport * as React from 'react';\nimport { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\nimport { useEventCallback } from '@fluentui/react-utilities';\n\nimport { createTabsterWithConfig } from './useTabster';\n\n/**\n * Subscribes to the tabster focused element. Calls the callback when the focused element changes.\n * @param callback - Callback to subscribe to the focused element.\n */\nexport function useFocusedElementChange(\n callback: TabsterTypes.SubscribableCallback<HTMLElement | undefined, TabsterTypes.FocusedElementDetail>,\n) {\n const { targetDocument } = useFluent();\n const listener = useEventCallback(callback);\n\n React.useEffect(() => {\n const tabster = createTabsterWithConfig(targetDocument);\n\n if (tabster) {\n tabster.focusedElement.subscribe(listener);\n\n return () => {\n tabster.focusedElement.unsubscribe(listener);\n disposeTabster(tabster);\n };\n }\n }, [listener, targetDocument]);\n}\n"],"names":["disposeTabster","React","useFluent_unstable","useFluent","useEventCallback","createTabsterWithConfig","useFocusedElementChange","callback","targetDocument","listener","useEffect","tabster","focusedElement","subscribe","unsubscribe"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,SAAqCA,cAAc,QAAQ,UAAU;AACrE,YAAYC,WAAW,QAAQ;AAC/B,SAASC,sBAAsBC,SAAS,QAAQ,kCAAkC;AAClF,SAASC,gBAAgB,QAAQ,4BAA4B;AAE7D,SAASC,uBAAuB,QAAQ,eAAe;AAEvD;;;CAGC,GACD,OAAO,SAASC,wBACdC,QAAuG;IAEvG,MAAM,EAAEC,cAAc,EAAE,GAAGL;IAC3B,MAAMM,WAAWL,iBAAiBG;IAElCN,MAAMS,SAAS,CAAC;QACd,MAAMC,UAAUN,wBAAwBG;QAExC,IAAIG,SAAS;YACXA,QAAQC,cAAc,CAACC,SAAS,CAACJ;YAEjC,OAAO;gBACLE,QAAQC,cAAc,CAACE,WAAW,CAACL;gBACnCT,eAAeW;YACjB;QACF;IACF,GAAG;QAACF;QAAUD;KAAe;AAC/B"}
|
@@ -9,8 +9,9 @@ import { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts
|
|
9
9
|
const { targetDocument } = useFluent();
|
10
10
|
const keyborgRef = React.useRef(null);
|
11
11
|
React.useEffect(()=>{
|
12
|
-
|
13
|
-
|
12
|
+
const targetWindow = targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.defaultView;
|
13
|
+
if (targetWindow) {
|
14
|
+
const keyborg = createKeyborg(targetWindow);
|
14
15
|
keyborgRef.current = keyborg;
|
15
16
|
return ()=>{
|
16
17
|
disposeKeyborg(keyborg);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/hooks/useKeyborgRef.ts"],"sourcesContent":["import * as React from 'react';\nimport { createKeyborg, disposeKeyborg, type Keyborg } from 'keyborg';\nimport { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\n\n/**\n * @internal\n * Instantiates [keyborg](https://github.com/microsoft/keyborg)\n * @returns - keyborg instance\n */\nexport function useKeyborgRef() {\n const { targetDocument } = useFluent();\n const keyborgRef = React.useRef<Keyborg | null>(null);\n\n React.useEffect(() => {\n if (
|
1
|
+
{"version":3,"sources":["../src/hooks/useKeyborgRef.ts"],"sourcesContent":["import * as React from 'react';\nimport { createKeyborg, disposeKeyborg, type Keyborg } from 'keyborg';\nimport { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\n\n/**\n * @internal\n * Instantiates [keyborg](https://github.com/microsoft/keyborg)\n * @returns - keyborg instance\n */\nexport function useKeyborgRef() {\n const { targetDocument } = useFluent();\n const keyborgRef = React.useRef<Keyborg | null>(null);\n\n React.useEffect(() => {\n const targetWindow = targetDocument?.defaultView;\n\n if (targetWindow) {\n const keyborg = createKeyborg(targetWindow);\n keyborgRef.current = keyborg;\n\n return () => {\n disposeKeyborg(keyborg);\n keyborgRef.current = null;\n };\n }\n }, [targetDocument]);\n\n return keyborgRef;\n}\n"],"names":["React","createKeyborg","disposeKeyborg","useFluent_unstable","useFluent","useKeyborgRef","targetDocument","keyborgRef","useRef","useEffect","targetWindow","defaultView","keyborg","current"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,YAAYA,WAAW,QAAQ;AAC/B,SAASC,aAAa,EAAEC,cAAc,QAAsB,UAAU;AACtE,SAASC,sBAAsBC,SAAS,QAAQ,kCAAkC;AAElF;;;;CAIC,GACD,OAAO,SAASC;IACd,MAAM,EAAEC,cAAc,EAAE,GAAGF;IAC3B,MAAMG,aAAaP,MAAMQ,MAAM,CAAiB;IAEhDR,MAAMS,SAAS,CAAC;QACd,MAAMC,eAAeJ,2BAAAA,qCAAAA,eAAgBK,WAAW;QAEhD,IAAID,cAAc;YAChB,MAAME,UAAUX,cAAcS;YAC9BH,WAAWM,OAAO,GAAGD;YAErB,OAAO;gBACLV,eAAeU;gBACfL,WAAWM,OAAO,GAAG;YACvB;QACF;IACF,GAAG;QAACP;KAAe;IAEnB,OAAOC;AACT"}
|
@@ -16,6 +16,10 @@ const DangerousNeverHiddenPropObject = {
|
|
16
16
|
const tabsterAccessibleCheck = (element)=>{
|
17
17
|
return element.hasAttribute(DangerousNeverHiddenAttribute);
|
18
18
|
};
|
19
|
+
function initTabsterModules(tabster) {
|
20
|
+
getModalizer(tabster, undefined, tabsterAccessibleCheck);
|
21
|
+
getRestorer(tabster);
|
22
|
+
}
|
19
23
|
/**
|
20
24
|
* Applies modal dialog behaviour through DOM attributes
|
21
25
|
* Modal element will focus trap and hide other content on the page
|
@@ -24,12 +28,8 @@ const tabsterAccessibleCheck = (element)=>{
|
|
24
28
|
* @returns DOM attributes to apply to the modal element and its trigger
|
25
29
|
*/ export const useModalAttributes = (options = {})=>{
|
26
30
|
const { trapFocus, alwaysFocusable, legacyTrapFocus } = options;
|
27
|
-
const tabster = useTabster();
|
28
31
|
// Initializes the modalizer and restorer APIs
|
29
|
-
|
30
|
-
getModalizer(tabster, undefined, tabsterAccessibleCheck);
|
31
|
-
getRestorer(tabster);
|
32
|
-
}
|
32
|
+
useTabster(initTabsterModules);
|
33
33
|
const id = useId('modal-', options.id);
|
34
34
|
const modalAttributes = useTabsterAttributes({
|
35
35
|
restorer: {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/hooks/useModalAttributes.ts"],"sourcesContent":["import { useId } from '@fluentui/react-utilities';\nimport { useTabsterAttributes } from './useTabsterAttributes';\nimport { getModalizer, getRestorer, Types as TabsterTypes, RestorerTypes } from 'tabster';\nimport { useTabster } from './useTabster';\n\nconst DangerousNeverHiddenAttribute = 'data-tabster-never-hide';\nconst DangerousNeverHiddenPropObject = { [DangerousNeverHiddenAttribute]: '' };\n\nexport interface UseModalAttributesOptions {\n /**\n * Traps focus inside the elements the attributes are applied.\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 traditional force-focus behavior to match previous versions of Fluent.\n * Without this, users can tab out of the focus trap and into the browser chrome.\n * This matches the behavior of the native <dialog> element and inert.\n * We recommend setting this to true based on user feedback and consistency.\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 * !!DANGEROUS!! Designates an element that will not be hidden even when outside an open modal.\n * Only works for top-level elements; should be used with extreme care.\n * @returns Attribute to apply to the target element that should never receive aria-hidden\n */\nexport function useDangerousNeverHidden_unstable(): { [key: string]: string } {\n return DangerousNeverHiddenPropObject;\n}\n\nconst tabsterAccessibleCheck: TabsterTypes.ModalizerElementAccessibleCheck = element => {\n return element.hasAttribute(DangerousNeverHiddenAttribute);\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
|
1
|
+
{"version":3,"sources":["../src/hooks/useModalAttributes.ts"],"sourcesContent":["import { useId } from '@fluentui/react-utilities';\nimport { useTabsterAttributes } from './useTabsterAttributes';\nimport { getModalizer, getRestorer, Types as TabsterTypes, RestorerTypes } from 'tabster';\nimport { useTabster } from './useTabster';\n\nconst DangerousNeverHiddenAttribute = 'data-tabster-never-hide';\nconst DangerousNeverHiddenPropObject = { [DangerousNeverHiddenAttribute]: '' };\n\nexport interface UseModalAttributesOptions {\n /**\n * Traps focus inside the elements the attributes are applied.\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 traditional force-focus behavior to match previous versions of Fluent.\n * Without this, users can tab out of the focus trap and into the browser chrome.\n * This matches the behavior of the native <dialog> element and inert.\n * We recommend setting this to true based on user feedback and consistency.\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 * !!DANGEROUS!! Designates an element that will not be hidden even when outside an open modal.\n * Only works for top-level elements; should be used with extreme care.\n * @returns Attribute to apply to the target element that should never receive aria-hidden\n */\nexport function useDangerousNeverHidden_unstable(): { [key: string]: string } {\n return DangerousNeverHiddenPropObject;\n}\n\nconst tabsterAccessibleCheck: TabsterTypes.ModalizerElementAccessibleCheck = element => {\n return element.hasAttribute(DangerousNeverHiddenAttribute);\n};\n\nfunction initTabsterModules(tabster: TabsterTypes.TabsterCore) {\n getModalizer(tabster, undefined, tabsterAccessibleCheck);\n getRestorer(tabster);\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\n // Initializes the modalizer and restorer APIs\n useTabster(initTabsterModules);\n\n const id = useId('modal-', options.id);\n const modalAttributes = useTabsterAttributes({\n restorer: { type: RestorerTypes.Source },\n ...(trapFocus && {\n modalizer: {\n id,\n isOthersAccessible: !trapFocus,\n isAlwaysAccessible: alwaysFocusable,\n isTrapped: legacyTrapFocus && trapFocus,\n },\n }),\n });\n\n const triggerAttributes = useTabsterAttributes({\n restorer: { type: RestorerTypes.Target },\n });\n\n return { modalAttributes, triggerAttributes };\n};\n"],"names":["useId","useTabsterAttributes","getModalizer","getRestorer","RestorerTypes","useTabster","DangerousNeverHiddenAttribute","DangerousNeverHiddenPropObject","useDangerousNeverHidden_unstable","tabsterAccessibleCheck","element","hasAttribute","initTabsterModules","tabster","undefined","useModalAttributes","options","trapFocus","alwaysFocusable","legacyTrapFocus","id","modalAttributes","restorer","type","Source","modalizer","isOthersAccessible","isAlwaysAccessible","isTrapped","triggerAttributes","Target"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,SAASA,KAAK,QAAQ,4BAA4B;AAClD,SAASC,oBAAoB,QAAQ,yBAAyB;AAC9D,SAASC,YAAY,EAAEC,WAAW,EAAyBC,aAAa,QAAQ,UAAU;AAC1F,SAASC,UAAU,QAAQ,eAAe;AAE1C,MAAMC,gCAAgC;AACtC,MAAMC,iCAAiC;IAAE,CAACD,8BAA8B,EAAE;AAAG;AA6B7E;;;;CAIC,GACD,OAAO,SAASE;IACd,OAAOD;AACT;AAEA,MAAME,yBAAuEC,CAAAA;IAC3E,OAAOA,QAAQC,YAAY,CAACL;AAC9B;AAEA,SAASM,mBAAmBC,OAAiC;IAC3DX,aAAaW,SAASC,WAAWL;IACjCN,YAAYU;AACd;AAEA;;;;;;CAMC,GACD,OAAO,MAAME,qBAAqB,CAChCC,UAAqC,CAAC,CAAC;IAEvC,MAAM,EAAEC,SAAS,EAAEC,eAAe,EAAEC,eAAe,EAAE,GAAGH;IAExD,8CAA8C;IAC9CX,WAAWO;IAEX,MAAMQ,KAAKpB,MAAM,UAAUgB,QAAQI,EAAE;IACrC,MAAMC,kBAAkBpB,qBAAqB;QAC3CqB,UAAU;YAAEC,MAAMnB,cAAcoB,MAAM;QAAC;QACvC,GAAIP,aAAa;YACfQ,WAAW;gBACTL;gBACAM,oBAAoB,CAACT;gBACrBU,oBAAoBT;gBACpBU,WAAWT,mBAAmBF;YAChC;QACF,CAAC;IACH;IAEA,MAAMY,oBAAoB5B,qBAAqB;QAC7CqB,UAAU;YAAEC,MAAMnB,cAAc0B,MAAM;QAAC;IACzC;IAEA,OAAO;QAAET;QAAiBQ;IAAkB;AAC9C,EAAE"}
|
@@ -1,11 +1,8 @@
|
|
1
|
-
import { useTabster } from './useTabster';
|
2
1
|
import { getObservedElement } from 'tabster';
|
2
|
+
import { useTabster } from './useTabster';
|
3
3
|
import { useTabsterAttributes } from './useTabsterAttributes';
|
4
4
|
export function useObservedElement(name) {
|
5
|
-
|
6
|
-
if (tabster) {
|
7
|
-
getObservedElement(tabster);
|
8
|
-
}
|
5
|
+
useTabster(getObservedElement);
|
9
6
|
return useTabsterAttributes({
|
10
7
|
observed: {
|
11
8
|
names: Array.isArray(name) ? name : [
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/hooks/useObservedElement.ts"],"sourcesContent":["import {
|
1
|
+
{"version":3,"sources":["../src/hooks/useObservedElement.ts"],"sourcesContent":["import { getObservedElement, Types as TabsterTypes } from 'tabster';\n\nimport { useTabster } from './useTabster';\nimport { useTabsterAttributes } from './useTabsterAttributes';\n\nexport function useObservedElement(name: string | string[]): TabsterTypes.TabsterDOMAttribute {\n useTabster(getObservedElement);\n\n return useTabsterAttributes({ observed: { names: Array.isArray(name) ? name : [name] } });\n}\n"],"names":["getObservedElement","useTabster","useTabsterAttributes","useObservedElement","name","observed","names","Array","isArray"],"rangeMappings":";;;;;;;;;;;;","mappings":"AAAA,SAASA,kBAAkB,QAA+B,UAAU;AAEpE,SAASC,UAAU,QAAQ,eAAe;AAC1C,SAASC,oBAAoB,QAAQ,yBAAyB;AAE9D,OAAO,SAASC,mBAAmBC,IAAuB;IACxDH,WAAWD;IAEX,OAAOE,qBAAqB;QAAEG,UAAU;YAAEC,OAAOC,MAAMC,OAAO,CAACJ,QAAQA,OAAO;gBAACA;aAAK;QAAC;IAAE;AACzF"}
|
@@ -4,11 +4,8 @@ import { useTabster } from './useTabster';
|
|
4
4
|
* Focus will be restored to the most recent target element when it is lost from a source
|
5
5
|
* @returns Attribute to apply to the target element where focus is restored
|
6
6
|
*/ export function useRestoreFocusTarget() {
|
7
|
-
const tabster = useTabster();
|
8
7
|
// Initializes the restorer API
|
9
|
-
|
10
|
-
getRestorer(tabster);
|
11
|
-
}
|
8
|
+
useTabster(getRestorer);
|
12
9
|
return getTabsterAttribute({
|
13
10
|
restorer: {
|
14
11
|
type: RestorerTypes.Target
|
@@ -19,11 +16,8 @@ import { useTabster } from './useTabster';
|
|
19
16
|
* Focus will be restored to the most recent target element when it is lost from a source
|
20
17
|
* @returns Attribute to apply to the element that might lose focus
|
21
18
|
*/ export function useRestoreFocusSource() {
|
22
|
-
const tabster = useTabster();
|
23
19
|
// Initializes the restorer API
|
24
|
-
|
25
|
-
getRestorer(tabster);
|
26
|
-
}
|
20
|
+
useTabster(getRestorer);
|
27
21
|
return getTabsterAttribute({
|
28
22
|
restorer: {
|
29
23
|
type: RestorerTypes.Source
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/hooks/useRestoreFocus.ts"],"sourcesContent":["import { getRestorer, getTabsterAttribute, Types as TabsterTypes, RestorerTypes } from 'tabster';\nimport { useTabster } from './useTabster';\n\n/**\n * Focus will be restored to the most recent target element when it is lost from a source\n * @returns Attribute to apply to the target element where focus is restored\n */\nexport function useRestoreFocusTarget(): TabsterTypes.TabsterDOMAttribute {\n
|
1
|
+
{"version":3,"sources":["../src/hooks/useRestoreFocus.ts"],"sourcesContent":["import { getRestorer, getTabsterAttribute, Types as TabsterTypes, RestorerTypes } from 'tabster';\nimport { useTabster } from './useTabster';\n\n/**\n * Focus will be restored to the most recent target element when it is lost from a source\n * @returns Attribute to apply to the target element where focus is restored\n */\nexport function useRestoreFocusTarget(): TabsterTypes.TabsterDOMAttribute {\n // Initializes the restorer API\n useTabster(getRestorer);\n\n return getTabsterAttribute({ restorer: { type: RestorerTypes.Target } });\n}\n\n/**\n * Focus will be restored to the most recent target element when it is lost from a source\n * @returns Attribute to apply to the element that might lose focus\n */\nexport function useRestoreFocusSource(): TabsterTypes.TabsterDOMAttribute {\n // Initializes the restorer API\n useTabster(getRestorer);\n\n return getTabsterAttribute({ restorer: { type: RestorerTypes.Source } });\n}\n"],"names":["getRestorer","getTabsterAttribute","RestorerTypes","useTabster","useRestoreFocusTarget","restorer","type","Target","useRestoreFocusSource","Source"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,SAASA,WAAW,EAAEC,mBAAmB,EAAyBC,aAAa,QAAQ,UAAU;AACjG,SAASC,UAAU,QAAQ,eAAe;AAE1C;;;CAGC,GACD,OAAO,SAASC;IACd,+BAA+B;IAC/BD,WAAWH;IAEX,OAAOC,oBAAoB;QAAEI,UAAU;YAAEC,MAAMJ,cAAcK,MAAM;QAAC;IAAE;AACxE;AAEA;;;CAGC,GACD,OAAO,SAASC;IACd,+BAA+B;IAC/BL,WAAWH;IAEX,OAAOC,oBAAoB;QAAEI,UAAU;YAAEC,MAAMJ,cAAcO,MAAM;QAAC;IAAE;AACxE"}
|
package/lib/hooks/useTabster.js
CHANGED
@@ -1,21 +1,19 @@
|
|
1
1
|
import * as React from 'react';
|
2
|
-
import { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';
|
3
2
|
import { createTabster, disposeTabster } from 'tabster';
|
4
|
-
import {
|
3
|
+
import { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';
|
4
|
+
import { getParent, usePrevious } from '@fluentui/react-utilities';
|
5
|
+
const DEFAULT_FACTORY = (tabster)=>{
|
6
|
+
return tabster;
|
7
|
+
};
|
5
8
|
/**
|
6
|
-
*
|
7
|
-
* Since Tabster is single instance only, feel free to call this hook to ensure Tabster exists if necessary
|
9
|
+
* Creates a tabster instance with the provided configuration
|
8
10
|
*
|
9
11
|
* @internal
|
10
|
-
* @
|
11
|
-
*/ export
|
12
|
-
const { targetDocument } = useFluent();
|
12
|
+
* @param targetDocument
|
13
|
+
*/ export function createTabsterWithConfig(targetDocument) {
|
13
14
|
const defaultView = (targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.defaultView) || undefined;
|
14
15
|
const shadowDOMAPI = defaultView === null || defaultView === void 0 ? void 0 : defaultView.__tabsterShadowDOMAPI;
|
15
|
-
|
16
|
-
if (!defaultView) {
|
17
|
-
return null;
|
18
|
-
}
|
16
|
+
if (defaultView) {
|
19
17
|
return createTabster(defaultView, {
|
20
18
|
autoRoot: {},
|
21
19
|
controlTab: false,
|
@@ -26,18 +24,33 @@ import { useIsomorphicLayoutEffect, getParent } from '@fluentui/react-utilities'
|
|
26
24
|
},
|
27
25
|
DOMAPI: shadowDOMAPI
|
28
26
|
});
|
29
|
-
}
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
27
|
+
}
|
28
|
+
}
|
29
|
+
export function useTabster(factory = DEFAULT_FACTORY) {
|
30
|
+
const { targetDocument } = useFluent();
|
31
|
+
const factoryResultRef = React.useRef(null);
|
32
|
+
React.useEffect(()=>{
|
33
|
+
const tabster = createTabsterWithConfig(targetDocument);
|
34
|
+
if (tabster) {
|
35
|
+
factoryResultRef.current = factory(tabster);
|
36
|
+
return ()=>{
|
36
37
|
disposeTabster(tabster);
|
37
|
-
|
38
|
-
|
38
|
+
factoryResultRef.current = null;
|
39
|
+
};
|
40
|
+
}
|
39
41
|
}, [
|
40
|
-
|
42
|
+
targetDocument,
|
43
|
+
factory
|
41
44
|
]);
|
42
|
-
|
43
|
-
|
45
|
+
if (process.env.NODE_ENV !== 'production') {
|
46
|
+
// eslint-disable-next-line
|
47
|
+
const previousFactory = usePrevious(factory);
|
48
|
+
if (previousFactory !== null && previousFactory !== factory) {
|
49
|
+
throw new Error([
|
50
|
+
'@fluentui/react-tabster: ',
|
51
|
+
'The factory function passed to useTabster has changed. This should not ever happen.'
|
52
|
+
].join('\n'));
|
53
|
+
}
|
54
|
+
}
|
55
|
+
return factoryResultRef;
|
56
|
+
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/hooks/useTabster.ts"],"sourcesContent":["import * as React from 'react';\nimport {
|
1
|
+
{"version":3,"sources":["../src/hooks/useTabster.ts"],"sourcesContent":["import * as React from 'react';\nimport { createTabster, disposeTabster, Types as TabsterTypes } from 'tabster';\nimport { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\nimport { getParent, usePrevious } from '@fluentui/react-utilities';\n\ninterface WindowWithTabsterShadowDOMAPI extends Window {\n __tabsterShadowDOMAPI?: TabsterTypes.DOMAPI;\n}\n\ntype UseTabsterFactory<FactoryResult> = (tabster: TabsterTypes.TabsterCore) => FactoryResult;\n\nconst DEFAULT_FACTORY: UseTabsterFactory<TabsterTypes.TabsterCore> = tabster => {\n return tabster;\n};\n\n/**\n * Creates a tabster instance with the provided configuration\n *\n * @internal\n * @param targetDocument\n */\nexport function createTabsterWithConfig(targetDocument: Document | undefined): TabsterTypes.TabsterCore | undefined {\n const defaultView = targetDocument?.defaultView || undefined;\n const shadowDOMAPI = (defaultView as WindowWithTabsterShadowDOMAPI | undefined)?.__tabsterShadowDOMAPI;\n\n if (defaultView) {\n return createTabster(defaultView, {\n autoRoot: {},\n controlTab: false,\n getParent,\n checkUncontrolledTrappingFocus: element =>\n !!element.firstElementChild?.hasAttribute('data-is-focus-trap-zone-bumper'),\n DOMAPI: shadowDOMAPI,\n });\n }\n}\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 a ref to core instance or a factory result\n */\nexport function useTabster(): React.RefObject<TabsterTypes.TabsterCore | null>;\nexport function useTabster<FactoryResult>(\n factory: UseTabsterFactory<FactoryResult>,\n): React.RefObject<FactoryResult | null>;\n\nexport function useTabster<FactoryResult>(factory = DEFAULT_FACTORY) {\n const { targetDocument } = useFluent();\n const factoryResultRef = React.useRef<FactoryResult | null>(null);\n\n React.useEffect(() => {\n const tabster = createTabsterWithConfig(targetDocument);\n\n if (tabster) {\n factoryResultRef.current = factory(tabster) as FactoryResult;\n\n return () => {\n disposeTabster(tabster);\n factoryResultRef.current = null;\n };\n }\n }, [targetDocument, factory]);\n\n if (process.env.NODE_ENV !== 'production') {\n // eslint-disable-next-line\n const previousFactory = usePrevious(factory);\n\n if (previousFactory !== null && previousFactory !== factory) {\n throw new Error(\n [\n '@fluentui/react-tabster: ',\n 'The factory function passed to useTabster has changed. This should not ever happen.',\n ].join('\\n'),\n );\n }\n }\n\n return factoryResultRef;\n}\n"],"names":["React","createTabster","disposeTabster","useFluent_unstable","useFluent","getParent","usePrevious","DEFAULT_FACTORY","tabster","createTabsterWithConfig","targetDocument","defaultView","undefined","shadowDOMAPI","__tabsterShadowDOMAPI","autoRoot","controlTab","checkUncontrolledTrappingFocus","element","firstElementChild","hasAttribute","DOMAPI","useTabster","factory","factoryResultRef","useRef","useEffect","current","process","env","NODE_ENV","previousFactory","Error","join"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,YAAYA,WAAW,QAAQ;AAC/B,SAASC,aAAa,EAAEC,cAAc,QAA+B,UAAU;AAC/E,SAASC,sBAAsBC,SAAS,QAAQ,kCAAkC;AAClF,SAASC,SAAS,EAAEC,WAAW,QAAQ,4BAA4B;AAQnE,MAAMC,kBAA+DC,CAAAA;IACnE,OAAOA;AACT;AAEA;;;;;CAKC,GACD,OAAO,SAASC,wBAAwBC,cAAoC;IAC1E,MAAMC,cAAcD,CAAAA,2BAAAA,qCAAAA,eAAgBC,WAAW,KAAIC;IACnD,MAAMC,eAAgBF,wBAAAA,kCAAD,AAACA,YAA2DG,qBAAqB;IAEtG,IAAIH,aAAa;QACf,OAAOV,cAAcU,aAAa;YAChCI,UAAU,CAAC;YACXC,YAAY;YACZX;YACAY,gCAAgCC,CAAAA;oBAC5BA;uBAAF,CAAC,GAACA,6BAAAA,QAAQC,iBAAiB,cAAzBD,iDAAAA,2BAA2BE,YAAY,CAAC;;YAC5CC,QAAQR;QACV;IACF;AACF;AAcA,OAAO,SAASS,WAA0BC,UAAUhB,eAAe;IACjE,MAAM,EAAEG,cAAc,EAAE,GAAGN;IAC3B,MAAMoB,mBAAmBxB,MAAMyB,MAAM,CAAuB;IAE5DzB,MAAM0B,SAAS,CAAC;QACd,MAAMlB,UAAUC,wBAAwBC;QAExC,IAAIF,SAAS;YACXgB,iBAAiBG,OAAO,GAAGJ,QAAQf;YAEnC,OAAO;gBACLN,eAAeM;gBACfgB,iBAAiBG,OAAO,GAAG;YAC7B;QACF;IACF,GAAG;QAACjB;QAAgBa;KAAQ;IAE5B,IAAIK,QAAQC,GAAG,CAACC,QAAQ,KAAK,cAAc;QACzC,2BAA2B;QAC3B,MAAMC,kBAAkBzB,YAAYiB;QAEpC,IAAIQ,oBAAoB,QAAQA,oBAAoBR,SAAS;YAC3D,MAAM,IAAIS,MACR;gBACE;gBACA;aACD,CAACC,IAAI,CAAC;QAEX;IACF;IAEA,OAAOT;AACT"}
|
package/lib/index.js
CHANGED
@@ -7,9 +7,7 @@ export { KEYBORG_FOCUSIN } from 'keyborg';
|
|
7
7
|
// we are putting a snapshot of Tabster.Types@6.0.1 and marking the entire export as deprecated.
|
8
8
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
9
9
|
import * as TabsterTypes6_0_1_DoNotUse from './tabster-types-6.0.1-do-not-use';
|
10
|
-
export { /** @deprecated (Do not use! Exposed by mistake and will be removed in the next major version.) */ TabsterTypes6_0_1_DoNotUse as TabsterTypes, /** @deprecated Use element.dispatchEvent(new GroupperMoveFocusEvent({ action: GroupperMoveFocusActions.Escape })) */
|
11
|
-
dispatchGroupperMoveFocusEvent, /** @deprecated Use element.dispatchEvent(new MoverMoveFocusEvent({ key: MoverKeys.ArrowDown })) */ // eslint-disable-next-line @typescript-eslint/no-deprecated
|
12
|
-
dispatchMoverMoveFocusEvent };
|
10
|
+
export { /** @deprecated (Do not use! Exposed by mistake and will be removed in the next major version.) */ TabsterTypes6_0_1_DoNotUse as TabsterTypes, /** @deprecated Use element.dispatchEvent(new GroupperMoveFocusEvent({ action: GroupperMoveFocusActions.Escape })) */ dispatchGroupperMoveFocusEvent, /** @deprecated Use element.dispatchEvent(new MoverMoveFocusEvent({ key: MoverKeys.ArrowDown })) */ dispatchMoverMoveFocusEvent };
|
13
11
|
/**
|
14
12
|
* For all exports below, we don't do wildcard exports to keep Tabster API flexible. We export only required
|
15
13
|
* parts when they are needed.
|