@fluentui/react-tabster 0.0.0-nightly-20220715-0418.1 → 0.0.0-nightly-20221007-1528.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 +139 -10
- package/CHANGELOG.md +47 -8
- package/dist/index.d.ts +22 -1
- package/lib/focus/constants.js +10 -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/createFocusOutlineStyle.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/useFocusFinders.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/useFocusableGroup.js.map +1 -1
- package/lib/hooks/useKeyboardNavAttribute.js.map +1 -1
- package/lib/hooks/useModalAttributes.js.map +1 -1
- package/lib/hooks/useTabster.js +20 -13
- package/lib/hooks/useTabster.js.map +1 -1
- package/lib/hooks/useTabsterAttributes.js.map +1 -1
- package/lib/index.js +2 -1
- package/lib/index.js.map +1 -1
- package/lib-commonjs/focus/constants.js +11 -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/createFocusOutlineStyle.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/useFocusFinders.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/useFocusableGroup.js.map +1 -1
- package/lib-commonjs/hooks/useKeyboardNavAttribute.js.map +1 -1
- package/lib-commonjs/hooks/useModalAttributes.js.map +1 -1
- package/lib-commonjs/hooks/useTabster.js +22 -13
- package/lib-commonjs/hooks/useTabster.js.map +1 -1
- package/lib-commonjs/hooks/useTabsterAttributes.js.map +1 -1
- package/lib-commonjs/index.js +22 -1
- package/lib-commonjs/index.js.map +1 -1
- package/package.json +12 -16
- package/dist/tsdoc-metadata.json +0 -11
package/CHANGELOG.json
CHANGED
@@ -2,13 +2,13 @@
|
|
2
2
|
"name": "@fluentui/react-tabster",
|
3
3
|
"entries": [
|
4
4
|
{
|
5
|
-
"date": "Fri,
|
6
|
-
"tag": "@fluentui/react-tabster_v0.0.0-nightly-
|
7
|
-
"version": "0.0.0-nightly-
|
5
|
+
"date": "Fri, 07 Oct 2022 15:35:00 GMT",
|
6
|
+
"tag": "@fluentui/react-tabster_v0.0.0-nightly-20221007-1528.1",
|
7
|
+
"version": "0.0.0-nightly-20221007-1528.1",
|
8
8
|
"comments": {
|
9
9
|
"prerelease": [
|
10
10
|
{
|
11
|
-
"author": "
|
11
|
+
"author": "fluentui-internal@service.microsoft.com",
|
12
12
|
"package": "@fluentui/react-tabster",
|
13
13
|
"commit": "not available",
|
14
14
|
"comment": "Release nightly v9"
|
@@ -16,20 +16,149 @@
|
|
16
16
|
{
|
17
17
|
"author": "beachball",
|
18
18
|
"package": "@fluentui/react-tabster",
|
19
|
-
"comment": "Bump @fluentui/react-shared-contexts to v0.0.0-nightly-
|
20
|
-
"commit": "
|
19
|
+
"comment": "Bump @fluentui/react-shared-contexts to v0.0.0-nightly-20221007-1528.1",
|
20
|
+
"commit": "827197046ec2b195a8997fadbb514a5693234e6b"
|
21
21
|
},
|
22
22
|
{
|
23
23
|
"author": "beachball",
|
24
24
|
"package": "@fluentui/react-tabster",
|
25
|
-
"comment": "Bump @fluentui/react-theme to v0.0.0-nightly-
|
26
|
-
"commit": "
|
25
|
+
"comment": "Bump @fluentui/react-theme to v0.0.0-nightly-20221007-1528.1",
|
26
|
+
"commit": "827197046ec2b195a8997fadbb514a5693234e6b"
|
27
27
|
},
|
28
28
|
{
|
29
29
|
"author": "beachball",
|
30
30
|
"package": "@fluentui/react-tabster",
|
31
|
-
"comment": "Bump @fluentui/react-utilities to v0.0.0-nightly-
|
32
|
-
"commit": "
|
31
|
+
"comment": "Bump @fluentui/react-utilities to v0.0.0-nightly-20221007-1528.1",
|
32
|
+
"commit": "827197046ec2b195a8997fadbb514a5693234e6b"
|
33
|
+
}
|
34
|
+
]
|
35
|
+
}
|
36
|
+
},
|
37
|
+
{
|
38
|
+
"date": "Mon, 03 Oct 2022 22:24:41 GMT",
|
39
|
+
"tag": "@fluentui/react-tabster_v9.1.2",
|
40
|
+
"version": "9.1.2",
|
41
|
+
"comments": {
|
42
|
+
"patch": [
|
43
|
+
{
|
44
|
+
"author": "lingfangao@hotmail.com",
|
45
|
+
"package": "@fluentui/react-tabster",
|
46
|
+
"commit": "5129090c2dedbaf91b8441898788413992c556e3",
|
47
|
+
"comment": "fix: focus outline selectors are data attributes"
|
48
|
+
}
|
49
|
+
]
|
50
|
+
}
|
51
|
+
},
|
52
|
+
{
|
53
|
+
"date": "Thu, 15 Sep 2022 09:49:31 GMT",
|
54
|
+
"tag": "@fluentui/react-tabster_v9.1.1",
|
55
|
+
"version": "9.1.1",
|
56
|
+
"comments": {
|
57
|
+
"patch": [
|
58
|
+
{
|
59
|
+
"author": "lingfangao@hotmail.com",
|
60
|
+
"package": "@fluentui/react-tabster",
|
61
|
+
"commit": "e4d50f2c501c4a8be23b24373242f650a601fdaf",
|
62
|
+
"comment": "fix: Remove provider classname from focus styles"
|
63
|
+
},
|
64
|
+
{
|
65
|
+
"author": "lingfangao@hotmail.com",
|
66
|
+
"package": "@fluentui/react-tabster",
|
67
|
+
"commit": "e2b71230d03f2cf03eff3cda02484dfcb72e9c51",
|
68
|
+
"comment": "fix: Bumps tabster to 2.1.2 and removes deep import for KeyborgCallback"
|
69
|
+
},
|
70
|
+
{
|
71
|
+
"author": "lingfangao@hotmail.com",
|
72
|
+
"package": "@fluentui/react-tabster",
|
73
|
+
"commit": "f1f4ab4ac21226c8f6729ca263ca09c1ec9b76f2",
|
74
|
+
"comment": "chore: Exports `applyFocusVisible` as internal"
|
75
|
+
},
|
76
|
+
{
|
77
|
+
"author": "olfedias@microsoft.com",
|
78
|
+
"package": "@fluentui/react-tabster",
|
79
|
+
"commit": "e610024474cfe5d45f61501a8b6a21daf4c794a2",
|
80
|
+
"comment": "chore: Update Griffel to latest version"
|
81
|
+
},
|
82
|
+
{
|
83
|
+
"author": "beachball",
|
84
|
+
"package": "@fluentui/react-tabster",
|
85
|
+
"comment": "Bump @fluentui/react-shared-contexts to v9.0.1",
|
86
|
+
"commit": "a33448fe4a0f4117686c378f80b893d1406d95a8"
|
87
|
+
},
|
88
|
+
{
|
89
|
+
"author": "beachball",
|
90
|
+
"package": "@fluentui/react-tabster",
|
91
|
+
"comment": "Bump @fluentui/react-theme to v9.1.0",
|
92
|
+
"commit": "a33448fe4a0f4117686c378f80b893d1406d95a8"
|
93
|
+
},
|
94
|
+
{
|
95
|
+
"author": "beachball",
|
96
|
+
"package": "@fluentui/react-tabster",
|
97
|
+
"comment": "Bump @fluentui/react-utilities to v9.1.0",
|
98
|
+
"commit": "a33448fe4a0f4117686c378f80b893d1406d95a8"
|
99
|
+
}
|
100
|
+
],
|
101
|
+
"none": [
|
102
|
+
{
|
103
|
+
"author": "martinhochel@microsoft.com",
|
104
|
+
"package": "@fluentui/react-tabster",
|
105
|
+
"commit": "ba9444d594f3a960cc590eae5237c08bf7c5a07f",
|
106
|
+
"comment": "chore: consume cypress.config from it's package boundary"
|
107
|
+
},
|
108
|
+
{
|
109
|
+
"author": "martinhochel@microsoft.com",
|
110
|
+
"package": "@fluentui/react-tabster",
|
111
|
+
"commit": "16aa65dcae8f75c6a221225fd0eb43800650ac66",
|
112
|
+
"comment": "docs: re-generate api.md files"
|
113
|
+
},
|
114
|
+
{
|
115
|
+
"author": "martinhochel@microsoft.com",
|
116
|
+
"package": "@fluentui/react-tabster",
|
117
|
+
"commit": "e6cf183695d6d67a24e038c49a876224e5ed35e5",
|
118
|
+
"comment": "chore: update package scaffold"
|
119
|
+
}
|
120
|
+
]
|
121
|
+
}
|
122
|
+
},
|
123
|
+
{
|
124
|
+
"date": "Wed, 03 Aug 2022 16:04:04 GMT",
|
125
|
+
"tag": "@fluentui/react-tabster_v9.1.0",
|
126
|
+
"version": "9.1.0",
|
127
|
+
"comments": {
|
128
|
+
"patch": [
|
129
|
+
{
|
130
|
+
"author": "lingfangao@hotmail.com",
|
131
|
+
"package": "@fluentui/react-tabster",
|
132
|
+
"commit": "b9e6c6a7dd8ce6111744739a0ec486b99c2bb2ea",
|
133
|
+
"comment": "chore: Bump tabster to 2.1.0"
|
134
|
+
},
|
135
|
+
{
|
136
|
+
"author": "miroslav.stastny@microsoft.com",
|
137
|
+
"package": "@fluentui/react-tabster",
|
138
|
+
"commit": "08563664778fd80284561d3c9d254307a0a32362",
|
139
|
+
"comment": "chore: Bump Griffel dependencies"
|
140
|
+
}
|
141
|
+
],
|
142
|
+
"minor": [
|
143
|
+
{
|
144
|
+
"author": "lingfangao@hotmail.com",
|
145
|
+
"package": "@fluentui/react-tabster",
|
146
|
+
"commit": "2756c649a83c0fa0a20b82c62855d388a5e6bc2a",
|
147
|
+
"comment": "feat: Adds `ignoreDefaultKeydown` option to `useArrowNavigationGroup`"
|
148
|
+
},
|
149
|
+
{
|
150
|
+
"author": "lingfangao@hotmail.com",
|
151
|
+
"package": "@fluentui/react-tabster",
|
152
|
+
"commit": "71590ea6aeab8ce24d8c8e50e0ee80ece81a4392",
|
153
|
+
"comment": "feat: create `:focus-visible` and `:focus-within` polyfills"
|
154
|
+
}
|
155
|
+
],
|
156
|
+
"none": [
|
157
|
+
{
|
158
|
+
"author": "lingfangao@hotmail.com",
|
159
|
+
"package": "@fluentui/react-tabster",
|
160
|
+
"commit": "99cc385631d04a76ee10ebc143cb9fecd99640b6",
|
161
|
+
"comment": "chore: Add `prerelease` as disallowed changetype for 9.0.0 packages"
|
33
162
|
}
|
34
163
|
]
|
35
164
|
}
|
package/CHANGELOG.md
CHANGED
@@ -1,20 +1,59 @@
|
|
1
1
|
# Change Log - @fluentui/react-tabster
|
2
2
|
|
3
|
-
This log was last generated on Fri,
|
3
|
+
This log was last generated on Fri, 07 Oct 2022 15:35:00 GMT and should not be manually modified.
|
4
4
|
|
5
5
|
<!-- Start content -->
|
6
6
|
|
7
|
-
## [0.0.0-nightly-
|
7
|
+
## [0.0.0-nightly-20221007-1528.1](https://github.com/microsoft/fluentui/tree/@fluentui/react-tabster_v0.0.0-nightly-20221007-1528.1)
|
8
8
|
|
9
|
-
Fri,
|
10
|
-
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-tabster_v9.
|
9
|
+
Fri, 07 Oct 2022 15:35:00 GMT
|
10
|
+
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-tabster_v9.1.2..@fluentui/react-tabster_v0.0.0-nightly-20221007-1528.1)
|
11
11
|
|
12
12
|
### Changes
|
13
13
|
|
14
|
-
- Release nightly v9 ([commit](https://github.com/microsoft/fluentui/commit/not available) by
|
15
|
-
- Bump @fluentui/react-shared-contexts to v0.0.0-nightly-
|
16
|
-
- Bump @fluentui/react-theme to v0.0.0-nightly-
|
17
|
-
- Bump @fluentui/react-utilities to v0.0.0-nightly-
|
14
|
+
- Release nightly v9 ([commit](https://github.com/microsoft/fluentui/commit/not available) by fluentui-internal@service.microsoft.com)
|
15
|
+
- Bump @fluentui/react-shared-contexts to v0.0.0-nightly-20221007-1528.1 ([commit](https://github.com/microsoft/fluentui/commit/827197046ec2b195a8997fadbb514a5693234e6b) by beachball)
|
16
|
+
- Bump @fluentui/react-theme to v0.0.0-nightly-20221007-1528.1 ([commit](https://github.com/microsoft/fluentui/commit/827197046ec2b195a8997fadbb514a5693234e6b) by beachball)
|
17
|
+
- Bump @fluentui/react-utilities to v0.0.0-nightly-20221007-1528.1 ([commit](https://github.com/microsoft/fluentui/commit/827197046ec2b195a8997fadbb514a5693234e6b) by beachball)
|
18
|
+
|
19
|
+
## [9.1.2](https://github.com/microsoft/fluentui/tree/@fluentui/react-tabster_v9.1.2)
|
20
|
+
|
21
|
+
Mon, 03 Oct 2022 22:24:41 GMT
|
22
|
+
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-tabster_v9.1.1..@fluentui/react-tabster_v9.1.2)
|
23
|
+
|
24
|
+
### Patches
|
25
|
+
|
26
|
+
- fix: focus outline selectors are data attributes ([PR #24994](https://github.com/microsoft/fluentui/pull/24994) by lingfangao@hotmail.com)
|
27
|
+
|
28
|
+
## [9.1.1](https://github.com/microsoft/fluentui/tree/@fluentui/react-tabster_v9.1.1)
|
29
|
+
|
30
|
+
Thu, 15 Sep 2022 09:49:31 GMT
|
31
|
+
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-tabster_v9.1.0..@fluentui/react-tabster_v9.1.1)
|
32
|
+
|
33
|
+
### Patches
|
34
|
+
|
35
|
+
- fix: Remove provider classname from focus styles ([PR #24710](https://github.com/microsoft/fluentui/pull/24710) by lingfangao@hotmail.com)
|
36
|
+
- 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)
|
37
|
+
- chore: Exports `applyFocusVisible` as internal ([PR #24712](https://github.com/microsoft/fluentui/pull/24712) by lingfangao@hotmail.com)
|
38
|
+
- chore: Update Griffel to latest version ([PR #24221](https://github.com/microsoft/fluentui/pull/24221) by olfedias@microsoft.com)
|
39
|
+
- Bump @fluentui/react-shared-contexts to v9.0.1 ([PR #24808](https://github.com/microsoft/fluentui/pull/24808) by beachball)
|
40
|
+
- Bump @fluentui/react-theme to v9.1.0 ([PR #24808](https://github.com/microsoft/fluentui/pull/24808) by beachball)
|
41
|
+
- Bump @fluentui/react-utilities to v9.1.0 ([PR #24808](https://github.com/microsoft/fluentui/pull/24808) by beachball)
|
42
|
+
|
43
|
+
## [9.1.0](https://github.com/microsoft/fluentui/tree/@fluentui/react-tabster_v9.1.0)
|
44
|
+
|
45
|
+
Wed, 03 Aug 2022 16:04:04 GMT
|
46
|
+
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-tabster_v9.0.3..@fluentui/react-tabster_v9.1.0)
|
47
|
+
|
48
|
+
### Minor changes
|
49
|
+
|
50
|
+
- feat: Adds `ignoreDefaultKeydown` option to `useArrowNavigationGroup` ([PR #24101](https://github.com/microsoft/fluentui/pull/24101) by lingfangao@hotmail.com)
|
51
|
+
- feat: create `:focus-visible` and `:focus-within` polyfills ([PR #24154](https://github.com/microsoft/fluentui/pull/24154) by lingfangao@hotmail.com)
|
52
|
+
|
53
|
+
### Patches
|
54
|
+
|
55
|
+
- chore: Bump tabster to 2.1.0 ([PR #23811](https://github.com/microsoft/fluentui/pull/23811) by lingfangao@hotmail.com)
|
56
|
+
- chore: Bump Griffel dependencies ([PR #24114](https://github.com/microsoft/fluentui/pull/24114) by miroslav.stastny@microsoft.com)
|
18
57
|
|
19
58
|
## [9.0.3](https://github.com/microsoft/fluentui/tree/@fluentui/react-tabster_v9.0.3)
|
20
59
|
|
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,15 @@
|
|
1
1
|
export const KEYBOARD_NAV_ATTRIBUTE = 'data-keyboard-nav';
|
2
2
|
export const KEYBOARD_NAV_SELECTOR = `:global([${KEYBOARD_NAV_ATTRIBUTE}])`;
|
3
|
+
/**
|
4
|
+
* @internal
|
5
|
+
*/
|
6
|
+
|
7
|
+
export const FOCUS_VISIBLE_ATTR = 'data-fui-focus-visible';
|
8
|
+
/**
|
9
|
+
* @internal
|
10
|
+
*/
|
11
|
+
|
12
|
+
export const FOCUS_WITHIN_ATTR = 'data-fui-focus-visible';
|
3
13
|
export const defaultOptions = {
|
4
14
|
style: {},
|
5
15
|
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":"
|
1
|
+
{"version":3,"sources":["../../src/focus/constants.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,sBAAsB,GAAG,mBAA/B;AACP,OAAO,MAAM,qBAAqB,GAAG,YAAY,sBAAsB,IAAhE;AAEP;;AAEG;;AACH,OAAO,MAAM,kBAAkB,GAAG,wBAA3B;AAEP;;AAEG;;AACH,OAAO,MAAM,iBAAiB,GAAG,wBAA1B;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;\n\n/**\n * @internal\n */\nexport const FOCUS_VISIBLE_ATTR = 'data-fui-focus-visible';\n\n/**\n * @internal\n */\nexport const FOCUS_WITHIN_ATTR = 'data-fui-focus-visible';\nexport const defaultOptions = {\n style: {},\n selector: 'focus',\n} as const;\n"],"sourceRoot":""}
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import {
|
1
|
+
import { defaultOptions, FOCUS_VISIBLE_ATTR, FOCUS_WITHIN_ATTR } 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_ATTR}]`]: style
|
21
|
+
}),
|
22
|
+
...(selector === 'focus-within' && {
|
23
|
+
[`&[${FOCUS_WITHIN_ATTR}]:${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":["../../src/focus/createCustomFocusIndicatorStyle.ts"],"names":[],"mappings":"AAAA,SAAS,cAAT,EAAyB,kBAAzB,EAA6C,iBAA7C,QAAsE,aAAtE;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,kBAAkB,GAAxB,GAA8B;EADJ,CAA5B,CARkB;EAWlB,IAAI,QAAQ,KAAK,cAAb,IAA+B;IACjC,CAAC,KAAK,iBAAiB,KAAK,QAAQ,EAApC,GAAyC;EADR,CAAnC;AAXkB,CAH2B,CAAxC","sourcesContent":["import { defaultOptions, FOCUS_VISIBLE_ATTR, FOCUS_WITHIN_ATTR } 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_ATTR}]`]: style,\n }),\n ...(selector === 'focus-within' && {\n [`&[${FOCUS_WITHIN_ATTR}]:${selector}`]: style,\n }),\n});\n"],"sourceRoot":""}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["focus/createFocusOutlineStyle.ts"],"names":[],"mappings":"AAAA,SAAS,MAAT,QAAuB,uBAAvB;AACA,SAAS,UAAT,QAA2B,gBAA3B;AAEA,SACE,+BADF,QAGO,mCAHP;AAIA,SAAS,cAAT,QAA+B,aAA/B;AAiBA;;;;;;AAMG;;AACH,MAAM,qBAAqB,GAAI,OAAD,IAAoD;;;EAChF,MAAM;IAAE,aAAF;IAAiB,YAAjB;IAA+B,aAA/B;IAA8C;EAA9C,IAA+D,OAArE;EAEA,MAAM,gBAAgB,GAAG,CAAA,CAAA,EAAA,GAAC,aAAD,MAAqC,IAArC,IAAqC,EAAA,KAAA,KAAA,CAArC,GAAqC,KAAA,CAArC,GAAqC,EAAA,CAAE,GAAvC,KAA8C,aAAvE;EACA,MAAM,mBAAmB,GAAG,CAAA,CAAA,EAAA,GAAC,aAAD,MAAqC,IAArC,IAAqC,EAAA,KAAA,KAAA,CAArC,GAAqC,KAAA,CAArC,GAAqC,EAAA,CAAE,MAAvC,KAAiD,aAA7E;EACA,MAAM,iBAAiB,GAAG,CAAA,CAAA,EAAA,GAAC,aAAD,MAAqC,IAArC,IAAqC,EAAA,KAAA,KAAA,CAArC,GAAqC,KAAA,CAArC,GAAqC,EAAA,CAAE,IAAvC,KAA+C,aAAzE;EACA,MAAM,kBAAkB,GAAG,CAAA,CAAA,EAAA,GAAC,aAAD,MAAqC,IAArC,IAAqC,EAAA,KAAA,KAAA,CAArC,GAAqC,KAAA,CAArC,GAAqC,EAAA,CAAE,KAAvC,KAAgD,aAA3E;EAEA,OAAO,EACL,GAAG,UAAU,CAAC,WAAX,CAAuB,aAAvB,CADE;IAEL,WAAW;MACT,OAAO,EAAE,IADA;MAET,QAAQ,EAAE,UAFD;MAGT,aAAa,EAAE,MAHN;MAIT,MAAM,EAAE,CAJC;MAMT,GAAG,UAAU,CAAC,WAAX,CAAuB,OAAvB,CANM;MAOT,GAAG,UAAU,CAAC,WAAX,CAAuB,YAAvB,CAPM;MAQT,GAAG,UAAU,CAAC,YAAX,CAAwB,aAAxB,CARM;MAST,GAAG,UAAU,CAAC,WAAX,CAAuB,YAAvB,CATM;MAWT,GAAG,EAAE,CAAC,aAAD,GAAiB,IAAI,YAAY,EAAjC,GAAsC,cAAc,YAAY,MAAM,gBAAgB,GAXlF;MAYT,MAAM,EAAE,CAAC,aAAD,GAAiB,IAAI,YAAY,EAAjC,GAAsC,cAAc,YAAY,MAAM,mBAAmB,GAZxF;MAaT,IAAI,EAAE,CAAC,aAAD,GAAiB,IAAI,YAAY,EAAjC,GAAsC,cAAc,YAAY,MAAM,iBAAiB,GAbpF;MAcT,KAAK,EAAE,CAAC,aAAD,GAAiB,IAAI,YAAY,EAAjC,GAAsC,cAAc,YAAY,MAAM,kBAAkB;IAdtF;EAFN,CAAP;AAmBD,CA3BD;AA6BA;;;;;;AAMG;;;AACH,OAAO,MAAM,uBAAuB,GAAG,CAAC;EACtC,QAAQ,GAAG,cAAc,CAAC,QADY;EAEtC,KAAK,GAAG,cAAc,CAAC;AAFe,IAGJ,cAHG,KAIrC,+BAA+B,CAC7B,qBAAqB,CAAC;EACpB,YAAY,EAAE,MAAM,CAAC,iBADD;EAEpB,aAAa,EAAE,MAAM,CAAC,kBAFF;EAGpB;EACA,YAAY,EAAE,KAJM;EAKpB,GAAG;AALiB,CAAD,CADQ,EAQ7B;EAAE;AAAF,CAR6B,CAJ1B","sourcesContent":["import { tokens } from '@fluentui/react-theme';\nimport { shorthands } from '@griffel/react';\nimport type { GriffelStyle } from '@griffel/react';\nimport {\n createCustomFocusIndicatorStyle,\n CreateCustomFocusIndicatorStyleOptions,\n} from './createCustomFocusIndicatorStyle';\nimport { defaultOptions } from './constants';\n\nexport type FocusOutlineOffset = Record<'top' | 'bottom' | 'left' | 'right', string>;\nexport type FocusOutlineStyleOptions = {\n /**\n * Only property not supported by the native CSS `outline`, if this is no longer needed\n * we can just go native instead\n */\n outlineRadius: string;\n outlineColor: string;\n outlineWidth: string;\n outlineOffset?: string | FocusOutlineOffset;\n};\nexport interface CreateFocusOutlineStyleOptions extends CreateCustomFocusIndicatorStyleOptions {\n style?: Partial<FocusOutlineStyleOptions>;\n}\n\n/**\n * NOTE: the element with the focus outline needs to have `position: relative` so that the\n * pseudo element can be properly positioned.\n *\n * @param options - Configures the style of the focus outline\n * @returns focus outline styles object\n */\nconst getFocusOutlineStyles = (options: FocusOutlineStyleOptions): GriffelStyle => {\n const { outlineRadius, outlineColor, outlineOffset, outlineWidth } = options;\n\n const outlineOffsetTop = (outlineOffset as FocusOutlineOffset)?.top || outlineOffset;\n const outlineOffsetBottom = (outlineOffset as FocusOutlineOffset)?.bottom || outlineOffset;\n const outlineOffsetLeft = (outlineOffset as FocusOutlineOffset)?.left || outlineOffset;\n const outlineOffsetRight = (outlineOffset as FocusOutlineOffset)?.right || outlineOffset;\n\n return {\n ...shorthands.borderColor('transparent'),\n '::after': {\n content: '\"\"',\n position: 'absolute',\n pointerEvents: 'none',\n zIndex: 1,\n\n ...shorthands.borderStyle('solid'),\n ...shorthands.borderWidth(outlineWidth),\n ...shorthands.borderRadius(outlineRadius),\n ...shorthands.borderColor(outlineColor),\n\n top: !outlineOffset ? `-${outlineWidth}` : `calc(0px - ${outlineWidth} - ${outlineOffsetTop})`,\n bottom: !outlineOffset ? `-${outlineWidth}` : `calc(0px - ${outlineWidth} - ${outlineOffsetBottom})`,\n left: !outlineOffset ? `-${outlineWidth}` : `calc(0px - ${outlineWidth} - ${outlineOffsetLeft})`,\n right: !outlineOffset ? `-${outlineWidth}` : `calc(0px - ${outlineWidth} - ${outlineOffsetRight})`,\n },\n };\n};\n\n/**\n * NOTE: The element with the focus outline needs to have `position: relative` so that the\n * pseudo element can be properly positioned.\n *\n * @param options - Configure the style of the focus outline\n * @returns focus outline styles object for @see makeStyles\n */\nexport const createFocusOutlineStyle = ({\n selector = defaultOptions.selector,\n style = defaultOptions.style,\n}: CreateFocusOutlineStyleOptions = defaultOptions): GriffelStyle =>\n createCustomFocusIndicatorStyle(\n getFocusOutlineStyles({\n outlineColor: tokens.colorStrokeFocus2,\n outlineRadius: tokens.borderRadiusMedium,\n // FIXME: tokens.strokeWidthThick causes some weird bugs\n outlineWidth: '2px',\n ...style,\n }),\n { selector },\n );\n"],"sourceRoot":"
|
1
|
+
{"version":3,"sources":["../../src/focus/createFocusOutlineStyle.ts"],"names":[],"mappings":"AAAA,SAAS,MAAT,QAAuB,uBAAvB;AACA,SAAS,UAAT,QAA2B,gBAA3B;AAEA,SACE,+BADF,QAGO,mCAHP;AAIA,SAAS,cAAT,QAA+B,aAA/B;AAiBA;;;;;;AAMG;;AACH,MAAM,qBAAqB,GAAI,OAAD,IAAoD;;;EAChF,MAAM;IAAE,aAAF;IAAiB,YAAjB;IAA+B,aAA/B;IAA8C;EAA9C,IAA+D,OAArE;EAEA,MAAM,gBAAgB,GAAG,CAAA,CAAA,EAAA,GAAC,aAAD,MAAqC,IAArC,IAAqC,EAAA,KAAA,KAAA,CAArC,GAAqC,KAAA,CAArC,GAAqC,EAAA,CAAE,GAAvC,KAA8C,aAAvE;EACA,MAAM,mBAAmB,GAAG,CAAA,CAAA,EAAA,GAAC,aAAD,MAAqC,IAArC,IAAqC,EAAA,KAAA,KAAA,CAArC,GAAqC,KAAA,CAArC,GAAqC,EAAA,CAAE,MAAvC,KAAiD,aAA7E;EACA,MAAM,iBAAiB,GAAG,CAAA,CAAA,EAAA,GAAC,aAAD,MAAqC,IAArC,IAAqC,EAAA,KAAA,KAAA,CAArC,GAAqC,KAAA,CAArC,GAAqC,EA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pB;EACA,YAAY,EAAE,KAJM;EAKpB,GAAG;AALiB,CAAD,CADQ,EAQ7B;EAAE;AAAF,CAR6B,CAJ1B","sourcesContent":["import { tokens } from '@fluentui/react-theme';\nimport { shorthands } from '@griffel/react';\nimport type { GriffelStyle } from '@griffel/react';\nimport {\n createCustomFocusIndicatorStyle,\n CreateCustomFocusIndicatorStyleOptions,\n} from './createCustomFocusIndicatorStyle';\nimport { defaultOptions } from './constants';\n\nexport type FocusOutlineOffset = Record<'top' | 'bottom' | 'left' | 'right', string>;\nexport type FocusOutlineStyleOptions = {\n /**\n * Only property not supported by the native CSS `outline`, if this is no longer needed\n * we can just go native instead\n */\n outlineRadius: string;\n outlineColor: string;\n outlineWidth: string;\n outlineOffset?: string | FocusOutlineOffset;\n};\nexport interface CreateFocusOutlineStyleOptions extends CreateCustomFocusIndicatorStyleOptions {\n style?: Partial<FocusOutlineStyleOptions>;\n}\n\n/**\n * NOTE: the element with the focus outline needs to have `position: relative` so that the\n * pseudo element can be properly positioned.\n *\n * @param options - Configures the style of the focus outline\n * @returns focus outline styles object\n */\nconst getFocusOutlineStyles = (options: FocusOutlineStyleOptions): GriffelStyle => {\n const { outlineRadius, outlineColor, outlineOffset, outlineWidth } = options;\n\n const outlineOffsetTop = (outlineOffset as FocusOutlineOffset)?.top || outlineOffset;\n const outlineOffsetBottom = (outlineOffset as FocusOutlineOffset)?.bottom || outlineOffset;\n const outlineOffsetLeft = (outlineOffset as FocusOutlineOffset)?.left || outlineOffset;\n const outlineOffsetRight = (outlineOffset as FocusOutlineOffset)?.right || outlineOffset;\n\n return {\n ...shorthands.borderColor('transparent'),\n '::after': {\n content: '\"\"',\n position: 'absolute',\n pointerEvents: 'none',\n zIndex: 1,\n\n ...shorthands.borderStyle('solid'),\n ...shorthands.borderWidth(outlineWidth),\n ...shorthands.borderRadius(outlineRadius),\n ...shorthands.borderColor(outlineColor),\n\n top: !outlineOffset ? `-${outlineWidth}` : `calc(0px - ${outlineWidth} - ${outlineOffsetTop})`,\n bottom: !outlineOffset ? `-${outlineWidth}` : `calc(0px - ${outlineWidth} - ${outlineOffsetBottom})`,\n left: !outlineOffset ? `-${outlineWidth}` : `calc(0px - ${outlineWidth} - ${outlineOffsetLeft})`,\n right: !outlineOffset ? `-${outlineWidth}` : `calc(0px - ${outlineWidth} - ${outlineOffsetRight})`,\n },\n };\n};\n\n/**\n * NOTE: The element with the focus outline needs to have `position: relative` so that the\n * pseudo element can be properly positioned.\n *\n * @param options - Configure the style of the focus outline\n * @returns focus outline styles object for @see makeStyles\n */\nexport const createFocusOutlineStyle = ({\n selector = defaultOptions.selector,\n style = defaultOptions.style,\n}: CreateFocusOutlineStyleOptions = defaultOptions): GriffelStyle =>\n createCustomFocusIndicatorStyle(\n getFocusOutlineStyles({\n outlineColor: tokens.colorStrokeFocus2,\n outlineRadius: tokens.borderRadiusMedium,\n // FIXME: tokens.strokeWidthThick causes some weird bugs\n outlineWidth: '2px',\n ...style,\n }),\n { selector },\n );\n"],"sourceRoot":""}
|
@@ -0,0 +1,90 @@
|
|
1
|
+
import { KEYBORG_FOCUSIN, createKeyborg, disposeKeyborg } from 'keyborg';
|
2
|
+
import { FOCUS_VISIBLE_ATTR } 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.setAttribute(FOCUS_VISIBLE_ATTR, '');
|
65
|
+
}
|
66
|
+
|
67
|
+
function removeFocusVisibleClass(el) {
|
68
|
+
el.removeAttribute(FOCUS_VISIBLE_ATTR);
|
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":["../../src/focus/focusVisiblePolyfill.ts"],"names":[],"mappings":"AAAA,SAAS,eAAT,EAA+C,aAA/C,EAA8D,cAA9D,QAAoF,SAApF;AACA,SAAS,kBAAT,QAAmC,aAAnC;AAoBA;;;;AAIG;;AACH,OAAM,SAAU,yBAAV,CAAoC,KAApC,EAAwD,GAAxD,EAAmE;EACvE,IAAI,cAAc,CAAC,KAAD,CAAlB,EAA2B;IACzB;IACA,OAAO,MAAM,SAAb;EACD;;EAED,MAAM,KAAK,GAAsB;IAC/B,OAAO,EAAE;EADsB,CAAjC;EAIA,MAAM,OAAO,GAAG,aAAa,CAAC,GAAD,CAA7B,CAVuE,CAYvE;;EACA,OAAO,CAAC,SAAR,CAAkB,wBAAwB,IAAG;IAC3C,IAAI,CAAC,wBAAD,IAA6B,KAAK,CAAC,OAAvC,EAAgD;MAC9C,uBAAuB,CAAC,KAAK,CAAC,OAAP,CAAvB;MACA,KAAK,CAAC,OAAN,GAAgB,SAAhB;IACD;EACF,CALD,EAbuE,CAoBvE;EACA;;EACA,MAAM,eAAe,GAAI,CAAD,IAA2B;IACjD,IAAI,KAAK,CAAC,OAAV,EAAmB;MACjB,uBAAuB,CAAC,KAAK,CAAC,OAAP,CAAvB;MACA,KAAK,CAAC,OAAN,GAAgB,SAAhB;IACD;;IAED,IAAI,OAAO,CAAC,wBAAR,MAAsC,aAAa,CAAC,CAAC,CAAC,MAAH,CAAnD,IAAiE,CAAC,CAAC,MA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D;;AAED,SAAS,cAAT,CAAwB,EAAxB,EAA0D;EACxD,IAAI,CAAC,EAAL,EAAS;IACP,OAAO,KAAP;EACD;;EAED,IAAK,EAAuC,CAAC,YAA7C,EAA2D;IACzD,OAAO,IAAP;EACD;;EAED,OAAO,cAAc,CAAC,EAAE,KAAA,IAAF,IAAA,EAAE,KAAA,KAAA,CAAF,GAAE,KAAA,CAAF,GAAA,EAAE,CAAE,aAAL,CAArB;AACD","sourcesContent":["import { KEYBORG_FOCUSIN, KeyborgFocusInEvent, createKeyborg, disposeKeyborg } from 'keyborg';\nimport { FOCUS_VISIBLE_ATTR } 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.setAttribute(FOCUS_VISIBLE_ATTR, '');\n}\n\nfunction removeFocusVisibleClass(el: HTMLElement) {\n el.removeAttribute(FOCUS_VISIBLE_ATTR);\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":""}
|
@@ -0,0 +1,58 @@
|
|
1
|
+
import { KEYBORG_FOCUSIN, createKeyborg, disposeKeyborg } from 'keyborg';
|
2
|
+
import { FOCUS_WITHIN_ATTR } 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.setAttribute(FOCUS_WITHIN_ATTR, '');
|
45
|
+
}
|
46
|
+
|
47
|
+
function removeFocusWithinClass(el) {
|
48
|
+
el.removeAttribute(FOCUS_WITHIN_ATTR);
|
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
|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,EAAE,CAAC,YAAH,CAAgB,iBAAhB,EAAmC,EAAnC;AACD;;AAED,SAAS,sBAAT,CAAgC,EAAhC,EAA+C;EAC7C,EAAE,CAAC,eAAH,CAAmB,iBAAnB;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_ATTR } 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.setAttribute(FOCUS_WITHIN_ATTR, '');\n}\n\nfunction removeFocusWithinClass(el: HTMLElement) {\n el.removeAttribute(FOCUS_WITHIN_ATTR);\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":""}
|
package/lib/focus/index.js
CHANGED
package/lib/focus/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/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":"
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/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
|
|