@fluentui/react-tabster 9.0.1 → 9.1.0

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.
Files changed (44) hide show
  1. package/CHANGELOG.json +80 -1
  2. package/CHANGELOG.md +36 -2
  3. package/dist/index.d.ts +15 -1
  4. package/lib/focus/constants.js +2 -0
  5. package/lib/focus/constants.js.map +1 -1
  6. package/lib/focus/createCustomFocusIndicatorStyle.js +16 -2
  7. package/lib/focus/createCustomFocusIndicatorStyle.js.map +1 -1
  8. package/lib/focus/focusVisiblePolyfill.js +84 -0
  9. package/lib/focus/focusVisiblePolyfill.js.map +1 -0
  10. package/lib/focus/focusWithinPolyfill.js +58 -0
  11. package/lib/focus/focusWithinPolyfill.js.map +1 -0
  12. package/lib/hooks/index.js +2 -0
  13. package/lib/hooks/index.js.map +1 -1
  14. package/lib/hooks/useArrowNavigationGroup.js +18 -8
  15. package/lib/hooks/useArrowNavigationGroup.js.map +1 -1
  16. package/lib/hooks/useFocusVisible.js +16 -0
  17. package/lib/hooks/useFocusVisible.js.map +1 -0
  18. package/lib/hooks/useFocusWithin.js +22 -0
  19. package/lib/hooks/useFocusWithin.js.map +1 -0
  20. package/lib/hooks/useTabster.js +20 -13
  21. package/lib/hooks/useTabster.js.map +1 -1
  22. package/lib/index.js +1 -1
  23. package/lib/index.js.map +1 -1
  24. package/lib-commonjs/focus/constants.js +3 -1
  25. package/lib-commonjs/focus/constants.js.map +1 -1
  26. package/lib-commonjs/focus/createCustomFocusIndicatorStyle.js +15 -1
  27. package/lib-commonjs/focus/createCustomFocusIndicatorStyle.js.map +1 -1
  28. package/lib-commonjs/focus/focusVisiblePolyfill.js +95 -0
  29. package/lib-commonjs/focus/focusVisiblePolyfill.js.map +1 -0
  30. package/lib-commonjs/focus/focusWithinPolyfill.js +69 -0
  31. package/lib-commonjs/focus/focusWithinPolyfill.js.map +1 -0
  32. package/lib-commonjs/hooks/index.js +4 -0
  33. package/lib-commonjs/hooks/index.js.map +1 -1
  34. package/lib-commonjs/hooks/useArrowNavigationGroup.js +18 -8
  35. package/lib-commonjs/hooks/useArrowNavigationGroup.js.map +1 -1
  36. package/lib-commonjs/hooks/useFocusVisible.js +28 -0
  37. package/lib-commonjs/hooks/useFocusVisible.js.map +1 -0
  38. package/lib-commonjs/hooks/useFocusWithin.js +34 -0
  39. package/lib-commonjs/hooks/useFocusWithin.js.map +1 -0
  40. package/lib-commonjs/hooks/useTabster.js +22 -13
  41. package/lib-commonjs/hooks/useTabster.js.map +1 -1
  42. package/lib-commonjs/index.js +13 -1
  43. package/lib-commonjs/index.js.map +1 -1
  44. package/package.json +6 -5
package/CHANGELOG.json CHANGED
@@ -2,7 +2,86 @@
2
2
  "name": "@fluentui/react-tabster",
