@fluentui/react-tabster 9.0.3 → 9.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.json +116 -2
- package/CHANGELOG.md +33 -3
- package/dist/index.d.ts +22 -1
- package/lib/focus/constants.js +2 -0
- package/lib/focus/constants.js.map +1 -1
- package/lib/focus/createCustomFocusIndicatorStyle.js +10 -2
- package/lib/focus/createCustomFocusIndicatorStyle.js.map +1 -1
- package/lib/focus/focusVisiblePolyfill.js +90 -0
- package/lib/focus/focusVisiblePolyfill.js.map +1 -0
- package/lib/focus/focusWithinPolyfill.js +58 -0
- package/lib/focus/focusWithinPolyfill.js.map +1 -0
- package/lib/focus/index.js +2 -0
- package/lib/focus/index.js.map +1 -1
- package/lib/hooks/index.js +2 -0
- package/lib/hooks/index.js.map +1 -1
- package/lib/hooks/useArrowNavigationGroup.js +18 -8
- package/lib/hooks/useArrowNavigationGroup.js.map +1 -1
- package/lib/hooks/useFocusVisible.js +16 -0
- package/lib/hooks/useFocusVisible.js.map +1 -0
- package/lib/hooks/useFocusWithin.js +22 -0
- package/lib/hooks/useFocusWithin.js.map +1 -0
- package/lib/hooks/useKeyboardNavAttribute.js.map +1 -1
- package/lib/hooks/useTabster.js +20 -13
- package/lib/hooks/useTabster.js.map +1 -1
- package/lib/index.js +2 -1
- package/lib/index.js.map +1 -1
- package/lib-commonjs/focus/constants.js +3 -1
- package/lib-commonjs/focus/constants.js.map +1 -1
- package/lib-commonjs/focus/createCustomFocusIndicatorStyle.js +9 -1
- package/lib-commonjs/focus/createCustomFocusIndicatorStyle.js.map +1 -1
- package/lib-commonjs/focus/focusVisiblePolyfill.js +101 -0
- package/lib-commonjs/focus/focusVisiblePolyfill.js.map +1 -0
- package/lib-commonjs/focus/focusWithinPolyfill.js +69 -0
- package/lib-commonjs/focus/focusWithinPolyfill.js.map +1 -0
- package/lib-commonjs/focus/index.js +4 -0
- package/lib-commonjs/focus/index.js.map +1 -1
- package/lib-commonjs/hooks/index.js +4 -0
- package/lib-commonjs/hooks/index.js.map +1 -1
- package/lib-commonjs/hooks/useArrowNavigationGroup.js +18 -8
- package/lib-commonjs/hooks/useArrowNavigationGroup.js.map +1 -1
- package/lib-commonjs/hooks/useFocusVisible.js +28 -0
- package/lib-commonjs/hooks/useFocusVisible.js.map +1 -0
- package/lib-commonjs/hooks/useFocusWithin.js +34 -0
- package/lib-commonjs/hooks/useFocusWithin.js.map +1 -0
- package/lib-commonjs/hooks/useKeyboardNavAttribute.js.map +1 -1
- package/lib-commonjs/hooks/useTabster.js +22 -13
- package/lib-commonjs/hooks/useTabster.js.map +1 -1
- package/lib-commonjs/index.js +22 -1
- package/lib-commonjs/index.js.map +1 -1
- package/package.json +13 -12
- package/dist/tsdoc-metadata.json +0 -11
package/CHANGELOG.json
CHANGED
@@ -2,7 +2,121 @@
|
|
2
2
|
"name": "@fluentui/react-tabster",
|
3
3
|
"entries": [
|
4
4
|
{
|
5
|
-
"date": "Thu,
|
5
|
+
"date": "Thu, 15 Sep 2022 09:44:52 GMT",
|
6
|
+
"tag": "@fluentui/react-tabster_v9.1.1",
|
7
|
+
"version": "9.1.1",
|
8
|
+
"comments": {
|
9
|
+
"patch": [
|
10
|
+
{
|
11
|
+
"author": "lingfangao@hotmail.com",
|
12
|
+
"package": "@fluentui/react-tabster",
|
13
|
+
"commit": "e4d50f2c501c4a8be23b24373242f650a601fdaf",
|
14
|
+
"comment": "fix: Remove provider classname from focus styles"
|
15
|
+
},
|
16
|
+
{
|
17
|
+
"author": "lingfangao@hotmail.com",
|
18
|
+
"package": "@fluentui/react-tabster",
|
19
|
+
"commit": "e2b71230d03f2cf03eff3cda02484dfcb72e9c51",
|
20
|
+
"comment": "fix: Bumps tabster to 2.1.2 and removes deep import for KeyborgCallback"
|
21
|
+
},
|
22
|
+
{
|
23
|
+
"author": "lingfangao@hotmail.com",
|
24
|
+
"package": "@fluentui/react-tabster",
|
25
|
+
"commit": "f1f4ab4ac21226c8f6729ca263ca09c1ec9b76f2",
|
26
|
+
"comment": "chore: Exports `applyFocusVisible` as internal"
|
27
|
+
},
|
28
|
+
{
|
29
|
+
"author": "olfedias@microsoft.com",
|
30
|
+
"package": "@fluentui/react-tabster",
|
31
|
+
"commit": "e610024474cfe5d45f61501a8b6a21daf4c794a2",
|
32
|
+
"comment": "chore: Update Griffel to latest version"
|
33
|
+
},
|
34
|
+
{
|
35
|
+
"author": "beachball",
|
36
|
+
"package": "@fluentui/react-tabster",
|
37
|
+
"comment": "Bump @fluentui/react-shared-contexts to v9.0.1",
|
38
|
+
"commit": "a33448fe4a0f4117686c378f80b893d1406d95a8"
|
39
|
+
},
|
40
|
+
{
|
41
|
+
"author": "beachball",
|
42
|
+
"package": "@fluentui/react-tabster",
|
43
|
+
"comment": "Bump @fluentui/react-theme to v9.1.0",
|
44
|
+
"commit": "a33448fe4a0f4117686c378f80b893d1406d95a8"
|
45
|
+
},
|
46
|
+
{
|
47
|
+
"author": "beachball",
|
48
|
+
"package": "@fluentui/react-tabster",
|
49
|
+
"comment": "Bump @fluentui/react-utilities to v9.1.0",
|
50
|
+
"commit": "a33448fe4a0f4117686c378f80b893d1406d95a8"
|
51
|
+
}
|
52
|
+
],
|
53
|
+
"none": [
|
54
|
+
{
|
55
|
+
"author": "martinhochel@microsoft.com",
|
56
|
+
"package": "@fluentui/react-tabster",
|
57
|
+
"commit": "ba9444d594f3a960cc590eae5237c08bf7c5a07f",
|
58
|
+
"comment": "chore: consume cypress.config from it's package boundary"
|
59
|
+
},
|
60
|
+
{
|
61
|
+
"author": "martinhochel@microsoft.com",
|
62
|
+
"package": "@fluentui/react-tabster",
|
63
|
+
"commit": "16aa65dcae8f75c6a221225fd0eb43800650ac66",
|
64
|
+
"comment": "docs: re-generate api.md files"
|
65
|
+
},
|
66
|
+
{
|
67
|
+
"author": "martinhochel@microsoft.com",
|
68
|
+
"package": "@fluentui/react-tabster",
|
69
|
+
"commit": "e6cf183695d6d67a24e038c49a876224e5ed35e5",
|
70
|
+
"comment": "chore: update package scaffold"
|
71
|
+
}
|
72
|
+
]
|
73
|
+
}
|
74
|
+
},
|
75
|
+
{
|
76
|
+
"date": "Wed, 03 Aug 2022 16:04:04 GMT",
|
77
|
+
"tag": "@fluentui/react-tabster_v9.1.0",
|
78
|
+
"version": "9.1.0",
|
79
|
+
"comments": {
|
80
|
+
"patch": [
|
81
|
+
{
|
82
|
+
"author": "lingfangao@hotmail.com",
|
83
|
+
"package": "@fluentui/react-tabster",
|
84
|
+
"commit": "b9e6c6a7dd8ce6111744739a0ec486b99c2bb2ea",
|
85
|
+
"comment": "chore: Bump tabster to 2.1.0"
|
86
|
+
},
|
87
|
+
{
|
88
|
+
"author": "miroslav.stastny@microsoft.com",
|
89
|
+
"package": "@fluentui/react-tabster",
|
90
|
+
"commit": "08563664778fd80284561d3c9d254307a0a32362",
|
91
|
+
"comment": "chore: Bump Griffel dependencies"
|
92
|
+
}
|
93
|
+
],
|
94
|
+
"minor": [
|
95
|
+
{
|
96
|
+
"author": "lingfangao@hotmail.com",
|
97
|
+
"package": "@fluentui/react-tabster",
|
98
|
+
"commit": "2756c649a83c0fa0a20b82c62855d388a5e6bc2a",
|
99
|
+
"comment": "feat: Adds `ignoreDefaultKeydown` option to `useArrowNavigationGroup`"
|
100
|
+
},
|
101
|
+
{
|
102
|
+
"author": "lingfangao@hotmail.com",
|
103
|
+
"package": "@fluentui/react-tabster",
|
104
|
+
"commit": "71590ea6aeab8ce24d8c8e50e0ee80ece81a4392",
|
105
|
+
"comment": "feat: create `:focus-visible` and `:focus-within` polyfills"
|
106
|
+
}
|
107
|
+
],
|
108
|
+
"none": [
|
109
|
+
{
|
110
|
+
"author": "lingfangao@hotmail.com",
|
111
|
+
"package": "@fluentui/react-tabster",
|
112
|
+
"commit": "99cc385631d04a76ee10ebc143cb9fecd99640b6",
|
113
|
+
"comment": "chore: Add `prerelease` as disallowed changetype for 9.0.0 packages"
|
114
|
+
}
|
115
|
+
]
|
116
|
+
}
|
117
|
+
},
|
118
|
+
{
|
119
|
+
"date": "Thu, 14 Jul 2022 21:21:05 GMT",
|
6
120
|
"tag": "@fluentui/react-tabster_v9.0.3",
|
7
121
|
"version": "9.0.3",
|
8
122
|
"comments": {
|
@@ -17,7 +131,7 @@
|
|
17
131
|
"author": "beachball",
|
18
132
|
"package": "@fluentui/react-tabster",
|
19
133
|
"comment": "Bump @fluentui/react-utilities to v9.0.2",
|
20
|
-
"commit": "
|
134
|
+
"commit": "79b513146194367544160f364b0a7dd749ed93e4"
|
21
135
|
}
|
22
136
|
]
|
23
137
|
}
|
package/CHANGELOG.md
CHANGED
@@ -1,18 +1,48 @@
|
|
1
1
|
# Change Log - @fluentui/react-tabster
|
2
2
|
|
3
|
-
This log was last generated on Thu,
|
3
|
+
This log was last generated on Thu, 15 Sep 2022 09:44:52 GMT and should not be manually modified.
|
4
4
|
|
5
5
|
<!-- Start content -->
|
6
6
|
|
7
|
+
## [9.1.1](https://github.com/microsoft/fluentui/tree/@fluentui/react-tabster_v9.1.1)
|
8
|
+
|
9
|
+
Thu, 15 Sep 2022 09:44:52 GMT
|
10
|
+
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-tabster_v9.1.0..@fluentui/react-tabster_v9.1.1)
|
11
|
+
|
12
|
+
### Patches
|
13
|
+
|
14
|
+
- fix: Remove provider classname from focus styles ([PR #24710](https://github.com/microsoft/fluentui/pull/24710) by lingfangao@hotmail.com)
|
15
|
+
- fix: Bumps tabster to 2.1.2 and removes deep import for KeyborgCallback ([PR #24376](https://github.com/microsoft/fluentui/pull/24376) by lingfangao@hotmail.com)
|
16
|
+
- chore: Exports `applyFocusVisible` as internal ([PR #24712](https://github.com/microsoft/fluentui/pull/24712) by lingfangao@hotmail.com)
|
17
|
+
- chore: Update Griffel to latest version ([PR #24221](https://github.com/microsoft/fluentui/pull/24221) by olfedias@microsoft.com)
|
18
|
+
- Bump @fluentui/react-shared-contexts to v9.0.1 ([PR #24808](https://github.com/microsoft/fluentui/pull/24808) by beachball)
|
19
|
+
- Bump @fluentui/react-theme to v9.1.0 ([PR #24808](https://github.com/microsoft/fluentui/pull/24808) by beachball)
|
20
|
+
- Bump @fluentui/react-utilities to v9.1.0 ([PR #24808](https://github.com/microsoft/fluentui/pull/24808) by beachball)
|
21
|
+
|
22
|
+
## [9.1.0](https://github.com/microsoft/fluentui/tree/@fluentui/react-tabster_v9.1.0)
|
23
|
+
|
24
|
+
Wed, 03 Aug 2022 16:04:04 GMT
|
25
|
+
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-tabster_v9.0.3..@fluentui/react-tabster_v9.1.0)
|
26
|
+
|
27
|
+
### Minor changes
|
28
|
+
|
29
|
+
- feat: Adds `ignoreDefaultKeydown` option to `useArrowNavigationGroup` ([PR #24101](https://github.com/microsoft/fluentui/pull/24101) by lingfangao@hotmail.com)
|
30
|
+
- feat: create `:focus-visible` and `:focus-within` polyfills ([PR #24154](https://github.com/microsoft/fluentui/pull/24154) by lingfangao@hotmail.com)
|
31
|
+
|
32
|
+
### Patches
|
33
|
+
|
34
|
+
- chore: Bump tabster to 2.1.0 ([PR #23811](https://github.com/microsoft/fluentui/pull/23811) by lingfangao@hotmail.com)
|
35
|
+
- chore: Bump Griffel dependencies ([PR #24114](https://github.com/microsoft/fluentui/pull/24114) by miroslav.stastny@microsoft.com)
|
36
|
+
|
7
37
|
## [9.0.3](https://github.com/microsoft/fluentui/tree/@fluentui/react-tabster_v9.0.3)
|
8
38
|
|
9
|
-
Thu, 14 Jul 2022 21:
|
39
|
+
Thu, 14 Jul 2022 21:21:05 GMT
|
10
40
|
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-tabster_v9.0.2..@fluentui/react-tabster_v9.0.3)
|
11
41
|
|
12
42
|
### Patches
|
13
43
|
|
14
44
|
- fix: Fixing bad version bump of @fluentui/react-utilities. ([PR #23920](https://github.com/microsoft/fluentui/pull/23920) by Humberto.Morimoto@microsoft.com)
|
15
|
-
- Bump @fluentui/react-utilities to v9.0.2 ([PR #
|
45
|
+
- Bump @fluentui/react-utilities to v9.0.2 ([PR #23918](https://github.com/microsoft/fluentui/pull/23918) by beachball)
|
16
46
|
|
17
47
|
## [9.0.2](https://github.com/microsoft/fluentui/tree/@fluentui/react-tabster_v9.0.2)
|
18
48
|
|
package/dist/index.d.ts
CHANGED
@@ -1,7 +1,15 @@
|
|
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
|
|
6
|
+
/**
|
7
|
+
* @internal
|
8
|
+
* @param scope - Applies the ponyfill to all DOM children
|
9
|
+
* @param win - window
|
10
|
+
*/
|
11
|
+
export declare function applyFocusVisiblePolyfill(scope: HTMLElement, win: Window): () => void;
|
12
|
+
|
5
13
|
/**
|
6
14
|
* Creates a style for @see makeStyles that includes the necessary selectors for focus.
|
7
15
|
* Should be used only when @see createFocusOutlineStyle does not fit requirements
|
@@ -45,7 +53,7 @@ export declare type FocusOutlineStyleOptions = {
|
|
45
53
|
* A hook that returns the necessary tabster attributes to support arrow key navigation
|
46
54
|
* @param options - Options to configure keyboard navigation
|
47
55
|
*/
|
48
|
-
export declare const useArrowNavigationGroup: (options?: UseArrowNavigationGroupOptions
|
56
|
+
export declare const useArrowNavigationGroup: (options?: UseArrowNavigationGroupOptions) => Types.TabsterDOMAttribute;
|
49
57
|
|
50
58
|
export declare interface UseArrowNavigationGroupOptions {
|
51
59
|
/**
|
@@ -66,6 +74,10 @@ export declare interface UseArrowNavigationGroupOptions {
|
|
66
74
|
* Allow tabbing within the arrow navigation group items.
|
67
75
|
*/
|
68
76
|
tabbable?: boolean;
|
77
|
+
/**
|
78
|
+
* Tabster should ignore default handling of keydown events
|
79
|
+
*/
|
80
|
+
ignoreDefaultKeydown?: Types.FocusableProps['ignoreKeydown'];
|
69
81
|
}
|
70
82
|
|
71
83
|
/**
|
@@ -92,6 +104,15 @@ export declare const useFocusFinders: () => {
|
|
92
104
|
findPrevFocusable: (currentElement: HTMLElement, options?: Pick<Types.FindNextProps, 'container'>) => HTMLElement | null | undefined;
|
93
105
|
};
|
94
106
|
|
107
|
+
export declare function useFocusVisible<TElement extends HTMLElement = HTMLElement>(): React_2.RefObject<TElement>;
|
108
|
+
|
109
|
+
/**
|
110
|
+
* A ponyfill that allows `:focus-within` to support visibility based on keyboard/mouse navigation
|
111
|
+
* like `:focus-visible` https://github.com/WICG/focus-visible/issues/151
|
112
|
+
* @returns ref to the element that uses `:focus-within` styles
|
113
|
+
*/
|
114
|
+
export declare function useFocusWithin<TElement extends HTMLElement = HTMLElement>(): React_2.RefObject<TElement>;
|
115
|
+
|
95
116
|
/**
|
96
117
|
* Instantiates [keyborg](https://github.com/microsoft/keyborg) and adds `data-keyboard-nav`
|
97
118
|
* attribute to a referenced element to ensure keyboard navigation awareness
|
package/lib/focus/constants.js
CHANGED
@@ -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 {
|
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,14 @@ export const createCustomFocusIndicatorStyle = (style, {
|
|
13
13
|
':focus': {
|
14
14
|
outlineStyle: 'none'
|
15
15
|
},
|
16
|
-
|
16
|
+
':focus-visible': {
|
17
|
+
outlineStyle: 'none'
|
18
|
+
},
|
19
|
+
...(selector === 'focus' && {
|
20
|
+
[`&.${FOCUS_VISIBLE_CLASS}`]: style
|
21
|
+
}),
|
22
|
+
...(selector === 'focus-within' && {
|
23
|
+
[`&.${FOCUS_WITHIN_CLASS}:${selector}`]: style
|
24
|
+
})
|
17
25
|
});
|
18
26
|
//# sourceMappingURL=createCustomFocusIndicatorStyle.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["focus/createCustomFocusIndicatorStyle.ts"],"names":[],"mappings":"AAAA,SAAS,
|
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;EAQlB,IAAI,QAAQ,KAAK,OAAb,IAAwB;IAC1B,CAAC,KAAK,mBAAmB,EAAzB,GAA8B;EADJ,CAA5B,CARkB;EAWlB,IAAI,QAAQ,KAAK,cAAb,IAA+B;IACjC,CAAC,KAAK,kBAAkB,IAAI,QAAQ,EAApC,GAAyC;EADR,CAAnC;AAXkB,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\n ...(selector === 'focus' && {\n [`&.${FOCUS_VISIBLE_CLASS}`]: style,\n }),\n ...(selector === 'focus-within' && {\n [`&.${FOCUS_WITHIN_CLASS}:${selector}`]: style,\n }),\n});\n"],"sourceRoot":"../src/"}
|
@@ -0,0 +1,90 @@
|
|
1
|
+
import { KEYBORG_FOCUSIN, createKeyborg, disposeKeyborg } from 'keyborg';
|
2
|
+
import { FOCUS_VISIBLE_CLASS } from './constants';
|
3
|
+
/**
|
4
|
+
* @internal
|
5
|
+
* @param scope - Applies the ponyfill to all DOM children
|
6
|
+
* @param win - window
|
7
|
+
*/
|
8
|
+
|
9
|
+
export function applyFocusVisiblePolyfill(scope, win) {
|
10
|
+
if (alreadyInScope(scope)) {
|
11
|
+
// Focus visible polyfill already applied at this scope
|
12
|
+
return () => undefined;
|
13
|
+
}
|
14
|
+
|
15
|
+
const state = {
|
16
|
+
current: undefined
|
17
|
+
};
|
18
|
+
const keyborg = createKeyborg(win); // When navigation mode changes remove the focus-visible selector
|
19
|
+
|
20
|
+
keyborg.subscribe(isNavigatingWithKeyboard => {
|
21
|
+
if (!isNavigatingWithKeyboard && state.current) {
|
22
|
+
removeFocusVisibleClass(state.current);
|
23
|
+
state.current = undefined;
|
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 (state.current) {
|
30
|
+
removeFocusVisibleClass(state.current);
|
31
|
+
state.current = undefined;
|
32
|
+
}
|
33
|
+
|
34
|
+
if (keyborg.isNavigatingWithKeyboard() && isHTMLElement(e.target) && e.target) {
|
35
|
+
// Griffel can't create chained global styles so use the parent element for now
|
36
|
+
state.current = e.target;
|
37
|
+
applyFocusVisibleClass(state.current);
|
38
|
+
}
|
39
|
+
}; // Make sure that when focus leaves the scope, the focus visible class is removed
|
40
|
+
|
41
|
+
|
42
|
+
const blurListener = e => {
|
43
|
+
if (!e.relatedTarget || isHTMLElement(e.relatedTarget) && !scope.contains(e.relatedTarget)) {
|
44
|
+
if (state.current) {
|
45
|
+
removeFocusVisibleClass(state.current);
|
46
|
+
state.current = undefined;
|
47
|
+
}
|
48
|
+
}
|
49
|
+
};
|
50
|
+
|
51
|
+
scope.addEventListener(KEYBORG_FOCUSIN, keyborgListener);
|
52
|
+
scope.addEventListener('focusout', blurListener);
|
53
|
+
scope.focusVisible = true; // Return disposer
|
54
|
+
|
55
|
+
return () => {
|
56
|
+
scope.removeEventListener(KEYBORG_FOCUSIN, keyborgListener);
|
57
|
+
scope.removeEventListener('focusout', blurListener);
|
58
|
+
delete scope.focusVisible;
|
59
|
+
disposeKeyborg(keyborg);
|
60
|
+
};
|
61
|
+
}
|
62
|
+
|
63
|
+
function applyFocusVisibleClass(el) {
|
64
|
+
el.classList.add(FOCUS_VISIBLE_CLASS);
|
65
|
+
}
|
66
|
+
|
67
|
+
function removeFocusVisibleClass(el) {
|
68
|
+
el.classList.remove(FOCUS_VISIBLE_CLASS);
|
69
|
+
}
|
70
|
+
|
71
|
+
function isHTMLElement(target) {
|
72
|
+
if (!target) {
|
73
|
+
return false;
|
74
|
+
}
|
75
|
+
|
76
|
+
return Boolean(target && typeof target === 'object' && 'classList' in target && 'contains' in target);
|
77
|
+
}
|
78
|
+
|
79
|
+
function alreadyInScope(el) {
|
80
|
+
if (!el) {
|
81
|
+
return false;
|
82
|
+
}
|
83
|
+
|
84
|
+
if (el.focusVisible) {
|
85
|
+
return true;
|
86
|
+
}
|
87
|
+
|
88
|
+
return alreadyInScope(el === null || el === void 0 ? void 0 : el.parentElement);
|
89
|
+
}
|
90
|
+
//# 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\n/**\n * @internal\n * @param scope - Applies the ponyfill to all DOM children\n * @param win - window\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/"}
|
package/lib/focus/index.js
CHANGED
package/lib/focus/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"../src/","sources":["focus/index.ts"],"names":[],"mappings":"AAAA,cAAc,mCAAmC,CAAC;AAClD,cAAc,2BAA2B,CAAC","sourcesContent":["export * from './createCustomFocusIndicatorStyle';\nexport * from './createFocusOutlineStyle';\n"]}
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"../src/","sources":["focus/index.ts"],"names":[],"mappings":"AAAA,cAAc,mCAAmC,CAAC;AAClD,cAAc,2BAA2B,CAAC;AAC1C,cAAc,wBAAwB,CAAC;AACvC,cAAc,uBAAuB,CAAC","sourcesContent":["export * from './createCustomFocusIndicatorStyle';\nexport * from './createFocusOutlineStyle';\nexport * from './focusVisiblePolyfill';\nexport * from './focusWithinPolyfill';\n"]}
|
package/lib/hooks/index.js
CHANGED
@@ -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';
|
package/lib/hooks/index.js.map
CHANGED
@@ -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
|
-
|
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: !!
|
21
|
-
direction: axisToMoverDirection(
|
22
|
-
memorizeCurrent:
|
23
|
-
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;
|
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 +1 @@
|
|
1
|
-
{"version":3,"sources":["hooks/useKeyboardNavAttribute.ts"],"names":[],"mappings":"AAAA,SAAS,aAAT,QAA8B,SAA9B;AACA,SAAS,SAAT,EAAoB,OAApB,EAA6B,MAA7B,QAA2C,OAA3C;AACA,SAAS,sBAAT,QAAuC,oBAAvC;AACA,SAAS,kBAAkB,IAAI,SAA/B,QAAgD,iCAAhD;AAIA;;;;AAIG;;AACH,OAAM,SAAU,uBAAV,GAAiC;EACrC,MAAM;IAAE;EAAF,IAAqB,SAAS,EAApC;EACA,MAAM,OAAO,GAAG,OAAO,CAAC,MAAM,cAAc,IAAI,aAAa,CAAC,cAAc,CAAC,WAAhB,CAAtC,EAAqE,CAAC,cAAD,CAArE,CAAvB;EACA,MAAM,GAAG,GAAG,MAAM,CAAI,IAAJ,CAAlB;EACA,SAAS,CAAC,MAAK;IACb,IAAI,OAAJ,EAAa;MACX,mBAAmB,CAAC,GAAD,EAAM,sBAAN,EAA8B,OAAO,CAAC,wBAAR,EAA9B,CAAnB;;MACA,MAAM,EAAE,GAAoB,IAAI,IAAG;QACjC,mBAAmB,CAAC,GAAD,EAAM,sBAAN,EAA8B,IAA9B,CAAnB;MACD,CAFD;;MAGA,OAAO,CAAC,SAAR,CAAkB,EAAlB;MACA,OAAO,MAAM,OAAO,CAAC,WAAR,CAAoB,EAApB,CAAb;IACD;EACF,CATQ,EASN,CAAC,OAAD,CATM,CAAT;EAUA,OAAO,GAAP;AACD;;AAED,SAAS,mBAAT,CAA6B,UAA7B,EAAiE,SAAjE,EAAoF,KAApF,EAAkG;EAChG,IAAI,CAAC,UAAU,CAAC,OAAhB,EAAyB;IACvB;EACD;;EACD,IAAI,KAAJ,EAAW;IACT,UAAU,CAAC,OAAX,CAAmB,YAAnB,CAAgC,SAAhC,EAA2C,EAA3C;EACD,CAFD,MAEO;IACL,UAAU,CAAC,OAAX,CAAmB,eAAnB,CAAmC,SAAnC;EACD;AACF","sourcesContent":["import { createKeyborg } from 'keyborg';\nimport { useEffect, useMemo, useRef } from 'react';\nimport { KEYBOARD_NAV_ATTRIBUTE } from '../focus/constants';\nimport { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\nimport type { KeyborgCallback } from 'keyborg
|
1
|
+
{"version":3,"sources":["hooks/useKeyboardNavAttribute.ts"],"names":[],"mappings":"AAAA,SAAS,aAAT,QAA8B,SAA9B;AACA,SAAS,SAAT,EAAoB,OAApB,EAA6B,MAA7B,QAA2C,OAA3C;AACA,SAAS,sBAAT,QAAuC,oBAAvC;AACA,SAAS,kBAAkB,IAAI,SAA/B,QAAgD,iCAAhD;AAIA;;;;AAIG;;AACH,OAAM,SAAU,uBAAV,GAAiC;EACrC,MAAM;IAAE;EAAF,IAAqB,SAAS,EAApC;EACA,MAAM,OAAO,GAAG,OAAO,CAAC,MAAM,cAAc,IAAI,aAAa,CAAC,cAAc,CAAC,WAAhB,CAAtC,EAAqE,CAAC,cAAD,CAArE,CAAvB;EACA,MAAM,GAAG,GAAG,MAAM,CAAI,IAAJ,CAAlB;EACA,SAAS,CAAC,MAAK;IACb,IAAI,OAAJ,EAAa;MACX,mBAAmB,CAAC,GAAD,EAAM,sBAAN,EAA8B,OAAO,CAAC,wBAAR,EAA9B,CAAnB;;MACA,MAAM,EAAE,GAAoB,IAAI,IAAG;QACjC,mBAAmB,CAAC,GAAD,EAAM,sBAAN,EAA8B,IAA9B,CAAnB;MACD,CAFD;;MAGA,OAAO,CAAC,SAAR,CAAkB,EAAlB;MACA,OAAO,MAAM,OAAO,CAAC,WAAR,CAAoB,EAApB,CAAb;IACD;EACF,CATQ,EASN,CAAC,OAAD,CATM,CAAT;EAUA,OAAO,GAAP;AACD;;AAED,SAAS,mBAAT,CAA6B,UAA7B,EAAiE,SAAjE,EAAoF,KAApF,EAAkG;EAChG,IAAI,CAAC,UAAU,CAAC,OAAhB,EAAyB;IACvB;EACD;;EACD,IAAI,KAAJ,EAAW;IACT,UAAU,CAAC,OAAX,CAAmB,YAAnB,CAAgC,SAAhC,EAA2C,EAA3C;EACD,CAFD,MAEO;IACL,UAAU,CAAC,OAAX,CAAmB,eAAnB,CAAmC,SAAnC;EACD;AACF","sourcesContent":["import { createKeyborg } from 'keyborg';\nimport { useEffect, useMemo, useRef } from 'react';\nimport { KEYBOARD_NAV_ATTRIBUTE } from '../focus/constants';\nimport { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\nimport type { KeyborgCallback } from 'keyborg';\nimport type { RefObject } from 'react';\n\n/**\n * Instantiates [keyborg](https://github.com/microsoft/keyborg) and adds `data-keyboard-nav`\n * attribute to a referenced element to ensure keyboard navigation awareness\n * synced to keyborg logic without having to cause a re-render on react tree.\n */\nexport function useKeyboardNavAttribute<E extends HTMLElement>() {\n const { targetDocument } = useFluent();\n const keyborg = useMemo(() => targetDocument && createKeyborg(targetDocument.defaultView!), [targetDocument]);\n const ref = useRef<E>(null);\n useEffect(() => {\n if (keyborg) {\n setBooleanAttribute(ref, KEYBOARD_NAV_ATTRIBUTE, keyborg.isNavigatingWithKeyboard());\n const cb: KeyborgCallback = next => {\n setBooleanAttribute(ref, KEYBOARD_NAV_ATTRIBUTE, next);\n };\n keyborg.subscribe(cb);\n return () => keyborg.unsubscribe(cb);\n }\n }, [keyborg]);\n return ref;\n}\n\nfunction setBooleanAttribute(elementRef: RefObject<HTMLElement>, attribute: string, value: boolean) {\n if (!elementRef.current) {\n return;\n }\n if (value) {\n elementRef.current.setAttribute(attribute, '');\n } else {\n elementRef.current.removeAttribute(attribute);\n }\n}\n"],"sourceRoot":"../src/"}
|