@fluentui/react-tabster 0.0.0-nightly-20230427-0418.1 → 0.0.0-nightly-20230501-0418.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 +9 -9
- package/CHANGELOG.md +7 -7
- package/package.json +4 -4
- package/dist/index.d.ts +0 -189
- package/lib/focus/constants.js +0 -15
- package/lib/focus/constants.js.map +0 -1
- package/lib/focus/createCustomFocusIndicatorStyle.js +0 -28
- package/lib/focus/createCustomFocusIndicatorStyle.js.map +0 -1
- package/lib/focus/createFocusOutlineStyle.js +0 -60
- package/lib/focus/createFocusOutlineStyle.js.map +0 -1
- package/lib/focus/focusVisiblePolyfill.js +0 -73
- package/lib/focus/focusVisiblePolyfill.js.map +0 -1
- package/lib/focus/focusWithinPolyfill.js +0 -51
- package/lib/focus/focusWithinPolyfill.js.map +0 -1
- package/lib/focus/index.js +0 -5
- package/lib/focus/index.js.map +0 -1
- package/lib/hooks/index.js +0 -9
- package/lib/hooks/index.js.map +0 -1
- package/lib/hooks/useArrowNavigationGroup.js +0 -50
- package/lib/hooks/useArrowNavigationGroup.js.map +0 -1
- package/lib/hooks/useFocusFinders.js +0 -61
- package/lib/hooks/useFocusFinders.js.map +0 -1
- package/lib/hooks/useFocusVisible.js +0 -16
- package/lib/hooks/useFocusVisible.js.map +0 -1
- package/lib/hooks/useFocusWithin.js +0 -21
- package/lib/hooks/useFocusWithin.js.map +0 -1
- package/lib/hooks/useFocusableGroup.js +0 -31
- package/lib/hooks/useFocusableGroup.js.map +0 -1
- package/lib/hooks/useKeyboardNavAttribute.js +0 -38
- package/lib/hooks/useKeyboardNavAttribute.js.map +0 -1
- package/lib/hooks/useModalAttributes.js +0 -42
- package/lib/hooks/useModalAttributes.js.map +0 -1
- package/lib/hooks/useTabster.js +0 -35
- package/lib/hooks/useTabster.js.map +0 -1
- package/lib/hooks/useTabsterAttributes.js +0 -13
- package/lib/hooks/useTabsterAttributes.js.map +0 -1
- package/lib/index.js +0 -4
- package/lib/index.js.map +0 -1
package/CHANGELOG.json
CHANGED
@@ -2,9 +2,9 @@
|
|
2
2
|
"name": "@fluentui/react-tabster",
|
3
3
|
"entries": [
|
4
4
|
{
|
5
|
-
"date": "
|
6
|
-
"tag": "@fluentui/react-tabster_v0.0.0-nightly-
|
7
|
-
"version": "0.0.0-nightly-
|
5
|
+
"date": "Mon, 01 May 2023 04:24:06 GMT",
|
6
|
+
"tag": "@fluentui/react-tabster_v0.0.0-nightly-20230501-0418.1",
|
7
|
+
"version": "0.0.0-nightly-20230501-0418.1",
|
8
8
|
"comments": {
|
9
9
|
"prerelease": [
|
10
10
|
{
|
@@ -16,20 +16,20 @@
|
|
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-20230501-0418.1",
|
20
|
+
"commit": "ec7f7770aa9dd65ad47721639ad0c5d238d9e037"
|
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-20230501-0418.1",
|
26
|
+
"commit": "ec7f7770aa9dd65ad47721639ad0c5d238d9e037"
|
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-20230501-0418.1",
|
32
|
+
"commit": "ec7f7770aa9dd65ad47721639ad0c5d238d9e037"
|
33
33
|
}
|
34
34
|
]
|
35
35
|
}
|
package/CHANGELOG.md
CHANGED
@@ -1,20 +1,20 @@
|
|
1
1
|
# Change Log - @fluentui/react-tabster
|
2
2
|
|
3
|
-
This log was last generated on
|
3
|
+
This log was last generated on Mon, 01 May 2023 04:24:06 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-20230501-0418.1](https://github.com/microsoft/fluentui/tree/@fluentui/react-tabster_v0.0.0-nightly-20230501-0418.1)
|
8
8
|
|
9
|
-
|
10
|
-
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-tabster_v9.6.5..@fluentui/react-tabster_v0.0.0-nightly-
|
9
|
+
Mon, 01 May 2023 04:24:06 GMT
|
10
|
+
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-tabster_v9.6.5..@fluentui/react-tabster_v0.0.0-nightly-20230501-0418.1)
|
11
11
|
|
12
12
|
### Changes
|
13
13
|
|
14
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-
|
16
|
-
- Bump @fluentui/react-theme to v0.0.0-nightly-
|
17
|
-
- Bump @fluentui/react-utilities to v0.0.0-nightly-
|
15
|
+
- Bump @fluentui/react-shared-contexts to v0.0.0-nightly-20230501-0418.1 ([commit](https://github.com/microsoft/fluentui/commit/ec7f7770aa9dd65ad47721639ad0c5d238d9e037) by beachball)
|
16
|
+
- Bump @fluentui/react-theme to v0.0.0-nightly-20230501-0418.1 ([commit](https://github.com/microsoft/fluentui/commit/ec7f7770aa9dd65ad47721639ad0c5d238d9e037) by beachball)
|
17
|
+
- Bump @fluentui/react-utilities to v0.0.0-nightly-20230501-0418.1 ([commit](https://github.com/microsoft/fluentui/commit/ec7f7770aa9dd65ad47721639ad0c5d238d9e037) by beachball)
|
18
18
|
|
19
19
|
## [9.6.5](https://github.com/microsoft/fluentui/tree/@fluentui/react-tabster_v9.6.5)
|
20
20
|
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@fluentui/react-tabster",
|
3
|
-
"version": "0.0.0-nightly-
|
3
|
+
"version": "0.0.0-nightly-20230501-0418.1",
|
4
4
|
"description": "Utilities for focus management and facade for tabster",
|
5
5
|
"main": "lib-commonjs/index.js",
|
6
6
|
"module": "lib/index.js",
|
@@ -31,9 +31,9 @@
|
|
31
31
|
},
|
32
32
|
"dependencies": {
|
33
33
|
"@griffel/react": "^1.5.2",
|
34
|
-
"@fluentui/react-shared-contexts": "0.0.0-nightly-
|
35
|
-
"@fluentui/react-theme": "0.0.0-nightly-
|
36
|
-
"@fluentui/react-utilities": "0.0.0-nightly-
|
34
|
+
"@fluentui/react-shared-contexts": "0.0.0-nightly-20230501-0418.1",
|
35
|
+
"@fluentui/react-theme": "0.0.0-nightly-20230501-0418.1",
|
36
|
+
"@fluentui/react-utilities": "0.0.0-nightly-20230501-0418.1",
|
37
37
|
"@swc/helpers": "^0.4.14",
|
38
38
|
"keyborg": "^2.0.0",
|
39
39
|
"tabster": "^4.1.1"
|
package/dist/index.d.ts
DELETED
@@ -1,189 +0,0 @@
|
|
1
|
-
import type { GriffelStyle } from '@griffel/react';
|
2
|
-
import { makeResetStyles } from '@griffel/react';
|
3
|
-
import * as React_2 from 'react';
|
4
|
-
import type { RefObject } from 'react';
|
5
|
-
import { Types } from 'tabster';
|
6
|
-
|
7
|
-
/**
|
8
|
-
* @internal
|
9
|
-
* @param scope - Applies the ponyfill to all DOM children
|
10
|
-
* @param targetWindow - window
|
11
|
-
*/
|
12
|
-
export declare function applyFocusVisiblePolyfill(scope: HTMLElement, targetWindow: Window): () => void;
|
13
|
-
|
14
|
-
/**
|
15
|
-
* Creates a style for @see makeStyles that includes the necessary selectors for focus.
|
16
|
-
* Should be used only when @see createFocusOutlineStyle does not fit requirements
|
17
|
-
*
|
18
|
-
* @param style - styling applied on focus, defaults to @see getDefaultFocusOutlineStyles
|
19
|
-
* @param options - Configure the style of the focus outline
|
20
|
-
*/
|
21
|
-
export declare function createCustomFocusIndicatorStyle<TStyle extends GriffelStyle | GriffelResetStyle>(style: TStyle, { selector, enableOutline, }?: CreateCustomFocusIndicatorStyleOptions): TStyle extends GriffelStyle ? GriffelStyle : GriffelResetStyle;
|
22
|
-
|
23
|
-
export declare interface CreateCustomFocusIndicatorStyleOptions {
|
24
|
-
/**
|
25
|
-
* Control if the indicator appears when the corresponding element is focused,
|
26
|
-
* or any child is focused within the corresponding element.
|
27
|
-
* @default 'focus'
|
28
|
-
*/
|
29
|
-
selector?: 'focus' | 'focus-within';
|
30
|
-
/**
|
31
|
-
* Enables the browser default outline style
|
32
|
-
* @default false
|
33
|
-
*/
|
34
|
-
enableOutline?: boolean;
|
35
|
-
}
|
36
|
-
|
37
|
-
/**
|
38
|
-
* NOTE: The element with the focus outline needs to have `position: relative` so that the
|
39
|
-
* pseudo element can be properly positioned.
|
40
|
-
*
|
41
|
-
* @param options - Configure the style of the focus outline
|
42
|
-
* @returns focus outline styles object for @see makeStyles
|
43
|
-
*/
|
44
|
-
export declare const createFocusOutlineStyle: ({ selector, style, }?: CreateFocusOutlineStyleOptions) => GriffelStyle;
|
45
|
-
|
46
|
-
export declare interface CreateFocusOutlineStyleOptions extends CreateCustomFocusIndicatorStyleOptions {
|
47
|
-
style?: Partial<FocusOutlineStyleOptions>;
|
48
|
-
}
|
49
|
-
|
50
|
-
export declare type FocusOutlineOffset = Record<'top' | 'bottom' | 'left' | 'right', string>;
|
51
|
-
|
52
|
-
export declare type FocusOutlineStyleOptions = {
|
53
|
-
/**
|
54
|
-
* Only property not supported by the native CSS `outline`, if this is no longer needed
|
55
|
-
* we can just go native instead
|
56
|
-
*/
|
57
|
-
outlineRadius: string;
|
58
|
-
outlineColor: string;
|
59
|
-
outlineWidth: string;
|
60
|
-
outlineOffset?: string | FocusOutlineOffset;
|
61
|
-
};
|
62
|
-
|
63
|
-
declare type GriffelResetStyle = Parameters<typeof makeResetStyles>[0];
|
64
|
-
|
65
|
-
/**
|
66
|
-
* A hook that returns the necessary tabster attributes to support arrow key navigation
|
67
|
-
* @param options - Options to configure keyboard navigation
|
68
|
-
*/
|
69
|
-
export declare const useArrowNavigationGroup: (options?: UseArrowNavigationGroupOptions) => Types.TabsterDOMAttribute;
|
70
|
-
|
71
|
-
export declare interface UseArrowNavigationGroupOptions {
|
72
|
-
/**
|
73
|
-
* Focus will navigate vertically, horizontally or in both directions (grid), defaults to horizontally
|
74
|
-
* @defaultValue vertical
|
75
|
-
*/
|
76
|
-
axis?: 'vertical' | 'horizontal' | 'grid' | 'both';
|
77
|
-
/**
|
78
|
-
* Focus will cycle to the first/last elements of the group without stopping
|
79
|
-
*/
|
80
|
-
circular?: boolean;
|
81
|
-
/**
|
82
|
-
* Last focused element in the group will be remembered and focused (if still
|
83
|
-
* available) when tabbing from outside of the group
|
84
|
-
*/
|
85
|
-
memorizeCurrent?: boolean;
|
86
|
-
/**
|
87
|
-
* Allow tabbing within the arrow navigation group items.
|
88
|
-
*/
|
89
|
-
tabbable?: boolean;
|
90
|
-
/**
|
91
|
-
* Tabster should ignore default handling of keydown events
|
92
|
-
*/
|
93
|
-
ignoreDefaultKeydown?: Types.FocusableProps['ignoreKeydown'];
|
94
|
-
/**
|
95
|
-
* The default focusable item in the group will be an element with Focusable.isDefault property.
|
96
|
-
* Note that there is no way in \@fluentui/react-tabster to set default focusable element,
|
97
|
-
* and this option is currently for internal testing purposes only.
|
98
|
-
*/
|
99
|
-
unstable_hasDefault?: boolean;
|
100
|
-
}
|
101
|
-
|
102
|
-
/**
|
103
|
-
* A hook that returns the necessary tabster attributes to support groupping.
|
104
|
-
* @param options - Options to configure keyboard navigation
|
105
|
-
*/
|
106
|
-
export declare const useFocusableGroup: (options?: UseFocusableGroupOptions | undefined) => Types.TabsterDOMAttribute;
|
107
|
-
|
108
|
-
export declare interface UseFocusableGroupOptions {
|
109
|
-
/**
|
110
|
-
* Behavior for the Tab key.
|
111
|
-
*/
|
112
|
-
tabBehavior?: 'unlimited' | 'limited' | 'limited-trap-focus';
|
113
|
-
}
|
114
|
-
|
115
|
-
/**
|
116
|
-
* Returns a set of helper functions that will traverse focusable elements in the context of a root DOM element
|
117
|
-
*/
|
118
|
-
export declare const useFocusFinders: () => {
|
119
|
-
findAllFocusable: (container: HTMLElement, acceptCondition?: ((el: HTMLElement) => boolean) | undefined) => HTMLElement[];
|
120
|
-
findFirstFocusable: (container: HTMLElement) => HTMLElement | null | undefined;
|
121
|
-
findLastFocusable: (container: HTMLElement) => HTMLElement | null | undefined;
|
122
|
-
findNextFocusable: (currentElement: HTMLElement, options?: Pick<Partial<Types.FindNextProps>, 'container'>) => HTMLElement | null | undefined;
|
123
|
-
findPrevFocusable: (currentElement: HTMLElement, options?: Pick<Partial<Types.FindNextProps>, 'container'>) => HTMLElement | null | undefined;
|
124
|
-
};
|
125
|
-
|
126
|
-
export declare function useFocusVisible<TElement extends HTMLElement = HTMLElement>(options?: UseFocusVisibleOptions): React_2.RefObject<TElement>;
|
127
|
-
|
128
|
-
declare type UseFocusVisibleOptions = {
|
129
|
-
targetDocument?: HTMLDocument;
|
130
|
-
};
|
131
|
-
|
132
|
-
/**
|
133
|
-
* A ponyfill that allows `:focus-within` to support visibility based on keyboard/mouse navigation
|
134
|
-
* like `:focus-visible` https://github.com/WICG/focus-visible/issues/151
|
135
|
-
* @returns ref to the element that uses `:focus-within` styles
|
136
|
-
*/
|
137
|
-
export declare function useFocusWithin<TElement extends HTMLElement = HTMLElement>(): React_2.RefObject<TElement>;
|
138
|
-
|
139
|
-
/**
|
140
|
-
* Instantiates [keyborg](https://github.com/microsoft/keyborg) and adds `data-keyboard-nav`
|
141
|
-
* attribute to a referenced element to ensure keyboard navigation awareness
|
142
|
-
* synced to keyborg logic without having to cause a re-render on react tree.
|
143
|
-
*/
|
144
|
-
export declare function useKeyboardNavAttribute<E extends HTMLElement>(): RefObject<E>;
|
145
|
-
|
146
|
-
/**
|
147
|
-
* Applies modal dialog behaviour through DOM attributes
|
148
|
-
* Modal element will focus trap and hide other content on the page
|
149
|
-
* The trigger element will be focused if focus is lost after the modal element is removed
|
150
|
-
*
|
151
|
-
* @returns DOM attributes to apply to the modal element and its trigger
|
152
|
-
*/
|
153
|
-
export declare const useModalAttributes: (options?: UseModalAttributesOptions) => {
|
154
|
-
modalAttributes: Types.TabsterDOMAttribute;
|
155
|
-
triggerAttributes: Types.TabsterDOMAttribute;
|
156
|
-
};
|
157
|
-
|
158
|
-
export declare interface UseModalAttributesOptions {
|
159
|
-
/**
|
160
|
-
* Traps focus inside the elements the attributes are applied.
|
161
|
-
* Prefer this to `legacyTrapFocus`
|
162
|
-
* it forbids users to tab out of the focus trap into the actual browser.
|
163
|
-
*/
|
164
|
-
trapFocus?: boolean;
|
165
|
-
/**
|
166
|
-
* Traps focus inside the elements the attributes are applied.
|
167
|
-
* This prop enables legacy behavior to match previous versions of Fluent and is not
|
168
|
-
* recommended for general use.
|
169
|
-
* Enabling `legacyTrapFocus` prevents users from tabbing out of the focus trap and into
|
170
|
-
* the actual browser. Prefer using `trapFocus` instead of this prop.
|
171
|
-
*/
|
172
|
-
legacyTrapFocus?: boolean;
|
173
|
-
/**
|
174
|
-
* Always reachabled in Tab order
|
175
|
-
*/
|
176
|
-
alwaysFocusable?: boolean;
|
177
|
-
/**
|
178
|
-
* Id to use for the modalizer. An id will be generated if not provided.
|
179
|
-
*/
|
180
|
-
id?: string;
|
181
|
-
}
|
182
|
-
|
183
|
-
/**
|
184
|
-
* @internal
|
185
|
-
* Hook that returns tabster attributes while ensuring tabster exists
|
186
|
-
*/
|
187
|
-
export declare const useTabsterAttributes: (props: Types.TabsterAttributeProps) => Types.TabsterDOMAttribute;
|
188
|
-
|
189
|
-
export { }
|
package/lib/focus/constants.js
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
export const KEYBOARD_NAV_ATTRIBUTE = 'data-keyboard-nav';
|
2
|
-
export const KEYBOARD_NAV_SELECTOR = `:global([${KEYBOARD_NAV_ATTRIBUTE}])`;
|
3
|
-
/**
|
4
|
-
* @internal
|
5
|
-
*/
|
6
|
-
export const FOCUS_VISIBLE_ATTR = 'data-fui-focus-visible';
|
7
|
-
/**
|
8
|
-
* @internal
|
9
|
-
*/
|
10
|
-
export const FOCUS_WITHIN_ATTR = 'data-fui-focus-within';
|
11
|
-
export const defaultOptions = {
|
12
|
-
style: {},
|
13
|
-
selector: 'focus'
|
14
|
-
};
|
15
|
-
//# sourceMappingURL=constants.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"names":["KEYBOARD_NAV_ATTRIBUTE","KEYBOARD_NAV_SELECTOR","FOCUS_VISIBLE_ATTR","FOCUS_WITHIN_ATTR","defaultOptions","style","selector"],"sources":["../../src/focus/constants.ts"],"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-within';\nexport const defaultOptions = {\n style: {},\n selector: 'focus',\n} as const;\n"],"mappings":"AAAA,OAAO,MAAMA,sBAAA,GAAyB;AACtC,OAAO,MAAMC,qBAAA,GAAyB,YAAWD,sBAAuB,IAAG;AAE3E;;;AAGA,OAAO,MAAME,kBAAA,GAAqB;AAElC;;;AAGA,OAAO,MAAMC,iBAAA,GAAoB;AACjC,OAAO,MAAMC,cAAA,GAAiB;EAC5BC,KAAA,EAAO,CAAC;EACRC,QAAA,EAAU;AACZ"}
|
@@ -1,28 +0,0 @@
|
|
1
|
-
import { defaultOptions, FOCUS_VISIBLE_ATTR, FOCUS_WITHIN_ATTR } from './constants';
|
2
|
-
/**
|
3
|
-
* Creates a style for @see makeStyles that includes the necessary selectors for focus.
|
4
|
-
* Should be used only when @see createFocusOutlineStyle does not fit requirements
|
5
|
-
*
|
6
|
-
* @param style - styling applied on focus, defaults to @see getDefaultFocusOutlineStyles
|
7
|
-
* @param options - Configure the style of the focus outline
|
8
|
-
*/
|
9
|
-
export function createCustomFocusIndicatorStyle(style, {
|
10
|
-
selector = defaultOptions.selector,
|
11
|
-
enableOutline = false
|
12
|
-
} = defaultOptions) {
|
13
|
-
return {
|
14
|
-
':focus': {
|
15
|
-
outlineStyle: enableOutline ? undefined : 'none'
|
16
|
-
},
|
17
|
-
':focus-visible': {
|
18
|
-
outlineStyle: enableOutline ? undefined : 'none'
|
19
|
-
},
|
20
|
-
...(selector === 'focus' && {
|
21
|
-
[`&[${FOCUS_VISIBLE_ATTR}]`]: style
|
22
|
-
}),
|
23
|
-
...(selector === 'focus-within' && {
|
24
|
-
[`&[${FOCUS_WITHIN_ATTR}]:${selector}`]: style
|
25
|
-
})
|
26
|
-
};
|
27
|
-
}
|
28
|
-
//# sourceMappingURL=createCustomFocusIndicatorStyle.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"names":["defaultOptions","FOCUS_VISIBLE_ATTR","FOCUS_WITHIN_ATTR","createCustomFocusIndicatorStyle","style","selector","enableOutline","outlineStyle","undefined"],"sources":["../../src/focus/createCustomFocusIndicatorStyle.ts"],"sourcesContent":["import { defaultOptions, FOCUS_VISIBLE_ATTR, FOCUS_WITHIN_ATTR } from './constants';\nimport { makeResetStyles } from '@griffel/react';\nimport type { GriffelStyle } from '@griffel/react';\n\n// TODO: Use the type directly from @griffel/react\n// https://github.com/microsoft/griffel/pull/278\ntype GriffelResetStyle = Parameters<typeof makeResetStyles>[0];\n\nexport interface CreateCustomFocusIndicatorStyleOptions {\n /**\n * Control if the indicator appears when the corresponding element is focused,\n * or any child is focused within the corresponding element.\n * @default 'focus'\n */\n selector?: 'focus' | 'focus-within';\n /**\n * Enables the browser default outline style\n * @default false\n */\n enableOutline?: boolean;\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 getDefaultFocusOutlineStyles\n * @param options - Configure the style of the focus outline\n */\nexport function createCustomFocusIndicatorStyle<TStyle extends GriffelStyle | GriffelResetStyle>(\n style: TStyle,\n {\n selector = defaultOptions.selector,\n enableOutline = false,\n }: CreateCustomFocusIndicatorStyleOptions = defaultOptions,\n): TStyle extends GriffelStyle ? GriffelStyle : GriffelResetStyle {\n return {\n ':focus': {\n outlineStyle: enableOutline ? undefined : 'none',\n },\n ':focus-visible': {\n outlineStyle: enableOutline ? undefined : '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}\n"],"mappings":"AAAA,SAASA,cAAc,EAAEC,kBAAkB,EAAEC,iBAAiB,QAAQ;AAsBtE;;;;;;;AAOA,OAAO,SAASC,gCACdC,KAAa,EACb;EACEC,QAAA,GAAWL,cAAA,CAAeK,QAAQ;EAClCC,aAAA,GAAgB;AAAK,CACkB,GAAGN,cAAc,EACM;EAChE,OAAO;IACL,UAAU;MACRO,YAAA,EAAcD,aAAA,GAAgBE,SAAA,GAAY;IAC5C;IACA,kBAAkB;MAChBD,YAAA,EAAcD,aAAA,GAAgBE,SAAA,GAAY;IAC5C;IAEA,IAAIH,QAAA,KAAa,WAAW;MAC1B,CAAE,KAAIJ,kBAAmB,GAAE,GAAGG;IAChC,CAAC;IACD,IAAIC,QAAA,KAAa,kBAAkB;MACjC,CAAE,KAAIH,iBAAkB,KAAIG,QAAS,EAAC,GAAGD;IAC3C,CAAC;EACH;AACF"}
|
@@ -1,60 +0,0 @@
|
|
1
|
-
import { tokens } from '@fluentui/react-theme';
|
2
|
-
import { shorthands } from '@griffel/react';
|
3
|
-
import { createCustomFocusIndicatorStyle } from './createCustomFocusIndicatorStyle';
|
4
|
-
import { defaultOptions } from './constants';
|
5
|
-
/**
|
6
|
-
* NOTE: the element with the focus outline needs to have `position: relative` so that the
|
7
|
-
* pseudo element can be properly positioned.
|
8
|
-
*
|
9
|
-
* @param options - Configures the style of the focus outline
|
10
|
-
* @returns focus outline styles object
|
11
|
-
*/
|
12
|
-
const getFocusOutlineStyles = options => {
|
13
|
-
const {
|
14
|
-
outlineRadius,
|
15
|
-
outlineColor,
|
16
|
-
outlineOffset,
|
17
|
-
outlineWidth
|
18
|
-
} = options;
|
19
|
-
const outlineOffsetTop = (outlineOffset === null || outlineOffset === void 0 ? void 0 : outlineOffset.top) || outlineOffset;
|
20
|
-
const outlineOffsetBottom = (outlineOffset === null || outlineOffset === void 0 ? void 0 : outlineOffset.bottom) || outlineOffset;
|
21
|
-
const outlineOffsetLeft = (outlineOffset === null || outlineOffset === void 0 ? void 0 : outlineOffset.left) || outlineOffset;
|
22
|
-
const outlineOffsetRight = (outlineOffset === null || outlineOffset === void 0 ? void 0 : outlineOffset.right) || outlineOffset;
|
23
|
-
return {
|
24
|
-
...shorthands.borderColor('transparent'),
|
25
|
-
'::after': {
|
26
|
-
content: '""',
|
27
|
-
position: 'absolute',
|
28
|
-
pointerEvents: 'none',
|
29
|
-
zIndex: 1,
|
30
|
-
...shorthands.borderStyle('solid'),
|
31
|
-
...shorthands.borderWidth(outlineWidth),
|
32
|
-
...shorthands.borderRadius(outlineRadius),
|
33
|
-
...shorthands.borderColor(outlineColor),
|
34
|
-
top: !outlineOffset ? `-${outlineWidth}` : `calc(0px - ${outlineWidth} - ${outlineOffsetTop})`,
|
35
|
-
bottom: !outlineOffset ? `-${outlineWidth}` : `calc(0px - ${outlineWidth} - ${outlineOffsetBottom})`,
|
36
|
-
left: !outlineOffset ? `-${outlineWidth}` : `calc(0px - ${outlineWidth} - ${outlineOffsetLeft})`,
|
37
|
-
right: !outlineOffset ? `-${outlineWidth}` : `calc(0px - ${outlineWidth} - ${outlineOffsetRight})`
|
38
|
-
}
|
39
|
-
};
|
40
|
-
};
|
41
|
-
/**
|
42
|
-
* NOTE: The element with the focus outline needs to have `position: relative` so that the
|
43
|
-
* pseudo element can be properly positioned.
|
44
|
-
*
|
45
|
-
* @param options - Configure the style of the focus outline
|
46
|
-
* @returns focus outline styles object for @see makeStyles
|
47
|
-
*/
|
48
|
-
export const createFocusOutlineStyle = ({
|
49
|
-
selector = defaultOptions.selector,
|
50
|
-
style = defaultOptions.style
|
51
|
-
} = defaultOptions) => createCustomFocusIndicatorStyle(getFocusOutlineStyles({
|
52
|
-
outlineColor: tokens.colorStrokeFocus2,
|
53
|
-
outlineRadius: tokens.borderRadiusMedium,
|
54
|
-
// FIXME: tokens.strokeWidthThick causes some weird bugs
|
55
|
-
outlineWidth: '2px',
|
56
|
-
...style
|
57
|
-
}), {
|
58
|
-
selector
|
59
|
-
});
|
60
|
-
//# sourceMappingURL=createFocusOutlineStyle.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"names":["tokens","shorthands","createCustomFocusIndicatorStyle","defaultOptions","getFocusOutlineStyles","options","outlineRadius","outlineColor","outlineOffset","outlineWidth","outlineOffsetTop","top","outlineOffsetBottom","bottom","outlineOffsetLeft","left","outlineOffsetRight","right","borderColor","content","position","pointerEvents","zIndex","borderStyle","borderWidth","borderRadius","createFocusOutlineStyle","selector","style","colorStrokeFocus2","borderRadiusMedium"],"sources":["../../src/focus/createFocusOutlineStyle.ts"],"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"],"mappings":"AAAA,SAASA,MAAM,QAAQ;AACvB,SAASC,UAAU,QAAQ;AAE3B,SACEC,+BAA+B,QAE1B;AACP,SAASC,cAAc,QAAQ;AAiB/B;;;;;;;AAOA,MAAMC,qBAAA,GAAyBC,OAAA,IAAoD;EACjF,MAAM;IAAEC,aAAA;IAAeC,YAAA;IAAcC,aAAA;IAAeC;EAAY,CAAE,GAAGJ,OAAA;EAErE,MAAMK,gBAAA,GAAmB,CAAAF,aAAC,aAAAA,aAAA,cAAD,SAAAA,aAAC,CAAsCG,GAAG,KAAIH,aAAA;EACvE,MAAMI,mBAAA,GAAsB,CAAAJ,aAAC,aAAAA,aAAA,cAAD,SAAAA,aAAC,CAAsCK,MAAM,KAAIL,aAAA;EAC7E,MAAMM,iBAAA,GAAoB,CAAAN,aAAC,aAAAA,aAAA,cAAD,SAAAA,aAAC,CAAsCO,IAAI,KAAIP,aAAA;EACzE,MAAMQ,kBAAA,GAAqB,CAAAR,aAAC,aAAAA,aAAA,cAAD,SAAAA,aAAC,CAAsCS,KAAK,KAAIT,aAAA;EAE3E,OAAO;IACL,GAAGP,UAAA,CAAWiB,WAAW,CAAC,cAAc;IACxC,WAAW;MACTC,OAAA,EAAS;MACTC,QAAA,EAAU;MACVC,aAAA,EAAe;MACfC,MAAA,EAAQ;MAER,GAAGrB,UAAA,CAAWsB,WAAW,CAAC,QAAQ;MAClC,GAAGtB,UAAA,CAAWuB,WAAW,CAACf,YAAA,CAAa;MACvC,GAAGR,UAAA,CAAWwB,YAAY,CAACnB,aAAA,CAAc;MACzC,GAAGL,UAAA,CAAWiB,WAAW,CAACX,YAAA,CAAa;MAEvCI,GAAA,EAAK,CAACH,aAAA,GAAiB,IAAGC,YAAa,EAAC,GAAI,cAAaA,YAAa,MAAKC,gBAAiB,GAAE;MAC9FG,MAAA,EAAQ,CAACL,aAAA,GAAiB,IAAGC,YAAa,EAAC,GAAI,cAAaA,YAAa,MAAKG,mBAAoB,GAAE;MACpGG,IAAA,EAAM,CAACP,aAAA,GAAiB,IAAGC,YAAa,EAAC,GAAI,cAAaA,YAAa,MAAKK,iBAAkB,GAAE;MAChGG,KAAA,EAAO,CAACT,aAAA,GAAiB,IAAGC,YAAa,EAAC,GAAI,cAAaA,YAAa,MAAKO,kBAAmB;IAClG;EACF;AACF;AAEA;;;;;;;AAOA,OAAO,MAAMU,uBAAA,GAA0BA,CAAC;EACtCC,QAAA,GAAWxB,cAAA,CAAewB,QAAQ;EAClCC,KAAA,GAAQzB,cAAA,CAAeyB;AAAK,CACG,GAAGzB,cAAc,KAChDD,+BAAA,CACEE,qBAAA,CAAsB;EACpBG,YAAA,EAAcP,MAAA,CAAO6B,iBAAiB;EACtCvB,aAAA,EAAeN,MAAA,CAAO8B,kBAAkB;EACxC;EACArB,YAAA,EAAc;EACd,GAAGmB;AACL,IACA;EAAED;AAAS"}
|
@@ -1,73 +0,0 @@
|
|
1
|
-
import { isHTMLElement } from '@fluentui/react-utilities';
|
2
|
-
import { KEYBORG_FOCUSIN, createKeyborg, disposeKeyborg } from 'keyborg';
|
3
|
-
import { FOCUS_VISIBLE_ATTR } from './constants';
|
4
|
-
/**
|
5
|
-
* @internal
|
6
|
-
* @param scope - Applies the ponyfill to all DOM children
|
7
|
-
* @param targetWindow - window
|
8
|
-
*/
|
9
|
-
export function applyFocusVisiblePolyfill(scope, targetWindow) {
|
10
|
-
if (alreadyInScope(scope)) {
|
11
|
-
// Focus visible polyfill already applied at this scope
|
12
|
-
return () => undefined;
|
13
|
-
}
|
14
|
-
const state = {
|
15
|
-
current: undefined
|
16
|
-
};
|
17
|
-
const keyborg = createKeyborg(targetWindow);
|
18
|
-
// When navigation mode changes remove the focus-visible selector
|
19
|
-
keyborg.subscribe(isNavigatingWithKeyboard => {
|
20
|
-
if (!isNavigatingWithKeyboard && state.current) {
|
21
|
-
removeFocusVisibleClass(state.current);
|
22
|
-
state.current = undefined;
|
23
|
-
}
|
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
|
-
const keyborgListener = e => {
|
28
|
-
if (state.current) {
|
29
|
-
removeFocusVisibleClass(state.current);
|
30
|
-
state.current = undefined;
|
31
|
-
}
|
32
|
-
if (keyborg.isNavigatingWithKeyboard() && isHTMLElement(e.target) && e.target) {
|
33
|
-
// Griffel can't create chained global styles so use the parent element for now
|
34
|
-
state.current = e.target;
|
35
|
-
applyFocusVisibleClass(state.current);
|
36
|
-
}
|
37
|
-
};
|
38
|
-
// Make sure that when focus leaves the scope, the focus visible class is removed
|
39
|
-
const blurListener = e => {
|
40
|
-
if (!e.relatedTarget || isHTMLElement(e.relatedTarget) && !scope.contains(e.relatedTarget)) {
|
41
|
-
if (state.current) {
|
42
|
-
removeFocusVisibleClass(state.current);
|
43
|
-
state.current = undefined;
|
44
|
-
}
|
45
|
-
}
|
46
|
-
};
|
47
|
-
scope.addEventListener(KEYBORG_FOCUSIN, keyborgListener);
|
48
|
-
scope.addEventListener('focusout', blurListener);
|
49
|
-
scope.focusVisible = true;
|
50
|
-
// Return disposer
|
51
|
-
return () => {
|
52
|
-
scope.removeEventListener(KEYBORG_FOCUSIN, keyborgListener);
|
53
|
-
scope.removeEventListener('focusout', blurListener);
|
54
|
-
delete scope.focusVisible;
|
55
|
-
disposeKeyborg(keyborg);
|
56
|
-
};
|
57
|
-
}
|
58
|
-
function applyFocusVisibleClass(el) {
|
59
|
-
el.setAttribute(FOCUS_VISIBLE_ATTR, '');
|
60
|
-
}
|
61
|
-
function removeFocusVisibleClass(el) {
|
62
|
-
el.removeAttribute(FOCUS_VISIBLE_ATTR);
|
63
|
-
}
|
64
|
-
function alreadyInScope(el) {
|
65
|
-
if (!el) {
|
66
|
-
return false;
|
67
|
-
}
|
68
|
-
if (el.focusVisible) {
|
69
|
-
return true;
|
70
|
-
}
|
71
|
-
return alreadyInScope(el === null || el === void 0 ? void 0 : el.parentElement);
|
72
|
-
}
|
73
|
-
//# sourceMappingURL=focusVisiblePolyfill.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"names":["isHTMLElement","KEYBORG_FOCUSIN","createKeyborg","disposeKeyborg","FOCUS_VISIBLE_ATTR","applyFocusVisiblePolyfill","scope","targetWindow","alreadyInScope","undefined","state","current","keyborg","subscribe","isNavigatingWithKeyboard","removeFocusVisibleClass","keyborgListener","e","target","applyFocusVisibleClass","blurListener","relatedTarget","contains","addEventListener","focusVisible","removeEventListener","el","setAttribute","removeAttribute","parentElement"],"sources":["../../src/focus/focusVisiblePolyfill.ts"],"sourcesContent":["import { isHTMLElement } from '@fluentui/react-utilities';\nimport { KEYBORG_FOCUSIN, KeyborgFocusInEvent, createKeyborg, disposeKeyborg } from 'keyborg';\n\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 targetWindow - window\n */\nexport function applyFocusVisiblePolyfill(scope: HTMLElement, targetWindow: 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(targetWindow);\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 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"],"mappings":"AAAA,SAASA,aAAa,QAAQ;AAC9B,SAASC,eAAe,EAAuBC,aAAa,EAAEC,cAAc,QAAQ;AAEpF,SAASC,kBAAkB,QAAQ;AAoBnC;;;;;AAKA,OAAO,SAASC,0BAA0BC,KAAkB,EAAEC,YAAoB,EAAc;EAC9F,IAAIC,cAAA,CAAeF,KAAA,GAAQ;IACzB;IACA,OAAO,MAAMG,SAAA;EACf;EAEA,MAAMC,KAAA,GAA2B;IAC/BC,OAAA,EAASF;EACX;EAEA,MAAMG,OAAA,GAAUV,aAAA,CAAcK,YAAA;EAE9B;EACAK,OAAA,CAAQC,SAAS,CAACC,wBAAA,IAA4B;IAC5C,IAAI,CAACA,wBAAA,IAA4BJ,KAAA,CAAMC,OAAO,EAAE;MAC9CI,uBAAA,CAAwBL,KAAA,CAAMC,OAAO;MACrCD,KAAA,CAAMC,OAAO,GAAGF,SAAA;IAClB;EACF;EAEA;EACA;EACA,MAAMO,eAAA,GAAmBC,CAAA,IAA2B;IAClD,IAAIP,KAAA,CAAMC,OAAO,EAAE;MACjBI,uBAAA,CAAwBL,KAAA,CAAMC,OAAO;MACrCD,KAAA,CAAMC,OAAO,GAAGF,SAAA;IAClB;IAEA,IAAIG,OAAA,CAAQE,wBAAwB,MAAMd,aAAA,CAAciB,CAAA,CAAEC,MAAM,KAAKD,CAAA,CAAEC,MAAM,EAAE;MAC7E;MACAR,KAAA,CAAMC,OAAO,GAAGM,CAAA,CAAEC,MAAM;MACxBC,sBAAA,CAAuBT,KAAA,CAAMC,OAAO;IACtC;EACF;EAEA;EACA,MAAMS,YAAA,GAAgBH,CAAA,IAAkB;IACtC,IAAI,CAACA,CAAA,CAAEI,aAAa,IAAKrB,aAAA,CAAciB,CAAA,CAAEI,aAAa,KAAK,CAACf,KAAA,CAAMgB,QAAQ,CAACL,CAAA,CAAEI,aAAa,GAAI;MAC5F,IAAIX,KAAA,CAAMC,OAAO,EAAE;QACjBI,uBAAA,CAAwBL,KAAA,CAAMC,OAAO;QACrCD,KAAA,CAAMC,OAAO,GAAGF,SAAA;MAClB;IACF;EACF;EAEAH,KAAA,CAAMiB,gBAAgB,CAACtB,eAAA,EAAiBe,eAAA;EACxCV,KAAA,CAAMiB,gBAAgB,CAAC,YAAYH,YAAA;EAClCd,KAAA,CAA2CkB,YAAY,GAAG,IAAI;EAE/D;EACA,OAAO,MAAM;IACXlB,KAAA,CAAMmB,mBAAmB,CAACxB,eAAA,EAAiBe,eAAA;IAC3CV,KAAA,CAAMmB,mBAAmB,CAAC,YAAYL,YAAA;IACtC,OAAOd,KAAC,CAA2CkB,YAAY;IAC/DrB,cAAA,CAAeS,OAAA;EACjB;AACF;AAEA,SAASO,uBAAuBO,EAAe,EAAE;EAC/CA,EAAA,CAAGC,YAAY,CAACvB,kBAAA,EAAoB;AACtC;AAEA,SAASW,wBAAwBW,EAAe,EAAE;EAChDA,EAAA,CAAGE,eAAe,CAACxB,kBAAA;AACrB;AAEA,SAASI,eAAekB,EAAkC,EAAW;EACnE,IAAI,CAACA,EAAA,EAAI;IACP,OAAO,KAAK;EACd;EAEA,IAAIA,EAAC,CAAwCF,YAAY,EAAE;IACzD,OAAO,IAAI;EACb;EAEA,OAAOhB,cAAA,CAAekB,EAAA,aAAAA,EAAA,uBAAAA,EAAA,CAAIG,aAAa;AACzC"}
|
@@ -1,51 +0,0 @@
|
|
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
|
-
export function applyFocusWithinPolyfill(element, win) {
|
9
|
-
const keyborg = createKeyborg(win);
|
10
|
-
// When navigation mode changes to mouse, remove the focus-within selector
|
11
|
-
keyborg.subscribe(isNavigatingWithKeyboard => {
|
12
|
-
if (!isNavigatingWithKeyboard) {
|
13
|
-
removeFocusWithinClass(element);
|
14
|
-
}
|
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
|
-
const keyborgListener = e => {
|
19
|
-
if (keyborg.isNavigatingWithKeyboard() && isHTMLElement(e.target)) {
|
20
|
-
// Griffel can't create chained global styles so use the parent element for now
|
21
|
-
applyFocusWithinClass(element);
|
22
|
-
}
|
23
|
-
};
|
24
|
-
// Make sure that when focus leaves the scope, the focus within class is removed
|
25
|
-
const blurListener = e => {
|
26
|
-
if (!e.relatedTarget || isHTMLElement(e.relatedTarget) && !element.contains(e.relatedTarget)) {
|
27
|
-
removeFocusWithinClass(element);
|
28
|
-
}
|
29
|
-
};
|
30
|
-
element.addEventListener(KEYBORG_FOCUSIN, keyborgListener);
|
31
|
-
element.addEventListener('focusout', blurListener);
|
32
|
-
// Return disposer
|
33
|
-
return () => {
|
34
|
-
element.removeEventListener(KEYBORG_FOCUSIN, keyborgListener);
|
35
|
-
element.removeEventListener('focusout', blurListener);
|
36
|
-
disposeKeyborg(keyborg);
|
37
|
-
};
|
38
|
-
}
|
39
|
-
function applyFocusWithinClass(el) {
|
40
|
-
el.setAttribute(FOCUS_WITHIN_ATTR, '');
|
41
|
-
}
|
42
|
-
function removeFocusWithinClass(el) {
|
43
|
-
el.removeAttribute(FOCUS_WITHIN_ATTR);
|
44
|
-
}
|
45
|
-
function isHTMLElement(target) {
|
46
|
-
if (!target) {
|
47
|
-
return false;
|
48
|
-
}
|
49
|
-
return Boolean(target && typeof target === 'object' && 'classList' in target && 'contains' in target);
|
50
|
-
}
|
51
|
-
//# sourceMappingURL=focusWithinPolyfill.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"names":["KEYBORG_FOCUSIN","createKeyborg","disposeKeyborg","FOCUS_WITHIN_ATTR","applyFocusWithinPolyfill","element","win","keyborg","subscribe","isNavigatingWithKeyboard","removeFocusWithinClass","keyborgListener","e","isHTMLElement","target","applyFocusWithinClass","blurListener","relatedTarget","contains","addEventListener","removeEventListener","el","setAttribute","removeAttribute","Boolean"],"sources":["../../src/focus/focusWithinPolyfill.ts"],"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"],"mappings":"AAAA,SAASA,eAAe,EAAuBC,aAAa,EAAEC,cAAc,QAAQ;AACpF,SAASC,iBAAiB,QAAQ;AASlC;;;;;AAKA,OAAO,SAASC,yBAAyBC,OAAoB,EAAEC,GAAW,EAAc;EACtF,MAAMC,OAAA,GAAUN,aAAA,CAAcK,GAAA;EAE9B;EACAC,OAAA,CAAQC,SAAS,CAACC,wBAAA,IAA4B;IAC5C,IAAI,CAACA,wBAAA,EAA0B;MAC7BC,sBAAA,CAAuBL,OAAA;IACzB;EACF;EAEA;EACA;EACA,MAAMM,eAAA,GAAmBC,CAAA,IAA2B;IAClD,IAAIL,OAAA,CAAQE,wBAAwB,MAAMI,aAAA,CAAcD,CAAA,CAAEE,MAAM,GAAG;MACjE;MACAC,qBAAA,CAAsBV,OAAA;IACxB;EACF;EAEA;EACA,MAAMW,YAAA,GAAgBJ,CAAA,IAAkB;IACtC,IAAI,CAACA,CAAA,CAAEK,aAAa,IAAKJ,aAAA,CAAcD,CAAA,CAAEK,aAAa,KAAK,CAACZ,OAAA,CAAQa,QAAQ,CAACN,CAAA,CAAEK,aAAa,GAAI;MAC9FP,sBAAA,CAAuBL,OAAA;IACzB;EACF;EAEAA,OAAA,CAAQc,gBAAgB,CAACnB,eAAA,EAAiBW,eAAA;EAC1CN,OAAA,CAAQc,gBAAgB,CAAC,YAAYH,YAAA;EAErC;EACA,OAAO,MAAM;IACXX,OAAA,CAAQe,mBAAmB,CAACpB,eAAA,EAAiBW,eAAA;IAC7CN,OAAA,CAAQe,mBAAmB,CAAC,YAAYJ,YAAA;IACxCd,cAAA,CAAeK,OAAA;EACjB;AACF;AAEA,SAASQ,sBAAsBM,EAAe,EAAE;EAC9CA,EAAA,CAAGC,YAAY,CAACnB,iBAAA,EAAmB;AACrC;AAEA,SAASO,uBAAuBW,EAAe,EAAE;EAC/CA,EAAA,CAAGE,eAAe,CAACpB,iBAAA;AACrB;AAEA,SAASU,cAAcC,MAA0B,EAAyB;EACxE,IAAI,CAACA,MAAA,EAAQ;IACX,OAAO,KAAK;EACd;EACA,OAAOU,OAAA,CAAQV,MAAA,IAAU,OAAOA,MAAA,KAAW,YAAY,eAAeA,MAAA,IAAU,cAAcA,MAAA;AAChG"}
|
package/lib/focus/index.js
DELETED
package/lib/focus/index.js.map
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"names":[],"sources":["../../src/focus/index.ts"],"sourcesContent":["export * from './createCustomFocusIndicatorStyle';\nexport * from './createFocusOutlineStyle';\nexport * from './focusVisiblePolyfill';\nexport * from './focusWithinPolyfill';\n"],"mappings":"AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc"}
|
package/lib/hooks/index.js
DELETED
@@ -1,9 +0,0 @@
|
|
1
|
-
export * from './useArrowNavigationGroup';
|
2
|
-
export * from './useFocusableGroup';
|
3
|
-
export * from './useFocusFinders';
|
4
|
-
export * from './useFocusVisible';
|
5
|
-
export * from './useFocusWithin';
|
6
|
-
export * from './useKeyboardNavAttribute';
|
7
|
-
export * from './useModalAttributes';
|
8
|
-
export * from './useTabsterAttributes';
|
9
|
-
//# sourceMappingURL=index.js.map
|
package/lib/hooks/index.js.map
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"names":[],"sources":["../../src/hooks/index.ts"],"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"],"mappings":"AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc"}
|
@@ -1,50 +0,0 @@
|
|
1
|
-
import { Types, getMover } from 'tabster';
|
2
|
-
import { useTabsterAttributes } from './useTabsterAttributes';
|
3
|
-
import { useTabster } from './useTabster';
|
4
|
-
/**
|
5
|
-
* A hook that returns the necessary tabster attributes to support arrow key navigation
|
6
|
-
* @param options - Options to configure keyboard navigation
|
7
|
-
*/
|
8
|
-
export const useArrowNavigationGroup = (options = {}) => {
|
9
|
-
const {
|
10
|
-
circular,
|
11
|
-
axis,
|
12
|
-
memorizeCurrent,
|
13
|
-
tabbable,
|
14
|
-
ignoreDefaultKeydown,
|
15
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
16
|
-
unstable_hasDefault
|
17
|
-
} = options;
|
18
|
-
const tabster = useTabster();
|
19
|
-
if (tabster) {
|
20
|
-
getMover(tabster);
|
21
|
-
}
|
22
|
-
return useTabsterAttributes({
|
23
|
-
mover: {
|
24
|
-
cyclic: !!circular,
|
25
|
-
direction: axisToMoverDirection(axis !== null && axis !== void 0 ? axis : 'vertical'),
|
26
|
-
memorizeCurrent,
|
27
|
-
tabbable,
|
28
|
-
hasDefault: unstable_hasDefault
|
29
|
-
},
|
30
|
-
...(ignoreDefaultKeydown && {
|
31
|
-
focusable: {
|
32
|
-
ignoreKeydown: ignoreDefaultKeydown
|
33
|
-
}
|
34
|
-
})
|
35
|
-
});
|
36
|
-
};
|
37
|
-
function axisToMoverDirection(axis) {
|
38
|
-
switch (axis) {
|
39
|
-
case 'horizontal':
|
40
|
-
return Types.MoverDirections.Horizontal;
|
41
|
-
case 'grid':
|
42
|
-
return Types.MoverDirections.Grid;
|
43
|
-
case 'both':
|
44
|
-
return Types.MoverDirections.Both;
|
45
|
-
case 'vertical':
|
46
|
-
default:
|
47
|
-
return Types.MoverDirections.Vertical;
|
48
|
-
}
|
49
|
-
}
|
50
|
-
//# sourceMappingURL=useArrowNavigationGroup.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"names":["Types","getMover","useTabsterAttributes","useTabster","useArrowNavigationGroup","options","circular","axis","memorizeCurrent","tabbable","ignoreDefaultKeydown","unstable_hasDefault","tabster","mover","cyclic","direction","axisToMoverDirection","hasDefault","focusable","ignoreKeydown","MoverDirections","Horizontal","Grid","Both","Vertical"],"sources":["../../src/hooks/useArrowNavigationGroup.ts"],"sourcesContent":["import { Types, getMover } from 'tabster';\nimport { useTabsterAttributes } from './useTabsterAttributes';\nimport { useTabster } from './useTabster';\n\nexport interface UseArrowNavigationGroupOptions {\n /**\n * Focus will navigate vertically, horizontally or in both directions (grid), defaults to horizontally\n * @defaultValue vertical\n */\n axis?: 'vertical' | 'horizontal' | 'grid' | 'both';\n /**\n * Focus will cycle to the first/last elements of the group without stopping\n */\n circular?: boolean;\n /**\n * Last focused element in the group will be remembered and focused (if still\n * available) when tabbing from outside of the group\n */\n memorizeCurrent?: boolean;\n /**\n * Allow tabbing within the arrow navigation group items.\n */\n tabbable?: boolean;\n /**\n * Tabster should ignore default handling of keydown events\n */\n ignoreDefaultKeydown?: Types.FocusableProps['ignoreKeydown'];\n /**\n * The default focusable item in the group will be an element with Focusable.isDefault property.\n * Note that there is no way in \\@fluentui/react-tabster to set default focusable element,\n * and this option is currently for internal testing purposes only.\n */\n // eslint-disable-next-line @typescript-eslint/naming-convention\n unstable_hasDefault?: boolean;\n}\n\n/**\n * A hook that returns the necessary tabster attributes to support arrow key navigation\n * @param options - Options to configure keyboard navigation\n */\nexport const useArrowNavigationGroup = (options: UseArrowNavigationGroupOptions = {}): Types.TabsterDOMAttribute => {\n const {\n circular,\n axis,\n memorizeCurrent,\n tabbable,\n ignoreDefaultKeydown,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n unstable_hasDefault,\n } = options;\n const tabster = useTabster();\n\n if (tabster) {\n getMover(tabster);\n }\n\n return useTabsterAttributes({\n mover: {\n cyclic: !!circular,\n direction: axisToMoverDirection(axis ?? 'vertical'),\n memorizeCurrent,\n tabbable,\n hasDefault: unstable_hasDefault,\n },\n ...(ignoreDefaultKeydown && {\n focusable: {\n ignoreKeydown: ignoreDefaultKeydown,\n },\n }),\n });\n};\n\nfunction axisToMoverDirection(axis: UseArrowNavigationGroupOptions['axis']): Types.MoverDirection {\n switch (axis) {\n case 'horizontal':\n return Types.MoverDirections.Horizontal;\n case 'grid':\n return Types.MoverDirections.Grid;\n case 'both':\n return Types.MoverDirections.Both;\n\n case 'vertical':\n default:\n return Types.MoverDirections.Vertical;\n }\n}\n"],"mappings":"AAAA,SAASA,KAAK,EAAEC,QAAQ,QAAQ;AAChC,SAASC,oBAAoB,QAAQ;AACrC,SAASC,UAAU,QAAQ;AAkC3B;;;;AAIA,OAAO,MAAMC,uBAAA,GAA0BA,CAACC,OAAA,GAA0C,CAAC,CAAC,KAAgC;EAClH,MAAM;IACJC,QAAA;IACAC,IAAA;IACAC,eAAA;IACAC,QAAA;IACAC,oBAAA;IACA;IACAC;EAAmB,CACpB,GAAGN,OAAA;EACJ,MAAMO,OAAA,GAAUT,UAAA;EAEhB,IAAIS,OAAA,EAAS;IACXX,QAAA,CAASW,OAAA;EACX;EAEA,OAAOV,oBAAA,CAAqB;IAC1BW,KAAA,EAAO;MACLC,MAAA,EAAQ,CAAC,CAACR,QAAA;MACVS,SAAA,EAAWC,oBAAA,CAAqBT,IAAA,aAAAA,IAAA,cAAAA,IAAA,GAAQ,UAAU;MAClDC,eAAA;MACAC,QAAA;MACAQ,UAAA,EAAYN;IACd;IACA,IAAID,oBAAA,IAAwB;MAC1BQ,SAAA,EAAW;QACTC,aAAA,EAAeT;MACjB;IACF,CAAC;EACH;AACF;AAEA,SAASM,qBAAqBT,IAA4C,EAAwB;EAChG,QAAQA,IAAA;IACN,KAAK;MACH,OAAOP,KAAA,CAAMoB,eAAe,CAACC,UAAU;IACzC,KAAK;MACH,OAAOrB,KAAA,CAAMoB,eAAe,CAACE,IAAI;IACnC,KAAK;MACH,OAAOtB,KAAA,CAAMoB,eAAe,CAACG,IAAI;IAEnC,KAAK;IACL;MACE,OAAOvB,KAAA,CAAMoB,eAAe,CAACI,QAAQ;EAAA;AAE3C"}
|
@@ -1,61 +0,0 @@
|
|
1
|
-
import * as React from 'react';
|
2
|
-
import { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';
|
3
|
-
import { useTabster } from './useTabster';
|
4
|
-
/**
|
5
|
-
* Returns a set of helper functions that will traverse focusable elements in the context of a root DOM element
|
6
|
-
*/
|
7
|
-
export const useFocusFinders = () => {
|
8
|
-
const tabster = useTabster();
|
9
|
-
const {
|
10
|
-
targetDocument
|
11
|
-
} = useFluent();
|
12
|
-
// Narrow props for now and let need dictate additional props in the future
|
13
|
-
const findAllFocusable = React.useCallback((container, acceptCondition) => {
|
14
|
-
return (tabster === null || tabster === void 0 ? void 0 : tabster.focusable.findAll({
|
15
|
-
container,
|
16
|
-
acceptCondition
|
17
|
-
})) || [];
|
18
|
-
}, [tabster]);
|
19
|
-
const findFirstFocusable = React.useCallback(container => {
|
20
|
-
return tabster === null || tabster === void 0 ? void 0 : tabster.focusable.findFirst({
|
21
|
-
container
|
22
|
-
});
|
23
|
-
}, [tabster]);
|
24
|
-
const findLastFocusable = React.useCallback(container => {
|
25
|
-
return tabster === null || tabster === void 0 ? void 0 : tabster.focusable.findLast({
|
26
|
-
container
|
27
|
-
});
|
28
|
-
}, [tabster]);
|
29
|
-
const findNextFocusable = React.useCallback((currentElement, options = {}) => {
|
30
|
-
if (!tabster || !targetDocument) {
|
31
|
-
return null;
|
32
|
-
}
|
33
|
-
const {
|
34
|
-
container = targetDocument.body
|
35
|
-
} = options;
|
36
|
-
return tabster.focusable.findNext({
|
37
|
-
currentElement,
|
38
|
-
container
|
39
|
-
});
|
40
|
-
}, [tabster, targetDocument]);
|
41
|
-
const findPrevFocusable = React.useCallback((currentElement, options = {}) => {
|
42
|
-
if (!tabster || !targetDocument) {
|
43
|
-
return null;
|
44
|
-
}
|
45
|
-
const {
|
46
|
-
container = targetDocument.body
|
47
|
-
} = options;
|
48
|
-
return tabster.focusable.findPrev({
|
49
|
-
currentElement,
|
50
|
-
container
|
51
|
-
});
|
52
|
-
}, [tabster, targetDocument]);
|
53
|
-
return {
|
54
|
-
findAllFocusable,
|
55
|
-
findFirstFocusable,
|
56
|
-
findLastFocusable,
|
57
|
-
findNextFocusable,
|
58
|
-
findPrevFocusable
|
59
|
-
};
|
60
|
-
};
|
61
|
-
//# sourceMappingURL=useFocusFinders.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"names":["React","useFluent_unstable","useFluent","useTabster","useFocusFinders","tabster","targetDocument","findAllFocusable","useCallback","container","acceptCondition","focusable","findAll","findFirstFocusable","findFirst","findLastFocusable","findLast","findNextFocusable","currentElement","options","body","findNext","findPrevFocusable","findPrev"],"sources":["../../src/hooks/useFocusFinders.ts"],"sourcesContent":["import * as React from 'react';\nimport { Types as TabsterTypes } from 'tabster';\nimport { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\nimport { useTabster } from './useTabster';\n\n/**\n * Returns a set of helper functions that will traverse focusable elements in the context of a root DOM element\n */\nexport const useFocusFinders = () => {\n const tabster = useTabster();\n const { targetDocument } = useFluent();\n\n // Narrow props for now and let need dictate additional props in the future\n const findAllFocusable = React.useCallback(\n (container: HTMLElement, acceptCondition?: (el: HTMLElement) => boolean) =>\n tabster?.focusable.findAll({ container, acceptCondition }) || [],\n [tabster],\n );\n\n const findFirstFocusable = React.useCallback(\n (container: HTMLElement) => tabster?.focusable.findFirst({ container }),\n [tabster],\n );\n\n const findLastFocusable = React.useCallback(\n (container: HTMLElement) => tabster?.focusable.findLast({ container }),\n [tabster],\n );\n\n const findNextFocusable = React.useCallback(\n (currentElement: HTMLElement, options: Pick<Partial<TabsterTypes.FindNextProps>, 'container'> = {}) => {\n if (!tabster || !targetDocument) {\n return null;\n }\n\n const { container = targetDocument.body } = options;\n\n return tabster.focusable.findNext({ currentElement, container });\n },\n [tabster, targetDocument],\n );\n\n const findPrevFocusable = React.useCallback(\n (currentElement: HTMLElement, options: Pick<Partial<TabsterTypes.FindNextProps>, 'container'> = {}) => {\n if (!tabster || !targetDocument) {\n return null;\n }\n\n const { container = targetDocument.body } = options;\n\n return tabster.focusable.findPrev({ currentElement, container });\n },\n [tabster, targetDocument],\n );\n\n return {\n findAllFocusable,\n findFirstFocusable,\n findLastFocusable,\n findNextFocusable,\n findPrevFocusable,\n };\n};\n"],"mappings":"AAAA,YAAYA,KAAA,MAAW;AAEvB,SAASC,kBAAA,IAAsBC,SAAS,QAAQ;AAChD,SAASC,UAAU,QAAQ;AAE3B;;;AAGA,OAAO,MAAMC,eAAA,GAAkBA,CAAA,KAAM;EACnC,MAAMC,OAAA,GAAUF,UAAA;EAChB,MAAM;IAAEG;EAAc,CAAE,GAAGJ,SAAA;EAE3B;EACA,MAAMK,gBAAA,GAAmBP,KAAA,CAAMQ,WAAW,CACxC,CAACC,SAAA,EAAwBC,eAAA;IACvB,QAAAL,OAAA,aAAAA,OAAA,uBAAAA,OAAA,CAASM,SAAS,CAACC,OAAO,CAAC;MAAEH,SAAA;MAAWC;IAAgB,EAAE,KAAI,EAAE;KAClE,CAACL,OAAA,CAAQ;EAGX,MAAMQ,kBAAA,GAAqBb,KAAA,CAAMQ,WAAW,CACzCC,SAAA;IAA2B,OAAAJ,OAAA,aAAAA,OAAA,uBAAAA,OAAA,CAASM,SAAS,CAACG,SAAS,CAAC;MAAEL;IAAU,EAAE;KACvE,CAACJ,OAAA,CAAQ;EAGX,MAAMU,iBAAA,GAAoBf,KAAA,CAAMQ,WAAW,CACxCC,SAAA;IAA2B,OAAAJ,OAAA,aAAAA,OAAA,uBAAAA,OAAA,CAASM,SAAS,CAACK,QAAQ,CAAC;MAAEP;IAAU,EAAE;KACtE,CAACJ,OAAA,CAAQ;EAGX,MAAMY,iBAAA,GAAoBjB,KAAA,CAAMQ,WAAW,CACzC,CAACU,cAAA,EAA6BC,OAAA,GAAkE,CAAC,CAAC,KAAK;IACrG,IAAI,CAACd,OAAA,IAAW,CAACC,cAAA,EAAgB;MAC/B,OAAO,IAAI;IACb;IAEA,MAAM;MAAEG,SAAA,GAAYH,cAAA,CAAec;IAAI,CAAE,GAAGD,OAAA;IAE5C,OAAOd,OAAA,CAAQM,SAAS,CAACU,QAAQ,CAAC;MAAEH,cAAA;MAAgBT;IAAU;EAChE,GACA,CAACJ,OAAA,EAASC,cAAA,CAAe;EAG3B,MAAMgB,iBAAA,GAAoBtB,KAAA,CAAMQ,WAAW,CACzC,CAACU,cAAA,EAA6BC,OAAA,GAAkE,CAAC,CAAC,KAAK;IACrG,IAAI,CAACd,OAAA,IAAW,CAACC,cAAA,EAAgB;MAC/B,OAAO,IAAI;IACb;IAEA,MAAM;MAAEG,SAAA,GAAYH,cAAA,CAAec;IAAI,CAAE,GAAGD,OAAA;IAE5C,OAAOd,OAAA,CAAQM,SAAS,CAACY,QAAQ,CAAC;MAAEL,cAAA;MAAgBT;IAAU;EAChE,GACA,CAACJ,OAAA,EAASC,cAAA,CAAe;EAG3B,OAAO;IACLC,gBAAA;IACAM,kBAAA;IACAE,iBAAA;IACAE,iBAAA;IACAK;EACF;AACF"}
|
@@ -1,16 +0,0 @@
|
|
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(options = {}) {
|
5
|
-
const contentValue = useFluent();
|
6
|
-
const scopeRef = React.useRef(null);
|
7
|
-
var _options_targetDocument;
|
8
|
-
const targetDocument = (_options_targetDocument = options.targetDocument) !== null && _options_targetDocument !== void 0 ? _options_targetDocument : contentValue.targetDocument;
|
9
|
-
React.useEffect(() => {
|
10
|
-
if ((targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.defaultView) && scopeRef.current) {
|
11
|
-
return applyFocusVisiblePolyfill(scopeRef.current, targetDocument.defaultView);
|
12
|
-
}
|
13
|
-
}, [scopeRef, targetDocument]);
|
14
|
-
return scopeRef;
|
15
|
-
}
|
16
|
-
//# sourceMappingURL=useFocusVisible.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"names":["React","useFluent_unstable","useFluent","applyFocusVisiblePolyfill","useFocusVisible","options","contentValue","scopeRef","useRef","_options_targetDocument","targetDocument","useEffect","defaultView","current"],"sources":["../../src/hooks/useFocusVisible.ts"],"sourcesContent":["import * as React from 'react';\nimport { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\n\nimport { applyFocusVisiblePolyfill } from '../focus/focusVisiblePolyfill';\n\ntype UseFocusVisibleOptions = {\n targetDocument?: HTMLDocument;\n};\n\nexport function useFocusVisible<TElement extends HTMLElement = HTMLElement>(options: UseFocusVisibleOptions = {}) {\n const contentValue = useFluent();\n const scopeRef = React.useRef<TElement>(null);\n\n const targetDocument = options.targetDocument ?? contentValue.targetDocument;\n\n React.useEffect(() => {\n if (targetDocument?.defaultView && scopeRef.current) {\n return applyFocusVisiblePolyfill(scopeRef.current, targetDocument.defaultView);\n }\n }, [scopeRef, targetDocument]);\n\n return scopeRef;\n}\n"],"mappings":"AAAA,YAAYA,KAAA,MAAW;AACvB,SAASC,kBAAA,IAAsBC,SAAS,QAAQ;AAEhD,SAASC,yBAAyB,QAAQ;AAM1C,OAAO,SAASC,gBAA4DC,OAAA,GAAkC,CAAC,CAAC,EAAE;EAChH,MAAMC,YAAA,GAAeJ,SAAA;EACrB,MAAMK,QAAA,GAAWP,KAAA,CAAMQ,MAAM,CAAW,IAAI;MAErBC,uBAAA;EAAvB,MAAMC,cAAA,GAAiB,CAAAD,uBAAA,GAAAJ,OAAA,CAAQK,cAAc,cAAtBD,uBAAA,cAAAA,uBAAA,GAA0BH,YAAA,CAAaI,cAAc;EAE5EV,KAAA,CAAMW,SAAS,CAAC,MAAM;IACpB,IAAI,CAAAD,cAAA,aAAAA,cAAA,uBAAAA,cAAA,CAAgBE,WAAW,KAAIL,QAAA,CAASM,OAAO,EAAE;MACnD,OAAOV,yBAAA,CAA0BI,QAAA,CAASM,OAAO,EAAEH,cAAA,CAAeE,WAAW;IAC/E;EACF,GAAG,CAACL,QAAA,EAAUG,cAAA,CAAe;EAE7B,OAAOH,QAAA;AACT"}
|
@@ -1,21 +0,0 @@
|
|
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
|
-
export function useFocusWithin() {
|
10
|
-
const {
|
11
|
-
targetDocument
|
12
|
-
} = useFluent();
|
13
|
-
const elementRef = React.useRef(null);
|
14
|
-
React.useEffect(() => {
|
15
|
-
if ((targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.defaultView) && elementRef.current) {
|
16
|
-
return applyFocusWithinPolyfill(elementRef.current, targetDocument.defaultView);
|
17
|
-
}
|
18
|
-
}, [elementRef, targetDocument]);
|
19
|
-
return elementRef;
|
20
|
-
}
|
21
|
-
//# sourceMappingURL=useFocusWithin.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"names":["React","useFluent_unstable","useFluent","applyFocusWithinPolyfill","useFocusWithin","targetDocument","elementRef","useRef","useEffect","defaultView","current"],"sources":["../../src/hooks/useFocusWithin.ts"],"sourcesContent":["import * as React from 'react';\nimport { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\nimport { applyFocusWithinPolyfill } from '../focus/focusWithinPolyfill';\n\n/**\n * A ponyfill that allows `:focus-within` to support visibility based on keyboard/mouse navigation\n * like `:focus-visible` https://github.com/WICG/focus-visible/issues/151\n * @returns ref to the element that uses `:focus-within` styles\n */\nexport function useFocusWithin<TElement extends HTMLElement = HTMLElement>() {\n const { targetDocument } = useFluent();\n const elementRef = React.useRef<TElement>(null);\n\n React.useEffect(() => {\n if (targetDocument?.defaultView && elementRef.current) {\n return applyFocusWithinPolyfill(elementRef.current, targetDocument.defaultView);\n }\n }, [elementRef, targetDocument]);\n\n return elementRef;\n}\n"],"mappings":"AAAA,YAAYA,KAAA,MAAW;AACvB,SAASC,kBAAA,IAAsBC,SAAS,QAAQ;AAChD,SAASC,wBAAwB,QAAQ;AAEzC;;;;;AAKA,OAAO,SAASC,eAAA,EAA6D;EAC3E,MAAM;IAAEC;EAAc,CAAE,GAAGH,SAAA;EAC3B,MAAMI,UAAA,GAAaN,KAAA,CAAMO,MAAM,CAAW,IAAI;EAE9CP,KAAA,CAAMQ,SAAS,CAAC,MAAM;IACpB,IAAI,CAAAH,cAAA,aAAAA,cAAA,uBAAAA,cAAA,CAAgBI,WAAW,KAAIH,UAAA,CAAWI,OAAO,EAAE;MACrD,OAAOP,wBAAA,CAAyBG,UAAA,CAAWI,OAAO,EAAEL,cAAA,CAAeI,WAAW;IAChF;EACF,GAAG,CAACH,UAAA,EAAYD,cAAA,CAAe;EAE/B,OAAOC,UAAA;AACT"}
|
@@ -1,31 +0,0 @@
|
|
1
|
-
import { Types, getGroupper } from 'tabster';
|
2
|
-
import { useTabsterAttributes } from './useTabsterAttributes';
|
3
|
-
import { useTabster } from './useTabster';
|
4
|
-
/**
|
5
|
-
* A hook that returns the necessary tabster attributes to support groupping.
|
6
|
-
* @param options - Options to configure keyboard navigation
|
7
|
-
*/
|
8
|
-
export const useFocusableGroup = options => {
|
9
|
-
const tabster = useTabster();
|
10
|
-
if (tabster) {
|
11
|
-
getGroupper(tabster);
|
12
|
-
}
|
13
|
-
return useTabsterAttributes({
|
14
|
-
groupper: {
|
15
|
-
tabbability: getTabbability(options === null || options === void 0 ? void 0 : options.tabBehavior)
|
16
|
-
}
|
17
|
-
});
|
18
|
-
};
|
19
|
-
const getTabbability = tabBehavior => {
|
20
|
-
switch (tabBehavior) {
|
21
|
-
case 'unlimited':
|
22
|
-
return Types.GroupperTabbabilities.Unlimited;
|
23
|
-
case 'limited':
|
24
|
-
return Types.GroupperTabbabilities.Limited;
|
25
|
-
case 'limited-trap-focus':
|
26
|
-
return Types.GroupperTabbabilities.LimitedTrapFocus;
|
27
|
-
default:
|
28
|
-
return undefined;
|
29
|
-
}
|
30
|
-
};
|
31
|
-
//# sourceMappingURL=useFocusableGroup.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"names":["Types","getGroupper","useTabsterAttributes","useTabster","useFocusableGroup","options","tabster","groupper","tabbability","getTabbability","tabBehavior","GroupperTabbabilities","Unlimited","Limited","LimitedTrapFocus","undefined"],"sources":["../../src/hooks/useFocusableGroup.ts"],"sourcesContent":["import { Types, getGroupper } from 'tabster';\nimport { useTabsterAttributes } from './useTabsterAttributes';\nimport { useTabster } from './useTabster';\n\nexport interface UseFocusableGroupOptions {\n /**\n * Behavior for the Tab key.\n */\n tabBehavior?: 'unlimited' | 'limited' | 'limited-trap-focus';\n}\n\n/**\n * A hook that returns the necessary tabster attributes to support groupping.\n * @param options - Options to configure keyboard navigation\n */\nexport const useFocusableGroup = (options?: UseFocusableGroupOptions): Types.TabsterDOMAttribute => {\n const tabster = useTabster();\n\n if (tabster) {\n getGroupper(tabster);\n }\n\n return useTabsterAttributes({\n groupper: {\n tabbability: getTabbability(options?.tabBehavior),\n },\n });\n};\n\nconst getTabbability = (\n tabBehavior?: UseFocusableGroupOptions['tabBehavior'],\n): Types.GroupperTabbability | undefined => {\n switch (tabBehavior) {\n case 'unlimited':\n return Types.GroupperTabbabilities.Unlimited;\n case 'limited':\n return Types.GroupperTabbabilities.Limited;\n case 'limited-trap-focus':\n return Types.GroupperTabbabilities.LimitedTrapFocus;\n default:\n return undefined;\n }\n};\n"],"mappings":"AAAA,SAASA,KAAK,EAAEC,WAAW,QAAQ;AACnC,SAASC,oBAAoB,QAAQ;AACrC,SAASC,UAAU,QAAQ;AAS3B;;;;AAIA,OAAO,MAAMC,iBAAA,GAAqBC,OAAA,IAAkE;EAClG,MAAMC,OAAA,GAAUH,UAAA;EAEhB,IAAIG,OAAA,EAAS;IACXL,WAAA,CAAYK,OAAA;EACd;EAEA,OAAOJ,oBAAA,CAAqB;IAC1BK,QAAA,EAAU;MACRC,WAAA,EAAaC,cAAA,CAAeJ,OAAA,aAAAA,OAAA,uBAAAA,OAAA,CAASK,WAAW;IAClD;EACF;AACF;AAEA,MAAMD,cAAA,GACJC,WAAA,IAC0C;EAC1C,QAAQA,WAAA;IACN,KAAK;MACH,OAAOV,KAAA,CAAMW,qBAAqB,CAACC,SAAS;IAC9C,KAAK;MACH,OAAOZ,KAAA,CAAMW,qBAAqB,CAACE,OAAO;IAC5C,KAAK;MACH,OAAOb,KAAA,CAAMW,qBAAqB,CAACG,gBAAgB;IACrD;MACE,OAAOC,SAAA;EAAA;AAEb"}
|
@@ -1,38 +0,0 @@
|
|
1
|
-
import { createKeyborg } from 'keyborg';
|
2
|
-
import { useEffect, useMemo, useRef } from 'react';
|
3
|
-
import { KEYBOARD_NAV_ATTRIBUTE } from '../focus/constants';
|
4
|
-
import { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';
|
5
|
-
/**
|
6
|
-
* Instantiates [keyborg](https://github.com/microsoft/keyborg) and adds `data-keyboard-nav`
|
7
|
-
* attribute to a referenced element to ensure keyboard navigation awareness
|
8
|
-
* synced to keyborg logic without having to cause a re-render on react tree.
|
9
|
-
*/
|
10
|
-
export function useKeyboardNavAttribute() {
|
11
|
-
const {
|
12
|
-
targetDocument
|
13
|
-
} = useFluent();
|
14
|
-
const keyborg = useMemo(() => targetDocument && createKeyborg(targetDocument.defaultView), [targetDocument]);
|
15
|
-
const ref = useRef(null);
|
16
|
-
useEffect(() => {
|
17
|
-
if (keyborg) {
|
18
|
-
setBooleanAttribute(ref, KEYBOARD_NAV_ATTRIBUTE, keyborg.isNavigatingWithKeyboard());
|
19
|
-
const cb = next => {
|
20
|
-
setBooleanAttribute(ref, KEYBOARD_NAV_ATTRIBUTE, next);
|
21
|
-
};
|
22
|
-
keyborg.subscribe(cb);
|
23
|
-
return () => keyborg.unsubscribe(cb);
|
24
|
-
}
|
25
|
-
}, [keyborg]);
|
26
|
-
return ref;
|
27
|
-
}
|
28
|
-
function setBooleanAttribute(elementRef, attribute, value) {
|
29
|
-
if (!elementRef.current) {
|
30
|
-
return;
|
31
|
-
}
|
32
|
-
if (value) {
|
33
|
-
elementRef.current.setAttribute(attribute, '');
|
34
|
-
} else {
|
35
|
-
elementRef.current.removeAttribute(attribute);
|
36
|
-
}
|
37
|
-
}
|
38
|
-
//# sourceMappingURL=useKeyboardNavAttribute.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"names":["createKeyborg","useEffect","useMemo","useRef","KEYBOARD_NAV_ATTRIBUTE","useFluent_unstable","useFluent","useKeyboardNavAttribute","targetDocument","keyborg","defaultView","ref","setBooleanAttribute","isNavigatingWithKeyboard","cb","next","subscribe","unsubscribe","elementRef","attribute","value","current","setAttribute","removeAttribute"],"sources":["../../src/hooks/useKeyboardNavAttribute.ts"],"sourcesContent":["import { createKeyborg } from 'keyborg';\nimport { useEffect, useMemo, useRef } from 'react';\nimport { KEYBOARD_NAV_ATTRIBUTE } from '../focus/constants';\nimport { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\nimport type { KeyborgCallback } from 'keyborg';\nimport type { RefObject } from 'react';\n\n/**\n * Instantiates [keyborg](https://github.com/microsoft/keyborg) and adds `data-keyboard-nav`\n * attribute to a referenced element to ensure keyboard navigation awareness\n * synced to keyborg logic without having to cause a re-render on react tree.\n */\nexport function useKeyboardNavAttribute<E extends HTMLElement>() {\n const { targetDocument } = useFluent();\n const keyborg = useMemo(() => targetDocument && createKeyborg(targetDocument.defaultView!), [targetDocument]);\n const ref = useRef<E>(null);\n useEffect(() => {\n if (keyborg) {\n setBooleanAttribute(ref, KEYBOARD_NAV_ATTRIBUTE, keyborg.isNavigatingWithKeyboard());\n const cb: KeyborgCallback = next => {\n setBooleanAttribute(ref, KEYBOARD_NAV_ATTRIBUTE, next);\n };\n keyborg.subscribe(cb);\n return () => keyborg.unsubscribe(cb);\n }\n }, [keyborg]);\n return ref;\n}\n\nfunction setBooleanAttribute(elementRef: RefObject<HTMLElement>, attribute: string, value: boolean) {\n if (!elementRef.current) {\n return;\n }\n if (value) {\n elementRef.current.setAttribute(attribute, '');\n } else {\n elementRef.current.removeAttribute(attribute);\n }\n}\n"],"mappings":"AAAA,SAASA,aAAa,QAAQ;AAC9B,SAASC,SAAS,EAAEC,OAAO,EAAEC,MAAM,QAAQ;AAC3C,SAASC,sBAAsB,QAAQ;AACvC,SAASC,kBAAA,IAAsBC,SAAS,QAAQ;AAIhD;;;;;AAKA,OAAO,SAASC,wBAAA,EAAiD;EAC/D,MAAM;IAAEC;EAAc,CAAE,GAAGF,SAAA;EAC3B,MAAMG,OAAA,GAAUP,OAAA,CAAQ,MAAMM,cAAA,IAAkBR,aAAA,CAAcQ,cAAA,CAAeE,WAAW,GAAI,CAACF,cAAA,CAAe;EAC5G,MAAMG,GAAA,GAAMR,MAAA,CAAU,IAAI;EAC1BF,SAAA,CAAU,MAAM;IACd,IAAIQ,OAAA,EAAS;MACXG,mBAAA,CAAoBD,GAAA,EAAKP,sBAAA,EAAwBK,OAAA,CAAQI,wBAAwB;MACjF,MAAMC,EAAA,GAAsBC,IAAA,IAAQ;QAClCH,mBAAA,CAAoBD,GAAA,EAAKP,sBAAA,EAAwBW,IAAA;MACnD;MACAN,OAAA,CAAQO,SAAS,CAACF,EAAA;MAClB,OAAO,MAAML,OAAA,CAAQQ,WAAW,CAACH,EAAA;IACnC;EACF,GAAG,CAACL,OAAA,CAAQ;EACZ,OAAOE,GAAA;AACT;AAEA,SAASC,oBAAoBM,UAAkC,EAAEC,SAAiB,EAAEC,KAAc,EAAE;EAClG,IAAI,CAACF,UAAA,CAAWG,OAAO,EAAE;IACvB;EACF;EACA,IAAID,KAAA,EAAO;IACTF,UAAA,CAAWG,OAAO,CAACC,YAAY,CAACH,SAAA,EAAW;EAC7C,OAAO;IACLD,UAAA,CAAWG,OAAO,CAACE,eAAe,CAACJ,SAAA;EACrC;AACF"}
|
@@ -1,42 +0,0 @@
|
|
1
|
-
import { useId } from '@fluentui/react-utilities';
|
2
|
-
import { useTabsterAttributes } from './useTabsterAttributes';
|
3
|
-
import { getDeloser, getModalizer } from 'tabster';
|
4
|
-
import { useTabster } from './useTabster';
|
5
|
-
/**
|
6
|
-
* Applies modal dialog behaviour through DOM attributes
|
7
|
-
* Modal element will focus trap and hide other content on the page
|
8
|
-
* The trigger element will be focused if focus is lost after the modal element is removed
|
9
|
-
*
|
10
|
-
* @returns DOM attributes to apply to the modal element and its trigger
|
11
|
-
*/
|
12
|
-
export const useModalAttributes = (options = {}) => {
|
13
|
-
const {
|
14
|
-
trapFocus,
|
15
|
-
alwaysFocusable,
|
16
|
-
legacyTrapFocus
|
17
|
-
} = options;
|
18
|
-
const tabster = useTabster();
|
19
|
-
// Initializes the modalizer and deloser APIs
|
20
|
-
if (tabster) {
|
21
|
-
getModalizer(tabster);
|
22
|
-
getDeloser(tabster);
|
23
|
-
}
|
24
|
-
const id = useId('modal-', options.id);
|
25
|
-
const modalAttributes = useTabsterAttributes({
|
26
|
-
deloser: {},
|
27
|
-
modalizer: {
|
28
|
-
id,
|
29
|
-
isOthersAccessible: !trapFocus,
|
30
|
-
isAlwaysAccessible: alwaysFocusable,
|
31
|
-
isTrapped: legacyTrapFocus && trapFocus
|
32
|
-
}
|
33
|
-
});
|
34
|
-
const triggerAttributes = useTabsterAttributes({
|
35
|
-
deloser: {}
|
36
|
-
});
|
37
|
-
return {
|
38
|
-
modalAttributes,
|
39
|
-
triggerAttributes
|
40
|
-
};
|
41
|
-
};
|
42
|
-
//# sourceMappingURL=useModalAttributes.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"names":["useId","useTabsterAttributes","getDeloser","getModalizer","useTabster","useModalAttributes","options","trapFocus","alwaysFocusable","legacyTrapFocus","tabster","id","modalAttributes","deloser","modalizer","isOthersAccessible","isAlwaysAccessible","isTrapped","triggerAttributes"],"sources":["../../src/hooks/useModalAttributes.ts"],"sourcesContent":["import { useId } from '@fluentui/react-utilities';\nimport { useTabsterAttributes } from './useTabsterAttributes';\nimport { getDeloser, getModalizer, Types as TabsterTypes } from 'tabster';\nimport { useTabster } from './useTabster';\n\nexport interface UseModalAttributesOptions {\n /**\n * Traps focus inside the elements the attributes are applied.\n * Prefer this to `legacyTrapFocus`\n * it forbids users to tab out of the focus trap into the actual browser.\n */\n trapFocus?: boolean;\n\n /**\n * Traps focus inside the elements the attributes are applied.\n * This prop enables legacy behavior to match previous versions of Fluent and is not\n * recommended for general use.\n * Enabling `legacyTrapFocus` prevents users from tabbing out of the focus trap and into\n * the actual browser. Prefer using `trapFocus` instead of this prop.\n */\n legacyTrapFocus?: boolean;\n\n /**\n * Always reachabled in Tab order\n */\n alwaysFocusable?: boolean;\n\n /**\n * Id to use for the modalizer. An id will be generated if not provided.\n */\n id?: string;\n}\n\n/**\n * Applies modal dialog behaviour through DOM attributes\n * Modal element will focus trap and hide other content on the page\n * The trigger element will be focused if focus is lost after the modal element is removed\n *\n * @returns DOM attributes to apply to the modal element and its trigger\n */\nexport const useModalAttributes = (\n options: UseModalAttributesOptions = {},\n): { modalAttributes: TabsterTypes.TabsterDOMAttribute; triggerAttributes: TabsterTypes.TabsterDOMAttribute } => {\n const { trapFocus, alwaysFocusable, legacyTrapFocus } = options;\n const tabster = useTabster();\n // Initializes the modalizer and deloser APIs\n if (tabster) {\n getModalizer(tabster);\n getDeloser(tabster);\n }\n\n const id = useId('modal-', options.id);\n const modalAttributes = useTabsterAttributes({\n deloser: {},\n modalizer: {\n id,\n isOthersAccessible: !trapFocus,\n isAlwaysAccessible: alwaysFocusable,\n isTrapped: legacyTrapFocus && trapFocus,\n },\n });\n\n const triggerAttributes = useTabsterAttributes({\n deloser: {},\n });\n\n return { modalAttributes, triggerAttributes };\n};\n"],"mappings":"AAAA,SAASA,KAAK,QAAQ;AACtB,SAASC,oBAAoB,QAAQ;AACrC,SAASC,UAAU,EAAEC,YAAY,QAA+B;AAChE,SAASC,UAAU,QAAQ;AA8B3B;;;;;;;AAOA,OAAO,MAAMC,kBAAA,GAAqBA,CAChCC,OAAA,GAAqC,CAAC,CAAC,KACwE;EAC/G,MAAM;IAAEC,SAAA;IAAWC,eAAA;IAAiBC;EAAe,CAAE,GAAGH,OAAA;EACxD,MAAMI,OAAA,GAAUN,UAAA;EAChB;EACA,IAAIM,OAAA,EAAS;IACXP,YAAA,CAAaO,OAAA;IACbR,UAAA,CAAWQ,OAAA;EACb;EAEA,MAAMC,EAAA,GAAKX,KAAA,CAAM,UAAUM,OAAA,CAAQK,EAAE;EACrC,MAAMC,eAAA,GAAkBX,oBAAA,CAAqB;IAC3CY,OAAA,EAAS,CAAC;IACVC,SAAA,EAAW;MACTH,EAAA;MACAI,kBAAA,EAAoB,CAACR,SAAA;MACrBS,kBAAA,EAAoBR,eAAA;MACpBS,SAAA,EAAWR,eAAA,IAAmBF;IAChC;EACF;EAEA,MAAMW,iBAAA,GAAoBjB,oBAAA,CAAqB;IAC7CY,OAAA,EAAS,CAAC;EACZ;EAEA,OAAO;IAAED,eAAA;IAAiBM;EAAkB;AAC9C"}
|
package/lib/hooks/useTabster.js
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
import * as React from 'react';
|
2
|
-
import { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';
|
3
|
-
import { createTabster, disposeTabster } from 'tabster';
|
4
|
-
import { useIsomorphicLayoutEffect } from '@fluentui/react-utilities';
|
5
|
-
/**
|
6
|
-
* Tries to get a tabster instance on the current window or creates a new one
|
7
|
-
* Since Tabster is single instance only, feel free to call this hook to ensure Tabster exists if necessary
|
8
|
-
*
|
9
|
-
* @internal
|
10
|
-
* @returns Tabster core instance
|
11
|
-
*/
|
12
|
-
export const useTabster = () => {
|
13
|
-
const {
|
14
|
-
targetDocument
|
15
|
-
} = useFluent();
|
16
|
-
const defaultView = (targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.defaultView) || undefined;
|
17
|
-
const tabster = React.useMemo(() => {
|
18
|
-
if (!defaultView) {
|
19
|
-
return null;
|
20
|
-
}
|
21
|
-
return createTabster(defaultView, {
|
22
|
-
autoRoot: {},
|
23
|
-
controlTab: false
|
24
|
-
});
|
25
|
-
}, [defaultView]);
|
26
|
-
useIsomorphicLayoutEffect(() => {
|
27
|
-
return () => {
|
28
|
-
if (tabster) {
|
29
|
-
disposeTabster(tabster);
|
30
|
-
}
|
31
|
-
};
|
32
|
-
}, [tabster]);
|
33
|
-
return tabster;
|
34
|
-
};
|
35
|
-
//# sourceMappingURL=useTabster.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"names":["React","useFluent_unstable","useFluent","createTabster","disposeTabster","useIsomorphicLayoutEffect","useTabster","targetDocument","defaultView","undefined","tabster","useMemo","autoRoot","controlTab"],"sources":["../../src/hooks/useTabster.ts"],"sourcesContent":["import * as React from 'react';\nimport { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\nimport { createTabster, disposeTabster, Types as TabsterTypes } from 'tabster';\nimport { useIsomorphicLayoutEffect } from '@fluentui/react-utilities';\n\n/**\n * Tries to get a tabster instance on the current window or creates a new one\n * Since Tabster is single instance only, feel free to call this hook to ensure Tabster exists if necessary\n *\n * @internal\n * @returns Tabster core instance\n */\nexport const useTabster = (): TabsterTypes.TabsterCore | null => {\n const { targetDocument } = useFluent();\n\n const defaultView = targetDocument?.defaultView || undefined;\n const tabster = React.useMemo(() => {\n if (!defaultView) {\n return null;\n }\n\n return createTabster(defaultView, { autoRoot: {}, controlTab: false });\n }, [defaultView]);\n\n useIsomorphicLayoutEffect(() => {\n return () => {\n if (tabster) {\n disposeTabster(tabster);\n }\n };\n }, [tabster]);\n\n return tabster;\n};\n"],"mappings":"AAAA,YAAYA,KAAA,MAAW;AACvB,SAASC,kBAAA,IAAsBC,SAAS,QAAQ;AAChD,SAASC,aAAa,EAAEC,cAAc,QAA+B;AACrE,SAASC,yBAAyB,QAAQ;AAE1C;;;;;;;AAOA,OAAO,MAAMC,UAAA,GAAaA,CAAA,KAAuC;EAC/D,MAAM;IAAEC;EAAc,CAAE,GAAGL,SAAA;EAE3B,MAAMM,WAAA,GAAc,CAAAD,cAAA,aAAAA,cAAA,uBAAAA,cAAA,CAAgBC,WAAW,KAAIC,SAAA;EACnD,MAAMC,OAAA,GAAUV,KAAA,CAAMW,OAAO,CAAC,MAAM;IAClC,IAAI,CAACH,WAAA,EAAa;MAChB,OAAO,IAAI;IACb;IAEA,OAAOL,aAAA,CAAcK,WAAA,EAAa;MAAEI,QAAA,EAAU,CAAC;MAAGC,UAAA,EAAY;IAAM;EACtE,GAAG,CAACL,WAAA,CAAY;EAEhBH,yBAAA,CAA0B,MAAM;IAC9B,OAAO,MAAM;MACX,IAAIK,OAAA,EAAS;QACXN,cAAA,CAAeM,OAAA;MACjB;IACF;EACF,GAAG,CAACA,OAAA,CAAQ;EAEZ,OAAOA,OAAA;AACT"}
|
@@ -1,13 +0,0 @@
|
|
1
|
-
import { getTabsterAttribute } from 'tabster';
|
2
|
-
import { useTabster } from './useTabster';
|
3
|
-
/**
|
4
|
-
* @internal
|
5
|
-
* Hook that returns tabster attributes while ensuring tabster exists
|
6
|
-
*/
|
7
|
-
export const useTabsterAttributes = props => {
|
8
|
-
// A tabster instance is not necessary to generate tabster attributes
|
9
|
-
// but calling the hook will ensure that a tabster instance exists internally and avoids consumers doing the same
|
10
|
-
useTabster();
|
11
|
-
return getTabsterAttribute(props);
|
12
|
-
};
|
13
|
-
//# sourceMappingURL=useTabsterAttributes.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"names":["getTabsterAttribute","useTabster","useTabsterAttributes","props"],"sources":["../../src/hooks/useTabsterAttributes.ts"],"sourcesContent":["import { getTabsterAttribute, Types as TabsterTypes } from 'tabster';\nimport { useTabster } from './useTabster';\n\n/**\n * @internal\n * Hook that returns tabster attributes while ensuring tabster exists\n */\nexport const useTabsterAttributes = (props: TabsterTypes.TabsterAttributeProps): TabsterTypes.TabsterDOMAttribute => {\n // A tabster instance is not necessary to generate tabster attributes\n // but calling the hook will ensure that a tabster instance exists internally and avoids consumers doing the same\n useTabster();\n\n return getTabsterAttribute(props);\n};\n"],"mappings":"AAAA,SAASA,mBAAmB,QAA+B;AAC3D,SAASC,UAAU,QAAQ;AAE3B;;;;AAIA,OAAO,MAAMC,oBAAA,GAAwBC,KAAA,IAAgF;EACnH;EACA;EACAF,UAAA;EAEA,OAAOD,mBAAA,CAAoBG,KAAA;AAC7B"}
|
package/lib/index.js
DELETED
@@ -1,4 +0,0 @@
|
|
1
|
-
export { useArrowNavigationGroup, useFocusableGroup, useFocusFinders, useFocusVisible, useFocusWithin, useKeyboardNavAttribute, useModalAttributes, useTabsterAttributes } from './hooks/index';
|
2
|
-
export { createCustomFocusIndicatorStyle, createFocusOutlineStyle } from './focus/index';
|
3
|
-
export { applyFocusVisiblePolyfill } from './focus/index';
|
4
|
-
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"names":["useArrowNavigationGroup","useFocusableGroup","useFocusFinders","useFocusVisible","useFocusWithin","useKeyboardNavAttribute","useModalAttributes","useTabsterAttributes","createCustomFocusIndicatorStyle","createFocusOutlineStyle","applyFocusVisiblePolyfill"],"sources":["../src/index.ts"],"sourcesContent":["export {\n useArrowNavigationGroup,\n useFocusableGroup,\n useFocusFinders,\n useFocusVisible,\n useFocusWithin,\n useKeyboardNavAttribute,\n useModalAttributes,\n useTabsterAttributes,\n} from './hooks/index';\nexport type {\n UseArrowNavigationGroupOptions,\n UseFocusableGroupOptions,\n UseModalAttributesOptions,\n} from './hooks/index';\n\nexport { createCustomFocusIndicatorStyle, createFocusOutlineStyle } from './focus/index';\n\nexport type {\n CreateCustomFocusIndicatorStyleOptions,\n CreateFocusOutlineStyleOptions,\n FocusOutlineOffset,\n FocusOutlineStyleOptions,\n} from './focus/index';\n\nexport { applyFocusVisiblePolyfill } from './focus/index';\n"],"mappings":"AAAA,SACEA,uBAAuB,EACvBC,iBAAiB,EACjBC,eAAe,EACfC,eAAe,EACfC,cAAc,EACdC,uBAAuB,EACvBC,kBAAkB,EAClBC,oBAAoB,QACf;AAOP,SAASC,+BAA+B,EAAEC,uBAAuB,QAAQ;AASzE,SAASC,yBAAyB,QAAQ"}
|