3
3
  "entries": [
4
4
  {
5
- "date": "Tue, 28 Jun 2022 17:37:53 GMT",
5
+ "date": "Wed, 03 Aug 2022 16:00:31 GMT",
6
+ "tag": "@fluentui/react-tabster_v9.1.0",
7
+ "version": "9.1.0",
8
+ "comments": {
9
+ "patch": [
10
+ {
11
+ "author": "lingfangao@hotmail.com",
12
+ "package": "@fluentui/react-tabster",
13
+ "commit": "b9e6c6a7dd8ce6111744739a0ec486b99c2bb2ea",
14
+ "comment": "chore: Bump tabster to 2.1.0"
15
+ },
16
+ {
17
+ "author": "miroslav.stastny@microsoft.com",
18
+ "package": "@fluentui/react-tabster",
19
+ "commit": "08563664778fd80284561d3c9d254307a0a32362",
20
+ "comment": "chore: Bump Griffel dependencies"
21
+ }
22
+ ],
23
+ "minor": [
24
+ {
25
+ "author": "lingfangao@hotmail.com",
26
+ "package": "@fluentui/react-tabster",
27
+ "commit": "2756c649a83c0fa0a20b82c62855d388a5e6bc2a",
28
+ "comment": "feat: Adds `ignoreDefaultKeydown` option to `useArrowNavigationGroup`"
29
+ },
30
+ {
31
+ "author": "lingfangao@hotmail.com",
32
+ "package": "@fluentui/react-tabster",
33
+ "commit": "71590ea6aeab8ce24d8c8e50e0ee80ece81a4392",
34
+ "comment": "feat: create `:focus-visible` and `:focus-within` polyfills"
35
+ }
36
+ ],
37
+ "none": [
38
+ {
39
+ "author": "lingfangao@hotmail.com",
40
+ "package": "@fluentui/react-tabster",
41
+ "commit": "99cc385631d04a76ee10ebc143cb9fecd99640b6",
42
+ "comment": "chore: Add `prerelease` as disallowed changetype for 9.0.0 packages"
43
+ }
44
+ ]
45
+ }
46
+ },
47
+ {
48
+ "date": "Thu, 14 Jul 2022 21:21:05 GMT",
49
+ "tag": "@fluentui/react-tabster_v9.0.3",
50
+ "version": "9.0.3",
51
+ "comments": {
52
+ "patch": [
53
+ {
54
+ "author": "Humberto.Morimoto@microsoft.com",
55
+ "package": "@fluentui/react-tabster",
56
+ "commit": "802bc4e3730a88b0fc61b5bf42ef7fc6b6543fe2",
57
+ "comment": "fix: Fixing bad version bump of @fluentui/react-utilities."
58
+ },
59
+ {
60
+ "author": "beachball",
61
+ "package": "@fluentui/react-tabster",
62
+ "comment": "Bump @fluentui/react-utilities to v9.0.2",
63
+ "commit": "79b513146194367544160f364b0a7dd749ed93e4"
64
+ }
65
+ ]
66
+ }
67
+ },
68
+ {
69
+ "date": "Thu, 14 Jul 2022 17:06:26 GMT",
70
+ "tag": "@fluentui/react-tabster_v9.0.2",
71
+ "version": "9.0.2",
72
+ "comments": {
73
+ "patch": [
74
+ {
75
+ "author": "beachball",
76
+ "package": "@fluentui/react-tabster",
77
+ "comment": "Bump @fluentui/react-utilities to v9.0.1-0",
78
+ "commit": "35237381e941c8935b1892c9217096cea3e5601f"
79
+ }
80
+ ]
81
+ }
82
+ },
83
+ {
84
+ "date": "Tue, 28 Jun 2022 17:39:53 GMT",
6
85
  "tag": "@fluentui/react-tabster_v9.0.1",
7
86
  "version": "9.0.1",
8
87
  "comments": {
package/CHANGELOG.md CHANGED
@@ -1,12 +1,46 @@
1
1
  # Change Log - @fluentui/react-tabster
2
2
 
3
- This log was last generated on Tue, 28 Jun 2022 17:37:53 GMT and should not be manually modified.
3
+ This log was last generated on Wed, 03 Aug 2022 16:00:31 GMT and should not be manually modified.
4
4
 
5
5
  <!-- Start content -->
6
6
 
7
+ ## [9.1.0](https://github.com/microsoft/fluentui/tree/@fluentui/react-tabster_v9.1.0)
8
+
9
+ Wed, 03 Aug 2022 16:00:31 GMT
10
+ [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-tabster_v9.0.3..@fluentui/react-tabster_v9.1.0)
11
+
12
+ ### Minor changes
13
+
14
+ - feat: Adds `ignoreDefaultKeydown` option to `useArrowNavigationGroup` ([PR #24101](https://github.com/microsoft/fluentui/pull/24101) by lingfangao@hotmail.com)
15
+ - feat: create `:focus-visible` and `:focus-within` polyfills ([PR #24154](https://github.com/microsoft/fluentui/pull/24154) by lingfangao@hotmail.com)
16
+
17
+ ### Patches
18
+
19
+ - chore: Bump tabster to 2.1.0 ([PR #23811](https://github.com/microsoft/fluentui/pull/23811) by lingfangao@hotmail.com)
20
+ - chore: Bump Griffel dependencies ([PR #24114](https://github.com/microsoft/fluentui/pull/24114) by miroslav.stastny@microsoft.com)
21
+
22
+ ## [9.0.3](https://github.com/microsoft/fluentui/tree/@fluentui/react-tabster_v9.0.3)
23
+
24
+ Thu, 14 Jul 2022 21:21:05 GMT
25
+ [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-tabster_v9.0.2..@fluentui/react-tabster_v9.0.3)
26
+
27
+ ### Patches
28
+
29
+ - fix: Fixing bad version bump of @fluentui/react-utilities. ([PR #23920](https://github.com/microsoft/fluentui/pull/23920) by Humberto.Morimoto@microsoft.com)
30
+ - Bump @fluentui/react-utilities to v9.0.2 ([PR #23918](https://github.com/microsoft/fluentui/pull/23918) by beachball)
31
+
32
+ ## [9.0.2](https://github.com/microsoft/fluentui/tree/@fluentui/react-tabster_v9.0.2)
33
+
34
+ Thu, 14 Jul 2022 17:06:26 GMT
35
+ [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-tabster_v9.0.1..@fluentui/react-tabster_v9.0.2)
36
+
37
+ ### Patches
38
+
39
+ - Bump @fluentui/react-utilities to v9.0.1-0 ([PR #23897](https://github.com/microsoft/fluentui/pull/23897) by beachball)
40
+
7
41
  ## [9.0.1](https://github.com/microsoft/fluentui/tree/@fluentui/react-tabster_v9.0.1)
8
42
 
9
- Tue, 28 Jun 2022 17:37:53 GMT
43
+ Tue, 28 Jun 2022 17:39:53 GMT
10
44
  [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-tabster_v9.0.0..@fluentui/react-tabster_v9.0.1)
11
45
 
12
46
  ### Patches
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import type { GriffelStyle } from '@griffel/react';
2
+ import * as React_2 from 'react';
2
3
  import type { RefObject } from 'react';
3
4
  import { Types } from 'tabster';
4
5
 
@@ -45,7 +46,7 @@ export declare type FocusOutlineStyleOptions = {
45
46
  * A hook that returns the necessary tabster attributes to support arrow key navigation
46
47
  * @param options - Options to configure keyboard navigation
47
48
  */
48
- export declare const useArrowNavigationGroup: (options?: UseArrowNavigationGroupOptions | undefined) => Types.TabsterDOMAttribute;
49
+ export declare const useArrowNavigationGroup: (options?: UseArrowNavigationGroupOptions) => Types.TabsterDOMAttribute;
49
50
 
50
51
  export declare interface UseArrowNavigationGroupOptions {
51
52
  /**
@@ -66,6 +67,10 @@ export declare interface UseArrowNavigationGroupOptions {
66
67
  * Allow tabbing within the arrow navigation group items.
67
68
  */
68
69
  tabbable?: boolean;
70
+ /**
71
+ * Tabster should ignore default handling of keydown events
72
+ */
73
+ ignoreDefaultKeydown?: Types.FocusableProps['ignoreKeydown'];
69
74
  }
70
75
 
71
76
  /**
@@ -92,6 +97,15 @@ export declare const useFocusFinders: () => {
92
97
  findPrevFocusable: (currentElement: HTMLElement, options?: Pick<Types.FindNextProps, 'container'>) => HTMLElement | null | undefined;
93
98
  };
94
99
 
100
+ export declare function useFocusVisible<TElement extends HTMLElement = HTMLElement>(): React_2.RefObject<TElement>;
101
+
102
+ /**
103
+ * A ponyfill that allows `:focus-within` to support visibility based on keyboard/mouse navigation
104
+ * like `:focus-visible` https://github.com/WICG/focus-visible/issues/151
105
+ * @returns ref to the element that uses `:focus-within` styles
106
+ */
107
+ export declare function useFocusWithin<TElement extends HTMLElement = HTMLElement>(): React_2.RefObject<TElement>;
108
+
95
109
  /**
96
110
  * Instantiates [keyborg](https://github.com/microsoft/keyborg) and adds `data-keyboard-nav`
97
111
  * attribute to a referenced element to ensure keyboard navigation awareness
@@ -1,5 +1,7 @@
1
1
  export const KEYBOARD_NAV_ATTRIBUTE = 'data-keyboard-nav';
2
2
  export const KEYBOARD_NAV_SELECTOR = `:global([${KEYBOARD_NAV_ATTRIBUTE}])`;
3
+ export const FOCUS_VISIBLE_CLASS = 'fui-focus-visible';
4
+ export const FOCUS_WITHIN_CLASS = 'fui-focus-within';
3
5
  export const defaultOptions = {
4
6
  style: {},
5
7
  selector: 'focus'
@@ -1 +1 @@
1
- {"version":3,"sources":["focus/constants.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,sBAAsB,GAAG,mBAA/B;AACP,OAAO,MAAM,qBAAqB,GAAG,YAAY,sBAAsB,IAAhE;AACP,OAAO,MAAM,cAAc,GAAG;EAC5B,KAAK,EAAE,EADqB;EAE5B,QAAQ,EAAE;AAFkB,CAAvB","sourcesContent":["export const KEYBOARD_NAV_ATTRIBUTE = 'data-keyboard-nav' as const;\nexport const KEYBOARD_NAV_SELECTOR = `:global([${KEYBOARD_NAV_ATTRIBUTE}])` as const;\nexport const defaultOptions = {\n style: {},\n selector: 'focus',\n} as const;\n"],"sourceRoot":"../src/"}
1
+ {"version":3,"sources":["focus/constants.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,sBAAsB,GAAG,mBAA/B;AACP,OAAO,MAAM,qBAAqB,GAAG,YAAY,sBAAsB,IAAhE;AACP,OAAO,MAAM,mBAAmB,GAAG,mBAA5B;AACP,OAAO,MAAM,kBAAkB,GAAG,kBAA3B;AACP,OAAO,MAAM,cAAc,GAAG;EAC5B,KAAK,EAAE,EADqB;EAE5B,QAAQ,EAAE;AAFkB,CAAvB","sourcesContent":["export const KEYBOARD_NAV_ATTRIBUTE = 'data-keyboard-nav' as const;\nexport const KEYBOARD_NAV_SELECTOR = `:global([${KEYBOARD_NAV_ATTRIBUTE}])` as const;\nexport const FOCUS_VISIBLE_CLASS = 'fui-focus-visible';\nexport const FOCUS_WITHIN_CLASS = 'fui-focus-within';\nexport const defaultOptions = {\n style: {},\n selector: 'focus',\n} as const;\n"],"sourceRoot":"../src/"}
@@ -1,4 +1,4 @@
1
- import { KEYBOARD_NAV_SELECTOR, defaultOptions } from './constants';
1
+ import { FOCUS_VISIBLE_CLASS, defaultOptions, FOCUS_WITHIN_CLASS } from './constants';
2
2
  /**
3
3
  * Creates a style for @see makeStyles that includes the necessary selectors for focus.
4
4
  * Should be used only when @see createFocusOutlineStyle does not fit requirements
@@ -13,6 +13,20 @@ export const createCustomFocusIndicatorStyle = (style, {
13
13
  ':focus': {
14
14
  outlineStyle: 'none'
15
15
  },
16
- [`${KEYBOARD_NAV_SELECTOR} :${selector}`]: style
16
+ ':focus-visible': {
17
+ outlineStyle: 'none'
18
+ },
19
+ // Remove the `.fui-FluentProvider` global selector once Griffel supports chained global styles
20
+ // https://github.com/microsoft/griffel/issues/178
21
+ ...(selector === 'focus' && {
22
+ [`:global(.fui-FluentProvider)`]: {
23
+ [`& .${FOCUS_VISIBLE_CLASS}`]: style
24
+ }
25
+ }),
26
+ ...(selector === 'focus-within' && {
27
+ [`:global(.fui-FluentProvider)`]: {
28
+ [`& .${FOCUS_WITHIN_CLASS}:${selector}`]: style
29
+ }
30
+ })
17
31
  });
18
32
  //# sourceMappingURL=createCustomFocusIndicatorStyle.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["focus/createCustomFocusIndicatorStyle.ts"],"names":[],"mappings":"AAAA,SAAS,qBAAT,EAAgC,cAAhC,QAAsD,aAAtD;AAOA;;;;;;AAMG;;AACH,OAAO,MAAM,+BAA+B,GAAG,CAC7C,KAD6C,EAE7C;EAAE,QAAQ,GAAG,cAAc,CAAC;AAA5B,IAAiF,cAFpC,MAG3B;EAClB,UAAU;IACR,YAAY,EAAE;EADN,CADQ;EAIlB,CAAC,GAAG,qBAAqB,KAAK,QAAQ,EAAtC,GAA2C;AAJzB,CAH2B,CAAxC","sourcesContent":["import { KEYBOARD_NAV_SELECTOR, defaultOptions } from './constants';\nimport type { GriffelStyle } from '@griffel/react';\n\nexport interface CreateCustomFocusIndicatorStyleOptions {\n selector?: 'focus' | 'focus-within';\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 * @param options - Configure the style of the focus outline\n */\nexport const createCustomFocusIndicatorStyle = (\n style: GriffelStyle,\n { selector = defaultOptions.selector }: CreateCustomFocusIndicatorStyleOptions = defaultOptions,\n): GriffelStyle => ({\n ':focus': {\n outlineStyle: 'none',\n },\n [`${KEYBOARD_NAV_SELECTOR} :${selector}`]: style,\n});\n"],"sourceRoot":"../src/"}
1
+ {"version":3,"sources":["focus/createCustomFocusIndicatorStyle.ts"],"names":[],"mappings":"AAAA,SAAS,mBAAT,EAA8B,cAA9B,EAA8C,kBAA9C,QAAwE,aAAxE;AAOA;;;;;;AAMG;;AACH,OAAO,MAAM,+BAA+B,GAAG,CAC7C,KAD6C,EAE7C;EAAE,QAAQ,GAAG,cAAc,CAAC;AAA5B,IAAiF,cAFpC,MAG3B;EAClB,UAAU;IACR,YAAY,EAAE;EADN,CADQ;EAIlB,kBAAkB;IAChB,YAAY,EAAE;EADE,CAJA;EAOlB;EACA;EACA,IAAI,QAAQ,KAAK,OAAb,IAAwB;IAC1B,CAAC,8BAAD,GAAkC;MAChC,CAAC,MAAM,mBAAmB,EAA1B,GAA+B;IADC;EADR,CAA5B,CATkB;EAclB,IAAI,QAAQ,KAAK,cAAb,IAA+B;IACjC,CAAC,8BAAD,GAAkC;MAChC,CAAC,MAAM,kBAAkB,IAAI,QAAQ,EAArC,GAA0C;IADV;EADD,CAAnC;AAdkB,CAH2B,CAAxC","sourcesContent":["import { FOCUS_VISIBLE_CLASS, defaultOptions, FOCUS_WITHIN_CLASS } from './constants';\nimport type { GriffelStyle } from '@griffel/react';\n\nexport interface CreateCustomFocusIndicatorStyleOptions {\n selector?: 'focus' | 'focus-within';\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 * @param options - Configure the style of the focus outline\n */\nexport const createCustomFocusIndicatorStyle = (\n style: GriffelStyle,\n { selector = defaultOptions.selector }: CreateCustomFocusIndicatorStyleOptions = defaultOptions,\n): GriffelStyle => ({\n ':focus': {\n outlineStyle: 'none',\n },\n ':focus-visible': {\n outlineStyle: 'none',\n },\n // Remove the `.fui-FluentProvider` global selector once Griffel supports chained global styles\n // https://github.com/microsoft/griffel/issues/178\n ...(selector === 'focus' && {\n [`:global(.fui-FluentProvider)`]: {\n [`& .${FOCUS_VISIBLE_CLASS}`]: style,\n },\n }),\n ...(selector === 'focus-within' && {\n [`:global(.fui-FluentProvider)`]: {\n [`& .${FOCUS_WITHIN_CLASS}:${selector}`]: style,\n },\n }),\n});\n"],"sourceRoot":"../src/"}
@@ -0,0 +1,84 @@
1
+ import { KEYBORG_FOCUSIN, createKeyborg, disposeKeyborg } from 'keyborg';
2
+ import { FOCUS_VISIBLE_CLASS } from './constants';
3
+ export function applyFocusVisiblePolyfill(scope, win) {
4
+ if (alreadyInScope(scope)) {
5
+ // Focus visible polyfill already applied at this scope
6
+ return () => undefined;
7
+ }
8
+
9
+ const state = {
10
+ current: undefined
11
+ };
12
+ const keyborg = createKeyborg(win); // When navigation mode changes remove the focus-visible selector
13
+
14
+ keyborg.subscribe(isNavigatingWithKeyboard => {
15
+ if (!isNavigatingWithKeyboard && state.current) {
16
+ removeFocusVisibleClass(state.current);
17
+ state.current = undefined;
18
+ }
19
+ }); // Keyborg's focusin event is delegated so it's only registered once on the window
20
+ // and contains metadata about the focus event
21
+
22
+ const keyborgListener = e => {
23
+ if (state.current) {
24
+ removeFocusVisibleClass(state.current);
25
+ state.current = undefined;
26
+ }
27
+
28
+ if (keyborg.isNavigatingWithKeyboard() && isHTMLElement(e.target) && e.target) {
29
+ // Griffel can't create chained global styles so use the parent element for now
30
+ state.current = e.target;
31
+ applyFocusVisibleClass(state.current);
32
+ }
33
+ }; // Make sure that when focus leaves the scope, the focus visible class is removed
34
+
35
+
36
+ const blurListener = e => {
37
+ if (!e.relatedTarget || isHTMLElement(e.relatedTarget) && !scope.contains(e.relatedTarget)) {
38
+ if (state.current) {
39
+ removeFocusVisibleClass(state.current);
40
+ state.current = undefined;
41
+ }
42
+ }
43
+ };
44
+
45
+ scope.addEventListener(KEYBORG_FOCUSIN, keyborgListener);
46
+ scope.addEventListener('focusout', blurListener);
47
+ scope.focusVisible = true; // Return disposer
48
+
49
+ return () => {
50
+ scope.removeEventListener(KEYBORG_FOCUSIN, keyborgListener);
51
+ scope.removeEventListener('focusout', blurListener);
52
+ delete scope.focusVisible;
53
+ disposeKeyborg(keyborg);
54
+ };
55
+ }
56
+
57
+ function applyFocusVisibleClass(el) {
58
+ el.classList.add(FOCUS_VISIBLE_CLASS);
59
+ }
60
+
61
+ function removeFocusVisibleClass(el) {
62
+ el.classList.remove(FOCUS_VISIBLE_CLASS);
63
+ }
64
+
65
+ function isHTMLElement(target) {
66
+ if (!target) {
67
+ return false;
68
+ }
69
+
70
+ return Boolean(target && typeof target === 'object' && 'classList' in target && 'contains' in target);
71
+ }
72
+
73
+ function alreadyInScope(el) {
74
+ if (!el) {
75
+ return false;
76
+ }
77
+
78
+ if (el.focusVisible) {
79
+ return true;
80
+ }
81
+
82
+ return alreadyInScope(el === null || el === void 0 ? void 0 : el.parentElement);
83
+ }
84
+ //# sourceMappingURL=focusVisiblePolyfill.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["focus/focusVisiblePolyfill.ts"],"names":[],"mappings":"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","sourcesContent":["import { KEYBORG_FOCUSIN, KeyborgFocusInEvent, createKeyborg, disposeKeyborg } from 'keyborg';\nimport { FOCUS_VISIBLE_CLASS } from './constants';\n\n/**\n * Because `addEventListener` type override falls back to 2nd definition (evt name is unknown string literal)\n * evt is being typed as a base class of MouseEvent -> `Event`.\n * This type is used to override `listener` calls to make TS happy\n */\ntype ListenerOverride = (evt: Event) => void;\n\ntype FocusVisibleState = {\n /**\n * Current element with focus visible in state\n */\n current: HTMLElement | undefined;\n};\n\ntype HTMLElementWithFocusVisibleScope = {\n focusVisible: boolean | undefined;\n} & HTMLElement;\n\nexport function applyFocusVisiblePolyfill(scope: HTMLElement, win: Window): () => void {\n if (alreadyInScope(scope)) {\n // Focus visible polyfill already applied at this scope\n return () => undefined;\n }\n\n const state: FocusVisibleState = {\n current: undefined,\n };\n\n const keyborg = createKeyborg(win);\n\n // When navigation mode changes remove the focus-visible selector\n keyborg.subscribe(isNavigatingWithKeyboard => {\n if (!isNavigatingWithKeyboard && state.current) {\n removeFocusVisibleClass(state.current);\n state.current = undefined;\n }\n });\n\n // Keyborg's focusin event is delegated so it's only registered once on the window\n // and contains metadata about the focus event\n const keyborgListener = (e: KeyborgFocusInEvent) => {\n if (state.current) {\n removeFocusVisibleClass(state.current);\n state.current = undefined;\n }\n\n if (keyborg.isNavigatingWithKeyboard() && isHTMLElement(e.target) && e.target) {\n // Griffel can't create chained global styles so use the parent element for now\n state.current = e.target;\n applyFocusVisibleClass(state.current);\n }\n };\n\n // Make sure that when focus leaves the scope, the focus visible class is removed\n const blurListener = (e: FocusEvent) => {\n if (!e.relatedTarget || (isHTMLElement(e.relatedTarget) && !scope.contains(e.relatedTarget))) {\n if (state.current) {\n removeFocusVisibleClass(state.current);\n state.current = undefined;\n }\n }\n };\n\n scope.addEventListener(KEYBORG_FOCUSIN, keyborgListener as ListenerOverride);\n scope.addEventListener('focusout', blurListener);\n (scope as HTMLElementWithFocusVisibleScope).focusVisible = true;\n\n // Return disposer\n return () => {\n scope.removeEventListener(KEYBORG_FOCUSIN, keyborgListener as ListenerOverride);\n scope.removeEventListener('focusout', blurListener);\n delete (scope as HTMLElementWithFocusVisibleScope).focusVisible;\n disposeKeyborg(keyborg);\n };\n}\n\nfunction applyFocusVisibleClass(el: HTMLElement) {\n el.classList.add(FOCUS_VISIBLE_CLASS);\n}\n\nfunction removeFocusVisibleClass(el: HTMLElement) {\n el.classList.remove(FOCUS_VISIBLE_CLASS);\n}\n\nfunction isHTMLElement(target: EventTarget | null): target is HTMLElement {\n if (!target) {\n return false;\n }\n return Boolean(target && typeof target === 'object' && 'classList' in target && 'contains' in target);\n}\n\nfunction alreadyInScope(el: HTMLElement | null | undefined): boolean {\n if (!el) {\n return false;\n }\n\n if ((el as HTMLElementWithFocusVisibleScope).focusVisible) {\n return true;\n }\n\n return alreadyInScope(el?.parentElement);\n}\n"],"sourceRoot":"../src/"}
@@ -0,0 +1,58 @@
1
+ import { KEYBORG_FOCUSIN, createKeyborg, disposeKeyborg } from 'keyborg';
2
+ import { FOCUS_WITHIN_CLASS } from './constants';
3
+ /**
4
+ * A ponyfill that allows `:focus-within` to support visibility based on keyboard/mouse navigation
5
+ * like `:focus-visible` https://github.com/WICG/focus-visible/issues/151
6
+ * @returns ref to the element that uses `:focus-within` styles
7
+ */
8
+
9
+ export function applyFocusWithinPolyfill(element, win) {
10
+ const keyborg = createKeyborg(win); // When navigation mode changes to mouse, remove the focus-within selector
11
+
12
+ keyborg.subscribe(isNavigatingWithKeyboard => {
13
+ if (!isNavigatingWithKeyboard) {
14
+ removeFocusWithinClass(element);
15
+ }
16
+ }); // Keyborg's focusin event is delegated so it's only registered once on the window
17
+ // and contains metadata about the focus event
18
+
19
+ const keyborgListener = e => {
20
+ if (keyborg.isNavigatingWithKeyboard() && isHTMLElement(e.target)) {
21
+ // Griffel can't create chained global styles so use the parent element for now
22
+ applyFocusWithinClass(element);
23
+ }
24
+ }; // Make sure that when focus leaves the scope, the focus within class is removed
25
+
26
+
27
+ const blurListener = e => {
28
+ if (!e.relatedTarget || isHTMLElement(e.relatedTarget) && !element.contains(e.relatedTarget)) {
29
+ removeFocusWithinClass(element);
30
+ }
31
+ };
32
+
33
+ element.addEventListener(KEYBORG_FOCUSIN, keyborgListener);
34
+ element.addEventListener('focusout', blurListener); // Return disposer
35
+
36
+ return () => {
37
+ element.removeEventListener(KEYBORG_FOCUSIN, keyborgListener);
38
+ element.removeEventListener('focusout', blurListener);
39
+ disposeKeyborg(keyborg);
40
+ };
41
+ }
42
+
43
+ function applyFocusWithinClass(el) {
44
+ el.classList.add(FOCUS_WITHIN_CLASS);
45
+ }
46
+
47
+ function removeFocusWithinClass(el) {
48
+ el.classList.remove(FOCUS_WITHIN_CLASS);
49
+ }
50
+
51
+ function isHTMLElement(target) {
52
+ if (!target) {
53
+ return false;
54
+ }
55
+
56
+ return Boolean(target && typeof target === 'object' && 'classList' in target && 'contains' in target);
57
+ }
58
+ //# sourceMappingURL=focusWithinPolyfill.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["focus/focusWithinPolyfill.ts"],"names":[],"mappings":"AAAA,SAAS,eAAT,EAA+C,aAA/C,EAA8D,cAA9D,QAAoF,SAApF;AACA,SAAS,kBAAT,QAAmC,aAAnC;AASA;;;;AAIG;;AACH,OAAM,SAAU,wBAAV,CAAmC,OAAnC,EAAyD,GAAzD,EAAoE;EACxE,MAAM,OAAO,GAAG,aAAa,CAAC,GAAD,CAA7B,CADwE,CAGxE;;EACA,OAAO,CAAC,SAAR,CAAkB,wBAAwB,IAAG;IAC3C,IAAI,CAAC,wBAAL,EAA+B;MAC7B,sBAAsB,CAAC,OAAD,CAAtB;IACD;EACF,CAJD,EAJwE,CAUxE;EACA;;EACA,MAAM,eAAe,GAAI,CAAD,IAA2B;IACjD,IAAI,OAAO,CAAC,wBAAR,MAAsC,aAAa,CAAC,CAAC,CAAC,MAAH,CAAvD,EAAmE;MACjE;MACA,qBAAqB,CAAC,OAAD,CAArB;IACD;EACF,CALD,CAZwE,CAmBxE;;;EACA,MAAM,YAAY,GAAI,CAAD,IAAkB;IACrC,IAAI,CAAC,CAAC,CAAC,aAAH,IAAqB,aAAa,CAAC,CAAC,CAAC,aAAH,CAAb,IAAkC,CAAC,OAAO,CAAC,QAAR,CAAiB,CAAC,CAAC,aAAnB,CAA5D,EAAgG;MAC9F,sBAAsB,CAAC,OAAD,CAAtB;IACD;EACF,CAJD;;EAMA,OAAO,CAAC,gBAAR,CAAyB,eAAzB,EAA0C,eAA1C;EACA,OAAO,CAAC,gBAAR,CAAyB,UAAzB,EAAqC,YAArC,EA3BwE,CA6BxE;;EACA,OAAO,MAAK;IACV,OAAO,CAAC,mBAAR,CAA4B,eAA5B,EAA6C,eAA7C;IACA,OAAO,CAAC,mBAAR,CAA4B,UAA5B,EAAwC,YAAxC;IACA,cAAc,CAAC,OAAD,CAAd;EACD,CAJD;AAKD;;AAED,SAAS,qBAAT,CAA+B,EAA/B,EAA8C;EAC5C,EAAE,CAAC,SAAH,CAAa,GAAb,CAAiB,kBAAjB;AACD;;AAED,SAAS,sBAAT,CAAgC,EAAhC,EAA+C;EAC7C,EAAE,CAAC,SAAH,CAAa,MAAb,CAAoB,kBAApB;AACD;;AAED,SAAS,aAAT,CAAuB,MAAvB,EAAiD;EAC/C,IAAI,CAAC,MAAL,EAAa;IACX,OAAO,KAAP;EACD;;EACD,OAAO,OAAO,CAAC,MAAM,IAAI,OAAO,MAAP,KAAkB,QAA5B,IAAwC,eAAe,MAAvD,IAAiE,cAAc,MAAhF,CAAd;AACD","sourcesContent":["import { KEYBORG_FOCUSIN, KeyborgFocusInEvent, createKeyborg, disposeKeyborg } from 'keyborg';\nimport { FOCUS_WITHIN_CLASS } from './constants';\n\n/**\n * Because `addEventListener` type override falls back to 2nd definition (evt name is unknown string literal)\n * evt is being typed as a base class of MouseEvent -> `Event`.\n * This type is used to override `listener` calls to make TS happy\n */\ntype ListenerOverride = (evt: Event) => void;\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 applyFocusWithinPolyfill(element: HTMLElement, win: Window): () => void {\n const keyborg = createKeyborg(win);\n\n // When navigation mode changes to mouse, remove the focus-within selector\n keyborg.subscribe(isNavigatingWithKeyboard => {\n if (!isNavigatingWithKeyboard) {\n removeFocusWithinClass(element);\n }\n });\n\n // Keyborg's focusin event is delegated so it's only registered once on the window\n // and contains metadata about the focus event\n const keyborgListener = (e: KeyborgFocusInEvent) => {\n if (keyborg.isNavigatingWithKeyboard() && isHTMLElement(e.target)) {\n // Griffel can't create chained global styles so use the parent element for now\n applyFocusWithinClass(element);\n }\n };\n\n // Make sure that when focus leaves the scope, the focus within class is removed\n const blurListener = (e: FocusEvent) => {\n if (!e.relatedTarget || (isHTMLElement(e.relatedTarget) && !element.contains(e.relatedTarget))) {\n removeFocusWithinClass(element);\n }\n };\n\n element.addEventListener(KEYBORG_FOCUSIN, keyborgListener as ListenerOverride);\n element.addEventListener('focusout', blurListener);\n\n // Return disposer\n return () => {\n element.removeEventListener(KEYBORG_FOCUSIN, keyborgListener as ListenerOverride);\n element.removeEventListener('focusout', blurListener);\n disposeKeyborg(keyborg);\n };\n}\n\nfunction applyFocusWithinClass(el: HTMLElement) {\n el.classList.add(FOCUS_WITHIN_CLASS);\n}\n\nfunction removeFocusWithinClass(el: HTMLElement) {\n el.classList.remove(FOCUS_WITHIN_CLASS);\n}\n\nfunction isHTMLElement(target: EventTarget | null): target is HTMLElement {\n if (!target) {\n return false;\n }\n return Boolean(target && typeof target === 'object' && 'classList' in target && 'contains' in target);\n}\n"],"sourceRoot":"../src/"}
@@ -1,6 +1,8 @@
1
1
  export * from './useArrowNavigationGroup';
2
2
  export * from './useFocusableGroup';
3
3
  export * from './useFocusFinders';
4
+ export * from './useFocusVisible';
5
+ export * from './useFocusWithin';
4
6
  export * from './useKeyboardNavAttribute';
5
7
  export * from './useModalAttributes';
6
8
  export * from './useTabsterAttributes';
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"../src/","sources":["hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAC;AAC1C,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,sBAAsB,CAAC;AACrC,cAAc,wBAAwB,CAAC","sourcesContent":["export * from './useArrowNavigationGroup';\nexport * from './useFocusableGroup';\nexport * from './useFocusFinders';\nexport * from './useKeyboardNavAttribute';\nexport * from './useModalAttributes';\nexport * from './useTabsterAttributes';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"../src/","sources":["hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAC;AAC1C,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,sBAAsB,CAAC;AACrC,cAAc,wBAAwB,CAAC","sourcesContent":["export * from './useArrowNavigationGroup';\nexport * from './useFocusableGroup';\nexport * from './useFocusFinders';\nexport * from './useFocusVisible';\nexport * from './useFocusWithin';\nexport * from './useKeyboardNavAttribute';\nexport * from './useModalAttributes';\nexport * from './useTabsterAttributes';\n"]}
@@ -6,9 +6,14 @@ import { useTabster } from './useTabster';
6
6
  * @param options - Options to configure keyboard navigation
7
7
  */
8
8
 
9
- export const useArrowNavigationGroup = options => {
10
- var _a;
11
-
9
+ export const useArrowNavigationGroup = (options = {}) => {
10
+ const {
11
+ circular,
12
+ axis,
13
+ memorizeCurrent,
14
+ tabbable,
15
+ ignoreDefaultKeydown
16
+ } = options;
12
17
  const tabster = useTabster();
13
18
 
14
19
  if (tabster) {
@@ -17,11 +22,16 @@ export const useArrowNavigationGroup = options => {
17
22
 
18
23
  return useTabsterAttributes({
19
24
  mover: {
20
- cyclic: !!(options === null || options === void 0 ? void 0 : options.circular),
21
- direction: axisToMoverDirection((_a = options === null || options === void 0 ? void 0 : options.axis) !== null && _a !== void 0 ? _a : 'vertical'),
22
- memorizeCurrent: options === null || options === void 0 ? void 0 : options.memorizeCurrent,
23
- tabbable: options === null || options === void 0 ? void 0 : options.tabbable
24
- }
25
+ cyclic: !!circular,
26
+ direction: axisToMoverDirection(axis !== null && axis !== void 0 ? axis : 'vertical'),
27
+ memorizeCurrent: memorizeCurrent,
28
+ tabbable: tabbable
29
+ },
30
+ ...(ignoreDefaultKeydown && {
31
+ focusable: {
32
+ ignoreKeydown: ignoreDefaultKeydown
33
+ }
34
+ })
25
35
  });
26
36
  };
27
37
 
@@ -1 +1 @@
1
- {"version":3,"sources":["hooks/useArrowNavigationGroup.ts"],"names":[],"mappings":"AAAA,SAAS,KAAT,EAAgB,QAAhB,QAAgC,SAAhC;AACA,SAAS,oBAAT,QAAqC,wBAArC;AACA,SAAS,UAAT,QAA2B,cAA3B;AAuBA;;;AAGG;;AACH,OAAO,MAAM,uBAAuB,GAAI,OAAD,IAAwE;;;EAC7G,MAAM,OAAO,GAAG,UAAU,EAA1B;;EAEA,IAAI,OAAJ,EAAa;IACX,QAAQ,CAAC,OAAD,CAAR;EACD;;EAED,OAAO,oBAAoB,CAAC;IAC1B,KAAK,EAAE;MACL,MAAM,EAAE,CAAC,EAAC,OAAO,KAAA,IAAP,IAAA,OAAO,KAAA,KAAA,CAAP,GAAO,KAAA,CAAP,GAAA,OAAO,CAAE,QAAV,CADJ;MAEL,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;MAGL,eAAe,EAAE,OAAO,KAAA,IAAP,IAAA,OAAO,KAAA,KAAA,CAAP,GAAO,KAAA,CAAP,GAAA,OAAO,CAAE,eAHrB;MAIL,QAAQ,EAAE,OAAO,KAAA,IAAP,IAAA,OAAO,KAAA,KAAA,CAAP,GAAO,KAAA,CAAP,GAAA,OAAO,CAAE;IAJd;EADmB,CAAD,CAA3B;AAQD,CAfM;;AAiBP,SAAS,oBAAT,CAA8B,IAA9B,EAA0E;EACxE,QAAQ,IAAR;IACE,KAAK,YAAL;MACE,OAAO,KAAK,CAAC,eAAN,CAAsB,UAA7B;;IACF,KAAK,MAAL;MACE,OAAO,KAAK,CAAC,eAAN,CAAsB,IAA7B;;IAEF,KAAK,UAAL;IACA;MACE,OAAO,KAAK,CAAC,eAAN,CAAsB,QAA7B;EARJ;AAUD","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';\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\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 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 tabbable: options?.tabbable,\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\n case 'vertical':\n default:\n return Types.MoverDirections.Vertical;\n }\n}\n"],"sourceRoot":"../src/"}
1
+ {"version":3,"sources":["hooks/useArrowNavigationGroup.ts"],"names":[],"mappings":"AAAA,SAAS,KAAT,EAAgB,QAAhB,QAAgC,SAAhC;AACA,SAAS,oBAAT,QAAqC,wBAArC;AACA,SAAS,UAAT,QAA2B,cAA3B;AA2BA;;;AAGG;;AACH,OAAO,MAAM,uBAAuB,GAAG,CAAC,OAAA,GAA0C,EAA3C,KAA4E;EACjH,MAAM;IAAE,QAAF;IAAY,IAAZ;IAAkB,eAAlB;IAAmC,QAAnC;IAA6C;EAA7C,IAAsE,OAA5E;EACA,MAAM,OAAO,GAAG,UAAU,EAA1B;;EAEA,IAAI,OAAJ,EAAa;IACX,QAAQ,CAAC,OAAD,CAAR;EACD;;EAED,OAAO,oBAAoB,CAAC;IAC1B,KAAK,EAAE;MACL,MAAM,EAAE,CAAC,CAAC,QADL;MAEL,SAAS,EAAE,oBAAoB,CAAC,IAAI,KAAA,IAAJ,IAAA,IAAI,KAAA,KAAA,CAAJ,GAAA,IAAA,GAAQ,UAAT,CAF1B;MAGL,eAAe,EAAE,eAHZ;MAIL,QAAQ,EAAE;IAJL,CADmB;IAO1B,IAAI,oBAAoB,IAAI;MAC1B,SAAS,EAAE;QACT,aAAa,EAAE;MADN;IADe,CAA5B;EAP0B,CAAD,CAA3B;AAaD,CArBM;;AAuBP,SAAS,oBAAT,CAA8B,IAA9B,EAA0E;EACxE,QAAQ,IAAR;IACE,KAAK,YAAL;MACE,OAAO,KAAK,CAAC,eAAN,CAAsB,UAA7B;;IACF,KAAK,MAAL;MACE,OAAO,KAAK,CAAC,eAAN,CAAsB,IAA7B;;IAEF,KAAK,UAAL;IACA;MACE,OAAO,KAAK,CAAC,eAAN,CAAsB,QAA7B;EARJ;AAUD","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';\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\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 { circular, axis, memorizeCurrent, tabbable, ignoreDefaultKeydown } = 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: memorizeCurrent,\n tabbable: tabbable,\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\n case 'vertical':\n default:\n return Types.MoverDirections.Vertical;\n }\n}\n"],"sourceRoot":"../src/"}
@@ -0,0 +1,16 @@
1
+ import * as React from 'react';
2
+ import { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';
3
+ import { applyFocusVisiblePolyfill } from '../focus/focusVisiblePolyfill';
4
+ export function useFocusVisible() {
5
+ const {
6
+ targetDocument
7
+ } = useFluent();
8
+ const scopeRef = React.useRef(null);
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
+ }, [scopeRef, targetDocument]);
14
+ return scopeRef;
15
+ }
16
+ //# sourceMappingURL=useFocusVisible.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["hooks/useFocusVisible.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,kBAAkB,IAAI,SAA/B,QAAgD,iCAAhD;AACA,SAAS,yBAAT,QAA0C,+BAA1C;AAEA,OAAM,SAAU,eAAV,GAAyB;EAC7B,MAAM;IAAE;EAAF,IAAqB,SAAS,EAApC;EACA,MAAM,QAAQ,GAAG,KAAK,CAAC,MAAN,CAAuB,IAAvB,CAAjB;EAEA,KAAK,CAAC,SAAN,CAAgB,MAAK;IACnB,IAAI,CAAA,cAAc,KAAA,IAAd,IAAA,cAAc,KAAA,KAAA,CAAd,GAAc,KAAA,CAAd,GAAA,cAAc,CAAE,WAAhB,KAA+B,QAAQ,CAAC,OAA5C,EAAqD;MACnD,OAAO,yBAAyB,CAAC,QAAQ,CAAC,OAAV,EAAmB,cAAc,CAAC,WAAlC,CAAhC;IACD;EACF,CAJD,EAIG,CAAC,QAAD,EAAW,cAAX,CAJH;EAMA,OAAO,QAAP;AACD","sourcesContent":["import * as React from 'react';\nimport { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\nimport { applyFocusVisiblePolyfill } from '../focus/focusVisiblePolyfill';\n\nexport function useFocusVisible<TElement extends HTMLElement = HTMLElement>() {\n const { targetDocument } = useFluent();\n const scopeRef = React.useRef<TElement>(null);\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"],"sourceRoot":"../src/"}
@@ -0,0 +1,22 @@
1
+ import * as React from 'react';
2
+ import { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';
3
+ import { applyFocusWithinPolyfill } from '../focus/focusWithinPolyfill';
4
+ /**
5
+ * A ponyfill that allows `:focus-within` to support visibility based on keyboard/mouse navigation
6
+ * like `:focus-visible` https://github.com/WICG/focus-visible/issues/151
7
+ * @returns ref to the element that uses `:focus-within` styles
8
+ */
9
+
10
+ export function useFocusWithin() {
11
+ const {
12
+ targetDocument
13
+ } = useFluent();
14
+ const elementRef = React.useRef(null);
15
+ React.useEffect(() => {
16
+ if ((targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.defaultView) && elementRef.current) {
17
+ return applyFocusWithinPolyfill(elementRef.current, targetDocument.defaultView);
18
+ }
19
+ }, [elementRef, targetDocument]);
20
+ return elementRef;
21
+ }
22
+ //# sourceMappingURL=useFocusWithin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["hooks/useFocusWithin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,kBAAkB,IAAI,SAA/B,QAAgD,iCAAhD;AACA,SAAS,wBAAT,QAAyC,8BAAzC;AAEA;;;;AAIG;;AACH,OAAM,SAAU,cAAV,GAAwB;EAC5B,MAAM;IAAE;EAAF,IAAqB,SAAS,EAApC;EACA,MAAM,UAAU,GAAG,KAAK,CAAC,MAAN,CAAuB,IAAvB,CAAnB;EAEA,KAAK,CAAC,SAAN,CAAgB,MAAK;IACnB,IAAI,CAAA,cAAc,KAAA,IAAd,IAAA,cAAc,KAAA,KAAA,CAAd,GAAc,KAAA,CAAd,GAAA,cAAc,CAAE,WAAhB,KAA+B,UAAU,CAAC,OAA9C,EAAuD;MACrD,OAAO,wBAAwB,CAAC,UAAU,CAAC,OAAZ,EAAqB,cAAc,CAAC,WAApC,CAA/B;IACD;EACF,CAJD,EAIG,CAAC,UAAD,EAAa,cAAb,CAJH;EAMA,OAAO,UAAP;AACD","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"],"sourceRoot":"../src/"}
@@ -1,5 +1,7 @@
1
+ import * as React from 'react';
1
2
  import { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';
2
- import { getCurrentTabster, createTabster } from 'tabster';
3
+ import { createTabster, disposeTabster } from 'tabster';
4
+ import { useIsomorphicLayoutEffect } from '@fluentui/react-utilities';
3
5
  /**
4
6
  * Tries to get a tabster instance on the current window or creates a new one
5
7
  * Since Tabster is single instance only, feel free to call this hook to ensure Tabster exists if necessary
@@ -9,22 +11,27 @@ import { getCurrentTabster, createTabster } from 'tabster';
9
11
  */
10
12
 
11
13
  export const useTabster = () => {
12
- var _a;
13
-
14
14
  const {
15
15
  targetDocument
16
16
  } = useFluent();
17
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
-
18
+ const tabster = React.useMemo(() => {
19
+ if (!defaultView) {
20
+ return null;
21
+ }
27
22
 
28
- return (_a = getCurrentTabster(defaultView)) !== null && _a !== void 0 ? _a : createTabster(defaultView, tabsterOptions);
23
+ return createTabster(defaultView, {
24
+ autoRoot: {},
25
+ controlTab: false
26
+ });
27
+ }, [defaultView]);
28
+ useIsomorphicLayoutEffect(() => {
29
+ return () => {
30
+ if (tabster) {
31
+ disposeTabster(tabster);
32
+ }
33
+ };
34
+ }, [tabster]);
35
+ return tabster;
29
36
  };
30
37
  //# sourceMappingURL=useTabster.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["hooks/useTabster.ts"],"names":[],"mappings":"AAAA,SAAS,kBAAkB,IAAI,SAA/B,QAAgD,iCAAhD;AACA,SAAS,iBAAT,EAA4B,aAA5B,QAAwE,SAAxE;AAEA;;;;;;AAMG;;AACH,OAAO,MAAM,UAAU,GAAG,MAAsC;;;EAC9D,MAAM;IAAE;EAAF,IAAqB,SAAS,EAApC;EAEA,MAAM,WAAW,GAAG,CAAA,cAAc,KAAA,IAAd,IAAA,cAAc,KAAA,KAAA,CAAd,GAAc,KAAA,CAAd,GAAA,cAAc,CAAE,WAAhB,KAA+B,SAAnD;EACA,MAAM,cAAc,GAAkC;IAAE,QAAQ,EAAE,EAAZ;IAAgB,UAAU,EAAE;EAA5B,CAAtD;;EAEA,IAAI,CAAC,WAAL,EAAkB;IAChB,OAAO,IAAP;EACD,CAR6D,CAU9D;;;EACA,OAAO,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_unstable as 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/"}
1
+ {"version":3,"sources":["hooks/useTabster.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,kBAAkB,IAAI,SAA/B,QAAgD,iCAAhD;AACA,SAAS,aAAT,EAAwB,cAAxB,QAAqE,SAArE;AACA,SAAS,yBAAT,QAA0C,2BAA1C;AAEA;;;;;;AAMG;;AACH,OAAO,MAAM,UAAU,GAAG,MAAsC;EAC9D,MAAM;IAAE;EAAF,IAAqB,SAAS,EAApC;EAEA,MAAM,WAAW,GAAG,CAAA,cAAc,KAAA,IAAd,IAAA,cAAc,KAAA,KAAA,CAAd,GAAc,KAAA,CAAd,GAAA,cAAc,CAAE,WAAhB,KAA+B,SAAnD;EACA,MAAM,OAAO,GAAG,KAAK,CAAC,OAAN,CAAc,MAAK;IACjC,IAAI,CAAC,WAAL,EAAkB;MAChB,OAAO,IAAP;IACD;;IAED,OAAO,aAAa,CAAC,WAAD,EAAc;MAAE,QAAQ,EAAE,EAAZ;MAAgB,UAAU,EAAE;IAA5B,CAAd,CAApB;EACD,CANe,EAMb,CAAC,WAAD,CANa,CAAhB;EAQA,yBAAyB,CAAC,MAAK;IAC7B,OAAO,MAAK;MACV,IAAI,OAAJ,EAAa;QACX,cAAc,CAAC,OAAD,CAAd;MACD;IACF,CAJD;EAKD,CANwB,EAMtB,CAAC,OAAD,CANsB,CAAzB;EAQA,OAAO,OAAP;AACD,CArBM","sourcesContent":["import * as React from 'react';\nimport { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\nimport { createTabster, disposeTabster, Types as TabsterTypes } from 'tabster';\nimport { useIsomorphicLayoutEffect } from '@fluentui/react-utilities';\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 tabster = React.useMemo(() => {\n if (!defaultView) {\n return null;\n }\n\n return createTabster(defaultView, { autoRoot: {}, controlTab: false });\n }, [defaultView]);\n\n useIsomorphicLayoutEffect(() => {\n return () => {\n if (tabster) {\n disposeTabster(tabster);\n }\n };\n }, [tabster]);\n\n return tabster;\n};\n"],"sourceRoot":"../src/"}
package/lib/index.js CHANGED
@@ -1,3 +1,3 @@
1
- export { useArrowNavigationGroup, useFocusableGroup, useFocusFinders, useKeyboardNavAttribute, useModalAttributes, useTabsterAttributes } from './hooks/index';
1
+ export { useArrowNavigationGroup, useFocusableGroup, useFocusFinders, useFocusVisible, useFocusWithin, useKeyboardNavAttribute, useModalAttributes, useTabsterAttributes } from './hooks/index';
2
2
  export { createCustomFocusIndicatorStyle, createFocusOutlineStyle } from './focus/index';
3
3
  //# sourceMappingURL=index.js.map
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["index.ts"],"names":[],"mappings":"AAAA,SACE,uBADF,EAEE,iBAFF,EAGE,eAHF,EAIE,uBAJF,EAKE,kBALF,EAME,oBANF,QAOO,eAPP;AAcA,SAAS,+BAAT,EAA0C,uBAA1C,QAAyE,eAAzE","sourcesContent":["export {\n useArrowNavigationGroup,\n useFocusableGroup,\n useFocusFinders,\n useKeyboardNavAttribute,\n useModalAttributes,\n useTabsterAttributes,\n} from './hooks/index';\nexport type {\n UseArrowNavigationGroupOptions,\n UseFocusableGroupOptions,\n UseModalAttributesOptions,\n} from './hooks/index';\n\nexport { createCustomFocusIndicatorStyle, createFocusOutlineStyle } from './focus/index';\n\nexport type {\n CreateCustomFocusIndicatorStyleOptions,\n CreateFocusOutlineStyleOptions,\n FocusOutlineOffset,\n FocusOutlineStyleOptions,\n} from './focus/index';\n"],"sourceRoot":"../src/"}
1
+ {"version":3,"sources":["index.ts"],"names":[],"mappings":"AAAA,SACE,uBADF,EAEE,iBAFF,EAGE,eAHF,EAIE,eAJF,EAKE,cALF,EAME,uBANF,EAOE,kBAPF,EAQE,oBARF,QASO,eATP;AAgBA,SAAS,+BAAT,EAA0C,uBAA1C,QAAyE,eAAzE","sourcesContent":["export {\n useArrowNavigationGroup,\n useFocusableGroup,\n useFocusFinders,\n useFocusVisible,\n useFocusWithin,\n useKeyboardNavAttribute,\n useModalAttributes,\n useTabsterAttributes,\n} from './hooks/index';\nexport type {\n UseArrowNavigationGroupOptions,\n UseFocusableGroupOptions,\n UseModalAttributesOptions,\n} from './hooks/index';\n\nexport { createCustomFocusIndicatorStyle, createFocusOutlineStyle } from './focus/index';\n\nexport type {\n CreateCustomFocusIndicatorStyleOptions,\n CreateFocusOutlineStyleOptions,\n FocusOutlineOffset,\n FocusOutlineStyleOptions,\n} from './focus/index';\n"],"sourceRoot":"../src/"}
@@ -3,9 +3,11 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.defaultOptions = exports.KEYBOARD_NAV_SELECTOR = exports.KEYBOARD_NAV_ATTRIBUTE = void 0;
6
+ exports.defaultOptions = exports.FOCUS_WITHIN_CLASS = exports.FOCUS_VISIBLE_CLASS = exports.KEYBOARD_NAV_SELECTOR = exports.KEYBOARD_NAV_ATTRIBUTE = void 0;
7
7
  exports.KEYBOARD_NAV_ATTRIBUTE = 'data-keyboard-nav';
8
8
  exports.KEYBOARD_NAV_SELECTOR = `:global([${exports.KEYBOARD_NAV_ATTRIBUTE}])`;
9
+ exports.FOCUS_VISIBLE_CLASS = 'fui-focus-visible';
10
+ exports.FOCUS_WITHIN_CLASS = 'fui-focus-within';
9
11
  exports.defaultOptions = {
10
12
  style: {},
11
13
  selector: 'focus'
@@ -1 +1 @@
1
- {"version":3,"sources":["focus/constants.ts"],"names":[],"mappings":";;;;;;AAAa,OAAA,CAAA,sBAAA,GAAyB,mBAAzB;AACA,OAAA,CAAA,qBAAA,GAAwB,YAAY,OAAA,CAAA,sBAAsB,IAA1D;AACA,OAAA,CAAA,cAAA,GAAiB;EAC5B,KAAK,EAAE,EADqB;EAE5B,QAAQ,EAAE;AAFkB,CAAjB","sourcesContent":["export const KEYBOARD_NAV_ATTRIBUTE = 'data-keyboard-nav' as const;\nexport const KEYBOARD_NAV_SELECTOR = `:global([${KEYBOARD_NAV_ATTRIBUTE}])` as const;\nexport const defaultOptions = {\n style: {},\n selector: 'focus',\n} as const;\n"],"sourceRoot":"../src/"}
1
+ {"version":3,"sources":["focus/constants.ts"],"names":[],"mappings":";;;;;;AAAa,OAAA,CAAA,sBAAA,GAAyB,mBAAzB;AACA,OAAA,CAAA,qBAAA,GAAwB,YAAY,OAAA,CAAA,sBAAsB,IAA1D;AACA,OAAA,CAAA,mBAAA,GAAsB,mBAAtB;AACA,OAAA,CAAA,kBAAA,GAAqB,kBAArB;AACA,OAAA,CAAA,cAAA,GAAiB;EAC5B,KAAK,EAAE,EADqB;EAE5B,QAAQ,EAAE;AAFkB,CAAjB","sourcesContent":["export const KEYBOARD_NAV_ATTRIBUTE = 'data-keyboard-nav' as const;\nexport const KEYBOARD_NAV_SELECTOR = `:global([${KEYBOARD_NAV_ATTRIBUTE}])` as const;\nexport const FOCUS_VISIBLE_CLASS = 'fui-focus-visible';\nexport const FOCUS_WITHIN_CLASS = 'fui-focus-within';\nexport const defaultOptions = {\n style: {},\n selector: 'focus',\n} as const;\n"],"sourceRoot":"../src/"}
@@ -21,7 +21,21 @@ const createCustomFocusIndicatorStyle = (style, {
21
21
  ':focus': {
22
22
  outlineStyle: 'none'
23
23
  },
24
- [`${constants_1.KEYBOARD_NAV_SELECTOR} :${selector}`]: style
24
+ ':focus-visible': {
25
+ outlineStyle: 'none'
26
+ },
27
+ // Remove the `.fui-FluentProvider` global selector once Griffel supports chained global styles
28
+ // https://github.com/microsoft/griffel/issues/178
29
+ ...(selector === 'focus' && {
30
+ [`:global(.fui-FluentProvider)`]: {
31
+ [`& .${constants_1.FOCUS_VISIBLE_CLASS}`]: style
32
+ }
33
+ }),
34
+ ...(selector === 'focus-within' && {
35
+ [`:global(.fui-FluentProvider)`]: {
36
+ [`& .${constants_1.FOCUS_WITHIN_CLASS}:${selector}`]: style
37
+ }
38
+ })
25
39
  });
26
40
 
27
41
  exports.createCustomFocusIndicatorStyle = createCustomFocusIndicatorStyle;
@@ -1 +1 @@
1
- {"version":3,"sources":["focus/createCustomFocusIndicatorStyle.ts"],"names":[],"mappings":";;;;;;;AAAA,MAAA,WAAA,gBAAA,OAAA,CAAA,aAAA,CAAA;AAOA;;;;;;AAMG;;;AACI,MAAM,+BAA+B,GAAG,CAC7C,KAD6C,EAE7C;EAAE,QAAQ,GAAG,WAAA,CAAA,cAAA,CAAe;AAA5B,IAAiF,WAAA,CAAA,cAFpC,MAG3B;EAClB,UAAU;IACR,YAAY,EAAE;EADN,CADQ;EAIlB,CAAC,GAAG,WAAA,CAAA,qBAAqB,KAAK,QAAQ,EAAtC,GAA2C;AAJzB,CAH2B,CAAxC;;AAAM,OAAA,CAAA,+BAAA,GAA+B,+BAA/B","sourcesContent":["import { KEYBOARD_NAV_SELECTOR, defaultOptions } from './constants';\nimport type { GriffelStyle } from '@griffel/react';\n\nexport interface CreateCustomFocusIndicatorStyleOptions {\n selector?: 'focus' | 'focus-within';\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 * @param options - Configure the style of the focus outline\n */\nexport const createCustomFocusIndicatorStyle = (\n style: GriffelStyle,\n { selector = defaultOptions.selector }: CreateCustomFocusIndicatorStyleOptions = defaultOptions,\n): GriffelStyle => ({\n ':focus': {\n outlineStyle: 'none',\n },\n [`${KEYBOARD_NAV_SELECTOR} :${selector}`]: style,\n});\n"],"sourceRoot":"../src/"}
1
+ {"version":3,"sources":["focus/createCustomFocusIndicatorStyle.ts"],"names":[],"mappings":";;;;;;;AAAA,MAAA,WAAA,gBAAA,OAAA,CAAA,aAAA,CAAA;AAOA;;;;;;AAMG;;;AACI,MAAM,+BAA+B,GAAG,CAC7C,KAD6C,EAE7C;EAAE,QAAQ,GAAG,WAAA,CAAA,cAAA,CAAe;AAA5B,IAAiF,WAAA,CAAA,cAFpC,MAG3B;EAClB,UAAU;IACR,YAAY,EAAE;EADN,CADQ;EAIlB,kBAAkB;IAChB,YAAY,EAAE;EADE,CAJA;EAOlB;EACA;EACA,IAAI,QAAQ,KAAK,OAAb,IAAwB;IAC1B,CAAC,8BAAD,GAAkC;MAChC,CAAC,MAAM,WAAA,CAAA,mBAAmB,EAA1B,GAA+B;IADC;EADR,CAA5B,CATkB;EAclB,IAAI,QAAQ,KAAK,cAAb,IAA+B;IACjC,CAAC,8BAAD,GAAkC;MAChC,CAAC,MAAM,WAAA,CAAA,kBAAkB,IAAI,QAAQ,EAArC,GAA0C;IADV;EADD,CAAnC;AAdkB,CAH2B,CAAxC;;AAAM,OAAA,CAAA,+BAAA,GAA+B,+BAA/B","sourcesContent":["import { FOCUS_VISIBLE_CLASS, defaultOptions, FOCUS_WITHIN_CLASS } from './constants';\nimport type { GriffelStyle } from '@griffel/react';\n\nexport interface CreateCustomFocusIndicatorStyleOptions {\n selector?: 'focus' | 'focus-within';\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 * @param options - Configure the style of the focus outline\n */\nexport const createCustomFocusIndicatorStyle = (\n style: GriffelStyle,\n { selector = defaultOptions.selector }: CreateCustomFocusIndicatorStyleOptions = defaultOptions,\n): GriffelStyle => ({\n ':focus': {\n outlineStyle: 'none',\n },\n ':focus-visible': {\n outlineStyle: 'none',\n },\n // Remove the `.fui-FluentProvider` global selector once Griffel supports chained global styles\n // https://github.com/microsoft/griffel/issues/178\n ...(selector === 'focus' && {\n [`:global(.fui-FluentProvider)`]: {\n [`& .${FOCUS_VISIBLE_CLASS}`]: style,\n },\n }),\n ...(selector === 'focus-within' && {\n [`:global(.fui-FluentProvider)`]: {\n [`& .${FOCUS_WITHIN_CLASS}:${selector}`]: style,\n },\n }),\n});\n"],"sourceRoot":"../src/"}
@@ -0,0 +1,95 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.applyFocusVisiblePolyfill = void 0;
7
+
8
+ const keyborg_1 = /*#__PURE__*/require("keyborg");
9
+
10
+ const constants_1 = /*#__PURE__*/require("./constants");
11
+
12
+ function applyFocusVisiblePolyfill(scope, win) {
13
+ if (alreadyInScope(scope)) {
14
+ // Focus visible polyfill already applied at this scope
15
+ return () => undefined;
16
+ }
17
+
18
+ const state = {
19
+ current: undefined
20
+ };
21
+ const keyborg = keyborg_1.createKeyborg(win); // When navigation mode changes remove the focus-visible selector
22
+
23
+ keyborg.subscribe(isNavigatingWithKeyboard => {
24
+ if (!isNavigatingWithKeyboard && state.current) {
25
+ removeFocusVisibleClass(state.current);
26
+ state.current = undefined;
27
+ }
28
+ }); // Keyborg's focusin event is delegated so it's only registered once on the window
29
+ // and contains metadata about the focus event
30
+
31
+ const keyborgListener = e => {
32
+ if (state.current) {
33
+ removeFocusVisibleClass(state.current);
34
+ state.current = undefined;
35
+ }
36
+
37
+ if (keyborg.isNavigatingWithKeyboard() && isHTMLElement(e.target) && e.target) {
38
+ // Griffel can't create chained global styles so use the parent element for now
39
+ state.current = e.target;
40
+ applyFocusVisibleClass(state.current);
41
+ }
42
+ }; // Make sure that when focus leaves the scope, the focus visible class is removed
43
+
44
+
45
+ const blurListener = e => {
46
+ if (!e.relatedTarget || isHTMLElement(e.relatedTarget) && !scope.contains(e.relatedTarget)) {
47
+ if (state.current) {
48
+ removeFocusVisibleClass(state.current);
49
+ state.current = undefined;
50
+ }
51
+ }
52
+ };
53
+
54
+ scope.addEventListener(keyborg_1.KEYBORG_FOCUSIN, keyborgListener);
55
+ scope.addEventListener('focusout', blurListener);
56
+ scope.focusVisible = true; // Return disposer
57
+
58
+ return () => {
59
+ scope.removeEventListener(keyborg_1.KEYBORG_FOCUSIN, keyborgListener);
60
+ scope.removeEventListener('focusout', blurListener);
61
+ delete scope.focusVisible;
62
+ keyborg_1.disposeKeyborg(keyborg);
63
+ };
64
+ }
65
+
66
+ exports.applyFocusVisiblePolyfill = applyFocusVisiblePolyfill;
67
+
68
+ function applyFocusVisibleClass(el) {
69
+ el.classList.add(constants_1.FOCUS_VISIBLE_CLASS);
70
+ }
71
+
72
+ function removeFocusVisibleClass(el) {
73
+ el.classList.remove(constants_1.FOCUS_VISIBLE_CLASS);
74
+ }
75
+
76
+ function isHTMLElement(target) {
77
+ if (!target) {
78
+ return false;
79
+ }
80
+
81
+ return Boolean(target && typeof target === 'object' && 'classList' in target && 'contains' in target);
82
+ }
83
+
84
+ function alreadyInScope(el) {
85
+ if (!el) {
86
+ return false;
87
+ }
88
+
89
+ if (el.focusVisible) {
90
+ return true;
91
+ }
92
+
93
+ return alreadyInScope(el === null || el === void 0 ? void 0 : el.parentElement);
94
+ }
95
+ //# sourceMappingURL=focusVisiblePolyfill.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["focus/focusVisiblePolyfill.ts"],"names":[],"mappings":"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","sourcesContent":["import { KEYBORG_FOCUSIN, KeyborgFocusInEvent, createKeyborg, disposeKeyborg } from 'keyborg';\nimport { FOCUS_VISIBLE_CLASS } from './constants';\n\n/**\n * Because `addEventListener` type override falls back to 2nd definition (evt name is unknown string literal)\n * evt is being typed as a base class of MouseEvent -> `Event`.\n * This type is used to override `listener` calls to make TS happy\n */\ntype ListenerOverride = (evt: Event) => void;\n\ntype FocusVisibleState = {\n /**\n * Current element with focus visible in state\n */\n current: HTMLElement | undefined;\n};\n\ntype HTMLElementWithFocusVisibleScope = {\n focusVisible: boolean | undefined;\n} & HTMLElement;\n\nexport function applyFocusVisiblePolyfill(scope: HTMLElement, win: Window): () => void {\n if (alreadyInScope(scope)) {\n // Focus visible polyfill already applied at this scope\n return () => undefined;\n }\n\n const state: FocusVisibleState = {\n current: undefined,\n };\n\n const keyborg = createKeyborg(win);\n\n // When navigation mode changes remove the focus-visible selector\n keyborg.subscribe(isNavigatingWithKeyboard => {\n if (!isNavigatingWithKeyboard && state.current) {\n removeFocusVisibleClass(state.current);\n state.current = undefined;\n }\n });\n\n // Keyborg's focusin event is delegated so it's only registered once on the window\n // and contains metadata about the focus event\n const keyborgListener = (e: KeyborgFocusInEvent) => {\n if (state.current) {\n removeFocusVisibleClass(state.current);\n state.current = undefined;\n }\n\n if (keyborg.isNavigatingWithKeyboard() && isHTMLElement(e.target) && e.target) {\n // Griffel can't create chained global styles so use the parent element for now\n state.current = e.target;\n applyFocusVisibleClass(state.current);\n }\n };\n\n // Make sure that when focus leaves the scope, the focus visible class is removed\n const blurListener = (e: FocusEvent) => {\n if (!e.relatedTarget || (isHTMLElement(e.relatedTarget) && !scope.contains(e.relatedTarget))) {\n if (state.current) {\n removeFocusVisibleClass(state.current);\n state.current = undefined;\n }\n }\n };\n\n scope.addEventListener(KEYBORG_FOCUSIN, keyborgListener as ListenerOverride);\n scope.addEventListener('focusout', blurListener);\n (scope as HTMLElementWithFocusVisibleScope).focusVisible = true;\n\n // Return disposer\n return () => {\n scope.removeEventListener(KEYBORG_FOCUSIN, keyborgListener as ListenerOverride);\n scope.removeEventListener('focusout', blurListener);\n delete (scope as HTMLElementWithFocusVisibleScope).focusVisible;\n disposeKeyborg(keyborg);\n };\n}\n\nfunction applyFocusVisibleClass(el: HTMLElement) {\n el.classList.add(FOCUS_VISIBLE_CLASS);\n}\n\nfunction removeFocusVisibleClass(el: HTMLElement) {\n el.classList.remove(FOCUS_VISIBLE_CLASS);\n}\n\nfunction isHTMLElement(target: EventTarget | null): target is HTMLElement {\n if (!target) {\n return false;\n }\n return Boolean(target && typeof target === 'object' && 'classList' in target && 'contains' in target);\n}\n\nfunction alreadyInScope(el: HTMLElement | null | undefined): boolean {\n if (!el) {\n return false;\n }\n\n if ((el as HTMLElementWithFocusVisibleScope).focusVisible) {\n return true;\n }\n\n return alreadyInScope(el?.parentElement);\n}\n"],"sourceRoot":"../src/"}
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.applyFocusWithinPolyfill = void 0;
7
+
8
+ const keyborg_1 = /*#__PURE__*/require("keyborg");
9
+
10
+ const constants_1 = /*#__PURE__*/require("./constants");
11
+ /**
12
+ * A ponyfill that allows `:focus-within` to support visibility based on keyboard/mouse navigation
13
+ * like `:focus-visible` https://github.com/WICG/focus-visible/issues/151
14
+ * @returns ref to the element that uses `:focus-within` styles
15
+ */
16
+
17
+
18
+ function applyFocusWithinPolyfill(element, win) {
19
+ const keyborg = keyborg_1.createKeyborg(win); // When navigation mode changes to mouse, remove the focus-within selector
20
+
21
+ keyborg.subscribe(isNavigatingWithKeyboard => {
22
+ if (!isNavigatingWithKeyboard) {
23
+ removeFocusWithinClass(element);
24
+ }
25
+ }); // Keyborg's focusin event is delegated so it's only registered once on the window
26
+ // and contains metadata about the focus event
27
+
28
+ const keyborgListener = e => {
29
+ if (keyborg.isNavigatingWithKeyboard() && isHTMLElement(e.target)) {
30
+ // Griffel can't create chained global styles so use the parent element for now
31
+ applyFocusWithinClass(element);
32
+ }
33
+ }; // Make sure that when focus leaves the scope, the focus within class is removed
34
+
35
+
36
+ const blurListener = e => {
37
+ if (!e.relatedTarget || isHTMLElement(e.relatedTarget) && !element.contains(e.relatedTarget)) {
38
+ removeFocusWithinClass(element);
39
+ }
40
+ };
41
+
42
+ element.addEventListener(keyborg_1.KEYBORG_FOCUSIN, keyborgListener);
43
+ element.addEventListener('focusout', blurListener); // Return disposer
44
+
45
+ return () => {
46
+ element.removeEventListener(keyborg_1.KEYBORG_FOCUSIN, keyborgListener);
47
+ element.removeEventListener('focusout', blurListener);
48
+ keyborg_1.disposeKeyborg(keyborg);
49
+ };
50
+ }
51
+
52
+ exports.applyFocusWithinPolyfill = applyFocusWithinPolyfill;
53
+
54
+ function applyFocusWithinClass(el) {
55
+ el.classList.add(constants_1.FOCUS_WITHIN_CLASS);
56
+ }
57
+
58
+ function removeFocusWithinClass(el) {
59
+ el.classList.remove(constants_1.FOCUS_WITHIN_CLASS);
60
+ }
61
+
62
+ function isHTMLElement(target) {
63
+ if (!target) {
64
+ return false;
65
+ }
66
+
67
+ return Boolean(target && typeof target === 'object' && 'classList' in target && 'contains' in target);
68
+ }
69
+ //# sourceMappingURL=focusWithinPolyfill.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["focus/focusWithinPolyfill.ts"],"names":[],"mappings":";;;;;;;AAAA,MAAA,SAAA,gBAAA,OAAA,CAAA,SAAA,CAAA;;AACA,MAAA,WAAA,gBAAA,OAAA,CAAA,aAAA,CAAA;AASA;;;;AAIG;;;AACH,SAAgB,wBAAhB,CAAyC,OAAzC,EAA+D,GAA/D,EAA0E;EACxE,MAAM,OAAO,GAAG,SAAA,CAAA,aAAA,CAAc,GAAd,CAAhB,CADwE,CAGxE;;EACA,OAAO,CAAC,SAAR,CAAkB,wBAAwB,IAAG;IAC3C,IAAI,CAAC,wBAAL,EAA+B;MAC7B,sBAAsB,CAAC,OAAD,CAAtB;IACD;EACF,CAJD,EAJwE,CAUxE;EACA;;EACA,MAAM,eAAe,GAAI,CAAD,IAA2B;IACjD,IAAI,OAAO,CAAC,wBAAR,MAAsC,aAAa,CAAC,CAAC,CAAC,MAAH,CAAvD,EAAmE;MACjE;MACA,qBAAqB,CAAC,OAAD,CAArB;IACD;EACF,CALD,CAZwE,CAmBxE;;;EACA,MAAM,YAAY,GAAI,CAAD,IAAkB;IACrC,IAAI,CAAC,CAAC,CAAC,aAAH,IAAqB,aAAa,CAAC,CAAC,CAAC,aAAH,CAAb,IAAkC,CAAC,OAAO,CAAC,QAAR,CAAiB,CAAC,CAAC,aAAnB,CAA5D,EAAgG;MAC9F,sBAAsB,CAAC,OAAD,CAAtB;IACD;EACF,CAJD;;EAMA,OAAO,CAAC,gBAAR,CAAyB,SAAA,CAAA,eAAzB,EAA0C,eAA1C;EACA,OAAO,CAAC,gBAAR,CAAyB,UAAzB,EAAqC,YAArC,EA3BwE,CA6BxE;;EACA,OAAO,MAAK;IACV,OAAO,CAAC,mBAAR,CAA4B,SAAA,CAAA,eAA5B,EAA6C,eAA7C;IACA,OAAO,CAAC,mBAAR,CAA4B,UAA5B,EAAwC,YAAxC;IACA,SAAA,CAAA,cAAA,CAAe,OAAf;EACD,CAJD;AAKD;;AAnCD,OAAA,CAAA,wBAAA,GAAA,wBAAA;;AAqCA,SAAS,qBAAT,CAA+B,EAA/B,EAA8C;EAC5C,EAAE,CAAC,SAAH,CAAa,GAAb,CAAiB,WAAA,CAAA,kBAAjB;AACD;;AAED,SAAS,sBAAT,CAAgC,EAAhC,EAA+C;EAC7C,EAAE,CAAC,SAAH,CAAa,MAAb,CAAoB,WAAA,CAAA,kBAApB;AACD;;AAED,SAAS,aAAT,CAAuB,MAAvB,EAAiD;EAC/C,IAAI,CAAC,MAAL,EAAa;IACX,OAAO,KAAP;EACD;;EACD,OAAO,OAAO,CAAC,MAAM,IAAI,OAAO,MAAP,KAAkB,QAA5B,IAAwC,eAAe,MAAvD,IAAiE,cAAc,MAAhF,CAAd;AACD","sourcesContent":["import { KEYBORG_FOCUSIN, KeyborgFocusInEvent, createKeyborg, disposeKeyborg } from 'keyborg';\nimport { FOCUS_WITHIN_CLASS } from './constants';\n\n/**\n * Because `addEventListener` type override falls back to 2nd definition (evt name is unknown string literal)\n * evt is being typed as a base class of MouseEvent -> `Event`.\n * This type is used to override `listener` calls to make TS happy\n */\ntype ListenerOverride = (evt: Event) => void;\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 applyFocusWithinPolyfill(element: HTMLElement, win: Window): () => void {\n const keyborg = createKeyborg(win);\n\n // When navigation mode changes to mouse, remove the focus-within selector\n keyborg.subscribe(isNavigatingWithKeyboard => {\n if (!isNavigatingWithKeyboard) {\n removeFocusWithinClass(element);\n }\n });\n\n // Keyborg's focusin event is delegated so it's only registered once on the window\n // and contains metadata about the focus event\n const keyborgListener = (e: KeyborgFocusInEvent) => {\n if (keyborg.isNavigatingWithKeyboard() && isHTMLElement(e.target)) {\n // Griffel can't create chained global styles so use the parent element for now\n applyFocusWithinClass(element);\n }\n };\n\n // Make sure that when focus leaves the scope, the focus within class is removed\n const blurListener = (e: FocusEvent) => {\n if (!e.relatedTarget || (isHTMLElement(e.relatedTarget) && !element.contains(e.relatedTarget))) {\n removeFocusWithinClass(element);\n }\n };\n\n element.addEventListener(KEYBORG_FOCUSIN, keyborgListener as ListenerOverride);\n element.addEventListener('focusout', blurListener);\n\n // Return disposer\n return () => {\n element.removeEventListener(KEYBORG_FOCUSIN, keyborgListener as ListenerOverride);\n element.removeEventListener('focusout', blurListener);\n disposeKeyborg(keyborg);\n };\n}\n\nfunction applyFocusWithinClass(el: HTMLElement) {\n el.classList.add(FOCUS_WITHIN_CLASS);\n}\n\nfunction removeFocusWithinClass(el: HTMLElement) {\n el.classList.remove(FOCUS_WITHIN_CLASS);\n}\n\nfunction isHTMLElement(target: EventTarget | null): target is HTMLElement {\n if (!target) {\n return false;\n }\n return Boolean(target && typeof target === 'object' && 'classList' in target && 'contains' in target);\n}\n"],"sourceRoot":"../src/"}
@@ -12,6 +12,10 @@ tslib_1.__exportStar(require("./useFocusableGroup"), exports);
12
12
 
13
13
  tslib_1.__exportStar(require("./useFocusFinders"), exports);
14
14
 
15
+ tslib_1.__exportStar(require("./useFocusVisible"), exports);
16
+
17
+ tslib_1.__exportStar(require("./useFocusWithin"), exports);
18
+
15
19
  tslib_1.__exportStar(require("./useKeyboardNavAttribute"), exports);
16
20
 
17
21
  tslib_1.__exportStar(require("./useModalAttributes"), exports);
@@ -1 +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,qBAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,mBAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,2BAAA,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","sourcesContent":["export * from './useArrowNavigationGroup';\nexport * from './useFocusableGroup';\nexport * from './useFocusFinders';\nexport * from './useKeyboardNavAttribute';\nexport * from './useModalAttributes';\nexport * from './useTabsterAttributes';\n"],"sourceRoot":"../src/"}
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,qBAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,mBAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,mBAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,kBAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,2BAAA,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","sourcesContent":["export * from './useArrowNavigationGroup';\nexport * from './useFocusableGroup';\nexport * from './useFocusFinders';\nexport * from './useFocusVisible';\nexport * from './useFocusWithin';\nexport * from './useKeyboardNavAttribute';\nexport * from './useModalAttributes';\nexport * from './useTabsterAttributes';\n"],"sourceRoot":"../src/"}
@@ -16,9 +16,14 @@ const useTabster_1 = /*#__PURE__*/require("./useTabster");
16
16
  */
17
17
 
18
18
 
19
- const useArrowNavigationGroup = options => {
20
- var _a;
21
-
19
+ const useArrowNavigationGroup = (options = {}) => {
20
+ const {
21
+ circular,
22
+ axis,
23
+ memorizeCurrent,
24
+ tabbable,
25
+ ignoreDefaultKeydown
26
+ } = options;
22
27
  const tabster = useTabster_1.useTabster();
23
28
 
24
29
  if (tabster) {
@@ -27,11 +32,16 @@ const useArrowNavigationGroup = options => {
27
32
 
28
33
  return useTabsterAttributes_1.useTabsterAttributes({
29
34
  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
- tabbable: options === null || options === void 0 ? void 0 : options.tabbable
34
- }
35
+ cyclic: !!circular,
36
+ direction: axisToMoverDirection(axis !== null && axis !== void 0 ? axis : 'vertical'),
37
+ memorizeCurrent: memorizeCurrent,
38
+ tabbable: tabbable
39
+ },
40
+ ...(ignoreDefaultKeydown && {
41
+ focusable: {
42
+ ignoreKeydown: ignoreDefaultKeydown
43
+ }
44
+ })
35
45
  });
36
46
  };
37
47
 
@@ -1 +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;AAuBA;;;AAGG;;;AACI,MAAM,uBAAuB,GAAI,OAAD,IAAwE;;;EAC7G,MAAM,OAAO,GAAG,YAAA,CAAA,UAAA,EAAhB;;EAEA,IAAI,OAAJ,EAAa;IACX,SAAA,CAAA,QAAA,CAAS,OAAT;EACD;;EAED,OAAO,sBAAA,CAAA,oBAAA,CAAqB;IAC1B,KAAK,EAAE;MACL,MAAM,EAAE,CAAC,EAAC,OAAO,KAAA,IAAP,IAAA,OAAO,KAAA,KAAA,CAAP,GAAO,KAAA,CAAP,GAAA,OAAO,CAAE,QAAV,CADJ;MAEL,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;MAGL,eAAe,EAAE,OAAO,KAAA,IAAP,IAAA,OAAO,KAAA,KAAA,CAAP,GAAO,KAAA,CAAP,GAAA,OAAO,CAAE,eAHrB;MAIL,QAAQ,EAAE,OAAO,KAAA,IAAP,IAAA,OAAO,KAAA,KAAA,CAAP,GAAO,KAAA,CAAP,GAAA,OAAO,CAAE;IAJd;EADmB,CAArB,CAAP;AAQD,CAfM;;AAAM,OAAA,CAAA,uBAAA,GAAuB,uBAAvB;;AAiBb,SAAS,oBAAT,CAA8B,IAA9B,EAA0E;EACxE,QAAQ,IAAR;IACE,KAAK,YAAL;MACE,OAAO,SAAA,CAAA,KAAA,CAAM,eAAN,CAAsB,UAA7B;;IACF,KAAK,MAAL;MACE,OAAO,SAAA,CAAA,KAAA,CAAM,eAAN,CAAsB,IAA7B;;IAEF,KAAK,UAAL;IACA;MACE,OAAO,SAAA,CAAA,KAAA,CAAM,eAAN,CAAsB,QAA7B;EARJ;AAUD","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';\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\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 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 tabbable: options?.tabbable,\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\n case 'vertical':\n default:\n return Types.MoverDirections.Vertical;\n }\n}\n"],"sourceRoot":"../src/"}
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;AA2BA;;;AAGG;;;AACI,MAAM,uBAAuB,GAAG,CAAC,OAAA,GAA0C,EAA3C,KAA4E;EACjH,MAAM;IAAE,QAAF;IAAY,IAAZ;IAAkB,eAAlB;IAAmC,QAAnC;IAA6C;EAA7C,IAAsE,OAA5E;EACA,MAAM,OAAO,GAAG,YAAA,CAAA,UAAA,EAAhB;;EAEA,IAAI,OAAJ,EAAa;IACX,SAAA,CAAA,QAAA,CAAS,OAAT;EACD;;EAED,OAAO,sBAAA,CAAA,oBAAA,CAAqB;IAC1B,KAAK,EAAE;MACL,MAAM,EAAE,CAAC,CAAC,QADL;MAEL,SAAS,EAAE,oBAAoB,CAAC,IAAI,KAAA,IAAJ,IAAA,IAAI,KAAA,KAAA,CAAJ,GAAA,IAAA,GAAQ,UAAT,CAF1B;MAGL,eAAe,EAAE,eAHZ;MAIL,QAAQ,EAAE;IAJL,CADmB;IAO1B,IAAI,oBAAoB,IAAI;MAC1B,SAAS,EAAE;QACT,aAAa,EAAE;MADN;IADe,CAA5B;EAP0B,CAArB,CAAP;AAaD,CArBM;;AAAM,OAAA,CAAA,uBAAA,GAAuB,uBAAvB;;AAuBb,SAAS,oBAAT,CAA8B,IAA9B,EAA0E;EACxE,QAAQ,IAAR;IACE,KAAK,YAAL;MACE,OAAO,SAAA,CAAA,KAAA,CAAM,eAAN,CAAsB,UAA7B;;IACF,KAAK,MAAL;MACE,OAAO,SAAA,CAAA,KAAA,CAAM,eAAN,CAAsB,IAA7B;;IAEF,KAAK,UAAL;IACA;MACE,OAAO,SAAA,CAAA,KAAA,CAAM,eAAN,CAAsB,QAA7B;EARJ;AAUD","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';\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\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 { circular, axis, memorizeCurrent, tabbable, ignoreDefaultKeydown } = 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: memorizeCurrent,\n tabbable: tabbable,\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\n case 'vertical':\n default:\n return Types.MoverDirections.Vertical;\n }\n}\n"],"sourceRoot":"../src/"}
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useFocusVisible = void 0;
7
+
8
+ const React = /*#__PURE__*/require("react");
9
+
10
+ const react_shared_contexts_1 = /*#__PURE__*/require("@fluentui/react-shared-contexts");
11
+
12
+ const focusVisiblePolyfill_1 = /*#__PURE__*/require("../focus/focusVisiblePolyfill");
13
+
14
+ function useFocusVisible() {
15
+ const {
16
+ targetDocument
17
+ } = react_shared_contexts_1.useFluent_unstable();
18
+ const scopeRef = React.useRef(null);
19
+ React.useEffect(() => {
20
+ if ((targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.defaultView) && scopeRef.current) {
21
+ return focusVisiblePolyfill_1.applyFocusVisiblePolyfill(scopeRef.current, targetDocument.defaultView);
22
+ }
23
+ }, [scopeRef, targetDocument]);
24
+ return scopeRef;
25
+ }
26
+
27
+ exports.useFocusVisible = useFocusVisible;
28
+ //# sourceMappingURL=useFocusVisible.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["hooks/useFocusVisible.ts"],"names":[],"mappings":";;;;;;;AAAA,MAAA,KAAA,gBAAA,OAAA,CAAA,OAAA,CAAA;;AACA,MAAA,uBAAA,gBAAA,OAAA,CAAA,iCAAA,CAAA;;AACA,MAAA,sBAAA,gBAAA,OAAA,CAAA,+BAAA,CAAA;;AAEA,SAAgB,eAAhB,GAA+B;EAC7B,MAAM;IAAE;EAAF,IAAqB,uBAAA,CAAA,kBAAA,EAA3B;EACA,MAAM,QAAQ,GAAG,KAAK,CAAC,MAAN,CAAuB,IAAvB,CAAjB;EAEA,KAAK,CAAC,SAAN,CAAgB,MAAK;IACnB,IAAI,CAAA,cAAc,KAAA,IAAd,IAAA,cAAc,KAAA,KAAA,CAAd,GAAc,KAAA,CAAd,GAAA,cAAc,CAAE,WAAhB,KAA+B,QAAQ,CAAC,OAA5C,EAAqD;MACnD,OAAO,sBAAA,CAAA,yBAAA,CAA0B,QAAQ,CAAC,OAAnC,EAA4C,cAAc,CAAC,WAA3D,CAAP;IACD;EACF,CAJD,EAIG,CAAC,QAAD,EAAW,cAAX,CAJH;EAMA,OAAO,QAAP;AACD;;AAXD,OAAA,CAAA,eAAA,GAAA,eAAA","sourcesContent":["import * as React from 'react';\nimport { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\nimport { applyFocusVisiblePolyfill } from '../focus/focusVisiblePolyfill';\n\nexport function useFocusVisible<TElement extends HTMLElement = HTMLElement>() {\n const { targetDocument } = useFluent();\n const scopeRef = React.useRef<TElement>(null);\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"],"sourceRoot":"../src/"}
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useFocusWithin = void 0;
7
+
8
+ const React = /*#__PURE__*/require("react");
9
+
10
+ const react_shared_contexts_1 = /*#__PURE__*/require("@fluentui/react-shared-contexts");
11
+
12
+ const focusWithinPolyfill_1 = /*#__PURE__*/require("../focus/focusWithinPolyfill");
13
+ /**
14
+ * A ponyfill that allows `:focus-within` to support visibility based on keyboard/mouse navigation
15
+ * like `:focus-visible` https://github.com/WICG/focus-visible/issues/151
16
+ * @returns ref to the element that uses `:focus-within` styles
17
+ */
18
+
19
+
20
+ function useFocusWithin() {
21
+ const {
22
+ targetDocument
23
+ } = react_shared_contexts_1.useFluent_unstable();
24
+ const elementRef = React.useRef(null);
25
+ React.useEffect(() => {
26
+ if ((targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.defaultView) && elementRef.current) {
27
+ return focusWithinPolyfill_1.applyFocusWithinPolyfill(elementRef.current, targetDocument.defaultView);
28
+ }
29
+ }, [elementRef, targetDocument]);
30
+ return elementRef;
31
+ }
32
+
33
+ exports.useFocusWithin = useFocusWithin;
34
+ //# sourceMappingURL=useFocusWithin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["hooks/useFocusWithin.ts"],"names":[],"mappings":";;;;;;;AAAA,MAAA,KAAA,gBAAA,OAAA,CAAA,OAAA,CAAA;;AACA,MAAA,uBAAA,gBAAA,OAAA,CAAA,iCAAA,CAAA;;AACA,MAAA,qBAAA,gBAAA,OAAA,CAAA,8BAAA,CAAA;AAEA;;;;AAIG;;;AACH,SAAgB,cAAhB,GAA8B;EAC5B,MAAM;IAAE;EAAF,IAAqB,uBAAA,CAAA,kBAAA,EAA3B;EACA,MAAM,UAAU,GAAG,KAAK,CAAC,MAAN,CAAuB,IAAvB,CAAnB;EAEA,KAAK,CAAC,SAAN,CAAgB,MAAK;IACnB,IAAI,CAAA,cAAc,KAAA,IAAd,IAAA,cAAc,KAAA,KAAA,CAAd,GAAc,KAAA,CAAd,GAAA,cAAc,CAAE,WAAhB,KAA+B,UAAU,CAAC,OAA9C,EAAuD;MACrD,OAAO,qBAAA,CAAA,wBAAA,CAAyB,UAAU,CAAC,OAApC,EAA6C,cAAc,CAAC,WAA5D,CAAP;IACD;EACF,CAJD,EAIG,CAAC,UAAD,EAAa,cAAb,CAJH;EAMA,OAAO,UAAP;AACD;;AAXD,OAAA,CAAA,cAAA,GAAA,cAAA","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"],"sourceRoot":"../src/"}
@@ -5,9 +5,13 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.useTabster = void 0;
7
7
 
8
+ const React = /*#__PURE__*/require("react");
9
+
8
10
  const react_shared_contexts_1 = /*#__PURE__*/require("@fluentui/react-shared-contexts");
9
11
 
10
12
  const tabster_1 = /*#__PURE__*/require("tabster");
13
+
14
+ const react_utilities_1 = /*#__PURE__*/require("@fluentui/react-utilities");
11
15
  /**
12
16
  * Tries to get a tabster instance on the current window or creates a new one
13
17
  * Since Tabster is single instance only, feel free to call this hook to ensure Tabster exists if necessary
@@ -18,23 +22,28 @@ const tabster_1 = /*#__PURE__*/require("tabster");
18
22
 
19
23
 
20
24
  const useTabster = () => {
21
- var _a;
22
-
23
25
  const {
24
26
  targetDocument
25
27
  } = react_shared_contexts_1.useFluent_unstable();
26
28
  const defaultView = (targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.defaultView) || undefined;
27
- const tabsterOptions = {
28
- autoRoot: {},
29
- controlTab: false
30
- };
31
-
32
- if (!defaultView) {
33
- return null;
34
- } // TODO: worth memoizing once more tabster options are used
35
-
36
-
37
- return (_a = tabster_1.getCurrentTabster(defaultView)) !== null && _a !== void 0 ? _a : tabster_1.createTabster(defaultView, tabsterOptions);
29
+ const tabster = React.useMemo(() => {
30
+ if (!defaultView) {
31
+ return null;
32
+ }
33
+
34
+ return tabster_1.createTabster(defaultView, {
35
+ autoRoot: {},
36
+ controlTab: false
37
+ });
38
+ }, [defaultView]);
39
+ react_utilities_1.useIsomorphicLayoutEffect(() => {
40
+ return () => {
41
+ if (tabster) {
42
+ tabster_1.disposeTabster(tabster);
43
+ }
44
+ };
45
+ }, [tabster]);
46
+ return tabster;
38
47
  };
39
48
 
40
49
  exports.useTabster = useTabster;
@@ -1 +1 @@
1
- {"version":3,"sources":["hooks/useTabster.ts"],"names":[],"mappings":";;;;;;;AAAA,MAAA,uBAAA,gBAAA,OAAA,CAAA,iCAAA,CAAA;;AACA,MAAA,SAAA,gBAAA,OAAA,CAAA,SAAA,CAAA;AAEA;;;;;;AAMG;;;AACI,MAAM,UAAU,GAAG,MAAsC;;;EAC9D,MAAM;IAAE;EAAF,IAAqB,uBAAA,CAAA,kBAAA,EAA3B;EAEA,MAAM,WAAW,GAAG,CAAA,cAAc,KAAA,IAAd,IAAA,cAAc,KAAA,KAAA,CAAd,GAAc,KAAA,CAAd,GAAA,cAAc,CAAE,WAAhB,KAA+B,SAAnD;EACA,MAAM,cAAc,GAAkC;IAAE,QAAQ,EAAE,EAAZ;IAAgB,UAAU,EAAE;EAA5B,CAAtD;;EAEA,IAAI,CAAC,WAAL,EAAkB;IAChB,OAAO,IAAP;EACD,CAR6D,CAU9D;;;EACA,OAAO,CAAA,EAAA,GAAA,SAAA,CAAA,iBAAA,CAAkB,WAAlB,CAAA,MAA8B,IAA9B,IAA8B,EAAA,KAAA,KAAA,CAA9B,GAA8B,EAA9B,GAAkC,SAAA,CAAA,aAAA,CAAc,WAAd,EAA2B,cAA3B,CAAzC;AACD,CAZM;;AAAM,OAAA,CAAA,UAAA,GAAU,UAAV","sourcesContent":["import { useFluent_unstable as 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/"}
1
+ {"version":3,"sources":["hooks/useTabster.ts"],"names":[],"mappings":";;;;;;;AAAA,MAAA,KAAA,gBAAA,OAAA,CAAA,OAAA,CAAA;;AACA,MAAA,uBAAA,gBAAA,OAAA,CAAA,iCAAA,CAAA;;AACA,MAAA,SAAA,gBAAA,OAAA,CAAA,SAAA,CAAA;;AACA,MAAA,iBAAA,gBAAA,OAAA,CAAA,2BAAA,CAAA;AAEA;;;;;;AAMG;;;AACI,MAAM,UAAU,GAAG,MAAsC;EAC9D,MAAM;IAAE;EAAF,IAAqB,uBAAA,CAAA,kBAAA,EAA3B;EAEA,MAAM,WAAW,GAAG,CAAA,cAAc,KAAA,IAAd,IAAA,cAAc,KAAA,KAAA,CAAd,GAAc,KAAA,CAAd,GAAA,cAAc,CAAE,WAAhB,KAA+B,SAAnD;EACA,MAAM,OAAO,GAAG,KAAK,CAAC,OAAN,CAAc,MAAK;IACjC,IAAI,CAAC,WAAL,EAAkB;MAChB,OAAO,IAAP;IACD;;IAED,OAAO,SAAA,CAAA,aAAA,CAAc,WAAd,EAA2B;MAAE,QAAQ,EAAE,EAAZ;MAAgB,UAAU,EAAE;IAA5B,CAA3B,CAAP;EACD,CANe,EAMb,CAAC,WAAD,CANa,CAAhB;EAQA,iBAAA,CAAA,yBAAA,CAA0B,MAAK;IAC7B,OAAO,MAAK;MACV,IAAI,OAAJ,EAAa;QACX,SAAA,CAAA,cAAA,CAAe,OAAf;MACD;IACF,CAJD;EAKD,CAND,EAMG,CAAC,OAAD,CANH;EAQA,OAAO,OAAP;AACD,CArBM;;AAAM,OAAA,CAAA,UAAA,GAAU,UAAV","sourcesContent":["import * as React from 'react';\nimport { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\nimport { createTabster, disposeTabster, Types as TabsterTypes } from 'tabster';\nimport { useIsomorphicLayoutEffect } from '@fluentui/react-utilities';\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 tabster = React.useMemo(() => {\n if (!defaultView) {\n return null;\n }\n\n return createTabster(defaultView, { autoRoot: {}, controlTab: false });\n }, [defaultView]);\n\n useIsomorphicLayoutEffect(() => {\n return () => {\n if (tabster) {\n disposeTabster(tabster);\n }\n };\n }, [tabster]);\n\n return tabster;\n};\n"],"sourceRoot":"../src/"}
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.createFocusOutlineStyle = exports.createCustomFocusIndicatorStyle = exports.useTabsterAttributes = exports.useModalAttributes = exports.useKeyboardNavAttribute = exports.useFocusFinders = exports.useFocusableGroup = exports.useArrowNavigationGroup = void 0;
6
+ exports.createFocusOutlineStyle = exports.createCustomFocusIndicatorStyle = exports.useTabsterAttributes = exports.useModalAttributes = exports.useKeyboardNavAttribute = exports.useFocusWithin = exports.useFocusVisible = exports.useFocusFinders = exports.useFocusableGroup = exports.useArrowNavigationGroup = void 0;
7
7
 
8
8
  var index_1 = /*#__PURE__*/require("./hooks/index");
9
9
 
@@ -25,6 +25,18 @@ Object.defineProperty(exports, "useFocusFinders", {
25
25
  return index_1.useFocusFinders;
26
26
  }
27
27
  });
28
+ Object.defineProperty(exports, "useFocusVisible", {
29
+ enumerable: true,
30
+ get: function () {
31
+ return index_1.useFocusVisible;
32
+ }
33
+ });
34
+ Object.defineProperty(exports, "useFocusWithin", {
35
+ enumerable: true,
36
+ get: function () {
37
+ return index_1.useFocusWithin;
38
+ }
39
+ });
28
40
  Object.defineProperty(exports, "useKeyboardNavAttribute", {
29
41
  enumerable: true,
30
42
  get: function () {
@@ -1 +1 @@
1
- {"version":3,"sources":["index.ts"],"names":[],"mappings":";;;;;;;AAAA,IAAA,OAAA,gBAAA,OAAA,CAAA,eAAA,CAAA;;AACE,MAAA,CAAA,cAAA,CAAA,OAAA,EAAA,yBAAA,EAAA;EAAA,UAAA,EAAA,IAAA;EAAA,GAAA,EAAA,YAAA;IAAA,OAAA,OAAA,CAAA,uBAAA;EAAuB;AAAvB,CAAA;AACA,MAAA,CAAA,cAAA,CAAA,OAAA,EAAA,mBAAA,EAAA;EAAA,UAAA,EAAA,IAAA;EAAA,GAAA,EAAA,YAAA;IAAA,OAAA,OAAA,CAAA,iBAAA;EAAiB;AAAjB,CAAA;AACA,MAAA,CAAA,cAAA,CAAA,OAAA,EAAA,iBAAA,EAAA;EAAA,UAAA,EAAA,IAAA;EAAA,GAAA,EAAA,YAAA;IAAA,OAAA,OAAA,CAAA,eAAA;EAAe;AAAf,CAAA;AACA,MAAA,CAAA,cAAA,CAAA,OAAA,EAAA,yBAAA,EAAA;EAAA,UAAA,EAAA,IAAA;EAAA,GAAA,EAAA,YAAA;IAAA,OAAA,OAAA,CAAA,uBAAA;EAAuB;AAAvB,CAAA;AACA,MAAA,CAAA,cAAA,CAAA,OAAA,EAAA,oBAAA,EAAA;EAAA,UAAA,EAAA,IAAA;EAAA,GAAA,EAAA,YAAA;IAAA,OAAA,OAAA,CAAA,kBAAA;EAAkB;AAAlB,CAAA;AACA,MAAA,CAAA,cAAA,CAAA,OAAA,EAAA,sBAAA,EAAA;EAAA,UAAA,EAAA,IAAA;EAAA,GAAA,EAAA,YAAA;IAAA,OAAA,OAAA,CAAA,oBAAA;EAAoB;AAApB,CAAA;;AAQF,IAAA,OAAA,gBAAA,OAAA,CAAA,eAAA,CAAA;;AAAS,MAAA,CAAA,cAAA,CAAA,OAAA,EAAA,iCAAA,EAAA;EAAA,UAAA,EAAA,IAAA;EAAA,GAAA,EAAA,YAAA;IAAA,OAAA,OAAA,CAAA,+BAAA;EAA+B;AAA/B,CAAA;AAAiC,MAAA,CAAA,cAAA,CAAA,OAAA,EAAA,yBAAA,EAAA;EAAA,UAAA,EAAA,IAAA;EAAA,GAAA,EAAA,YAAA;IAAA,OAAA,OAAA,CAAA,uBAAA;EAAuB;AAAvB,CAAA","sourcesContent":["export {\n useArrowNavigationGroup,\n useFocusableGroup,\n useFocusFinders,\n useKeyboardNavAttribute,\n useModalAttributes,\n useTabsterAttributes,\n} from './hooks/index';\nexport type {\n UseArrowNavigationGroupOptions,\n UseFocusableGroupOptions,\n UseModalAttributesOptions,\n} from './hooks/index';\n\nexport { createCustomFocusIndicatorStyle, createFocusOutlineStyle } from './focus/index';\n\nexport type {\n CreateCustomFocusIndicatorStyleOptions,\n CreateFocusOutlineStyleOptions,\n FocusOutlineOffset,\n FocusOutlineStyleOptions,\n} from './focus/index';\n"],"sourceRoot":"../src/"}
1
+ {"version":3,"sources":["index.ts"],"names":[],"mappings":";;;;;;;AAAA,IAAA,OAAA,gBAAA,OAAA,CAAA,eAAA,CAAA;;AACE,MAAA,CAAA,cAAA,CAAA,OAAA,EAAA,yBAAA,EAAA;EAAA,UAAA,EAAA,IAAA;EAAA,GAAA,EAAA,YAAA;IAAA,OAAA,OAAA,CAAA,uBAAA;EAAuB;AAAvB,CAAA;AACA,MAAA,CAAA,cAAA,CAAA,OAAA,EAAA,mBAAA,EAAA;EAAA,UAAA,EAAA,IAAA;EAAA,GAAA,EAAA,YAAA;IAAA,OAAA,OAAA,CAAA,iBAAA;EAAiB;AAAjB,CAAA;AACA,MAAA,CAAA,cAAA,CAAA,OAAA,EAAA,iBAAA,EAAA;EAAA,UAAA,EAAA,IAAA;EAAA,GAAA,EAAA,YAAA;IAAA,OAAA,OAAA,CAAA,eAAA;EAAe;AAAf,CAAA;AACA,MAAA,CAAA,cAAA,CAAA,OAAA,EAAA,iBAAA,EAAA;EAAA,UAAA,EAAA,IAAA;EAAA,GAAA,EAAA,YAAA;IAAA,OAAA,OAAA,CAAA,eAAA;EAAe;AAAf,CAAA;AACA,MAAA,CAAA,cAAA,CAAA,OAAA,EAAA,gBAAA,EAAA;EAAA,UAAA,EAAA,IAAA;EAAA,GAAA,EAAA,YAAA;IAAA,OAAA,OAAA,CAAA,cAAA;EAAc;AAAd,CAAA;AACA,MAAA,CAAA,cAAA,CAAA,OAAA,EAAA,yBAAA,EAAA;EAAA,UAAA,EAAA,IAAA;EAAA,GAAA,EAAA,YAAA;IAAA,OAAA,OAAA,CAAA,uBAAA;EAAuB;AAAvB,CAAA;AACA,MAAA,CAAA,cAAA,CAAA,OAAA,EAAA,oBAAA,EAAA;EAAA,UAAA,EAAA,IAAA;EAAA,GAAA,EAAA,YAAA;IAAA,OAAA,OAAA,CAAA,kBAAA;EAAkB;AAAlB,CAAA;AACA,MAAA,CAAA,cAAA,CAAA,OAAA,EAAA,sBAAA,EAAA;EAAA,UAAA,EAAA,IAAA;EAAA,GAAA,EAAA,YAAA;IAAA,OAAA,OAAA,CAAA,oBAAA;EAAoB;AAApB,CAAA;;AAQF,IAAA,OAAA,gBAAA,OAAA,CAAA,eAAA,CAAA;;AAAS,MAAA,CAAA,cAAA,CAAA,OAAA,EAAA,iCAAA,EAAA;EAAA,UAAA,EAAA,IAAA;EAAA,GAAA,EAAA,YAAA;IAAA,OAAA,OAAA,CAAA,+BAAA;EAA+B;AAA/B,CAAA;AAAiC,MAAA,CAAA,cAAA,CAAA,OAAA,EAAA,yBAAA,EAAA;EAAA,UAAA,EAAA,IAAA;EAAA,GAAA,EAAA,YAAA;IAAA,OAAA,OAAA,CAAA,uBAAA;EAAuB;AAAvB,CAAA","sourcesContent":["export {\n useArrowNavigationGroup,\n useFocusableGroup,\n useFocusFinders,\n useFocusVisible,\n useFocusWithin,\n useKeyboardNavAttribute,\n useModalAttributes,\n useTabsterAttributes,\n} from './hooks/index';\nexport type {\n UseArrowNavigationGroupOptions,\n UseFocusableGroupOptions,\n UseModalAttributesOptions,\n} from './hooks/index';\n\nexport { createCustomFocusIndicatorStyle, createFocusOutlineStyle } from './focus/index';\n\nexport type {\n CreateCustomFocusIndicatorStyleOptions,\n CreateFocusOutlineStyleOptions,\n FocusOutlineOffset,\n FocusOutlineStyleOptions,\n} from './focus/index';\n"],"sourceRoot":"../src/"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluentui/react-tabster",
3
- "version": "9.0.1",
3
+ "version": "9.1.0",
4
4
  "description": "Utilities for focus management and facade for tabster",
5
5
  "main": "lib-commonjs/index.js",
6
6
  "module": "lib/index.js",
@@ -31,12 +31,12 @@
31
31
  "@fluentui/scripts": "^1.0.0"
32
32
  },
33
33
  "dependencies": {
34
- "@griffel/react": "^1.2.0",
34
+ "@griffel/react": "^1.2.3",
35
35
  "@fluentui/react-shared-contexts": "^9.0.0",
36
36
  "@fluentui/react-theme": "^9.0.0",
37
- "@fluentui/react-utilities": "^9.0.0",
37
+ "@fluentui/react-utilities": "^9.0.2",
38
38
  "keyborg": "^1.1.0",
39
- "tabster": "^1.4.2",
39
+ "tabster": "^2.1.0",
40
40
  "tslib": "^2.1.0"
41
41
  },
42
42
  "peerDependencies": {
@@ -47,7 +47,8 @@
47
47
  },
48
48
  "beachball": {
49
49
  "disallowedChangeTypes": [
50
- "major"
50
+ "major",
51
+ "prerelease"
51
52
  ]
52
53
  },
53
54
  "exports": {