@fluentui/react-tabster 9.7.4 → 9.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.json +77 -1
- package/CHANGELOG.md +29 -2
- package/dist/index.d.ts +3 -3
- package/lib/focus/constants.js +4 -7
- package/lib/focus/constants.js.map +1 -1
- package/lib/focus/createCustomFocusIndicatorStyle.js +9 -13
- package/lib/focus/createCustomFocusIndicatorStyle.js.map +1 -1
- package/lib/focus/createFocusOutlineStyle.js +49 -52
- package/lib/focus/createFocusOutlineStyle.js.map +1 -1
- package/lib/focus/focusVisiblePolyfill.js +56 -58
- package/lib/focus/focusVisiblePolyfill.js.map +1 -1
- package/lib/focus/focusWithinPolyfill.js +36 -38
- package/lib/focus/focusWithinPolyfill.js.map +1 -1
- package/lib/focus/index.js +0 -1
- package/lib/focus/index.js.map +1 -1
- package/lib/hooks/index.js +0 -1
- package/lib/hooks/index.js.map +1 -1
- package/lib/hooks/useArrowNavigationGroup.js +34 -41
- package/lib/hooks/useArrowNavigationGroup.js.map +1 -1
- package/lib/hooks/useFocusFinders.js +59 -55
- package/lib/hooks/useFocusFinders.js.map +1 -1
- package/lib/hooks/useFocusVisible.js +13 -11
- package/lib/hooks/useFocusVisible.js.map +1 -1
- package/lib/hooks/useFocusWithin.js +12 -13
- package/lib/hooks/useFocusWithin.js.map +1 -1
- package/lib/hooks/useFocusableGroup.js +20 -22
- package/lib/hooks/useFocusableGroup.js.map +1 -1
- package/lib/hooks/useKeyboardNavAttribute.js +27 -27
- package/lib/hooks/useKeyboardNavAttribute.js.map +1 -1
- package/lib/hooks/useModalAttributes.js +24 -30
- package/lib/hooks/useModalAttributes.js.map +1 -1
- package/lib/hooks/useTabster.js +24 -24
- package/lib/hooks/useTabster.js.map +1 -1
- package/lib/hooks/useTabsterAttributes.js +5 -7
- package/lib/hooks/useTabsterAttributes.js.map +1 -1
- package/lib/index.js +0 -1
- package/lib/index.js.map +1 -1
- package/lib-commonjs/focus/constants.js +1 -3
- package/lib-commonjs/focus/constants.js.map +1 -1
- package/lib-commonjs/focus/createCustomFocusIndicatorStyle.js +1 -3
- package/lib-commonjs/focus/createCustomFocusIndicatorStyle.js.map +1 -1
- package/lib-commonjs/focus/createFocusOutlineStyle.js +19 -12
- package/lib-commonjs/focus/createFocusOutlineStyle.js.map +1 -1
- package/lib-commonjs/focus/focusVisiblePolyfill.js +1 -3
- package/lib-commonjs/focus/focusVisiblePolyfill.js.map +1 -1
- package/lib-commonjs/focus/focusWithinPolyfill.js +1 -3
- package/lib-commonjs/focus/focusWithinPolyfill.js.map +1 -1
- package/lib-commonjs/focus/index.js +0 -3
- package/lib-commonjs/focus/index.js.map +1 -1
- package/lib-commonjs/hooks/index.js +0 -3
- package/lib-commonjs/hooks/index.js.map +1 -1
- package/lib-commonjs/hooks/useArrowNavigationGroup.js +4 -5
- package/lib-commonjs/hooks/useArrowNavigationGroup.js.map +1 -1
- package/lib-commonjs/hooks/useFocusFinders.js +1 -3
- package/lib-commonjs/hooks/useFocusFinders.js.map +1 -1
- package/lib-commonjs/hooks/useFocusVisible.js +1 -3
- package/lib-commonjs/hooks/useFocusVisible.js.map +1 -1
- package/lib-commonjs/hooks/useFocusWithin.js +1 -3
- package/lib-commonjs/hooks/useFocusWithin.js.map +1 -1
- package/lib-commonjs/hooks/useFocusableGroup.js +1 -3
- package/lib-commonjs/hooks/useFocusableGroup.js.map +1 -1
- package/lib-commonjs/hooks/useKeyboardNavAttribute.js +1 -3
- package/lib-commonjs/hooks/useKeyboardNavAttribute.js.map +1 -1
- package/lib-commonjs/hooks/useModalAttributes.js +1 -3
- package/lib-commonjs/hooks/useModalAttributes.js.map +1 -1
- package/lib-commonjs/hooks/useTabster.js +1 -3
- package/lib-commonjs/hooks/useTabster.js.map +1 -1
- package/lib-commonjs/hooks/useTabsterAttributes.js +1 -3
- package/lib-commonjs/hooks/useTabsterAttributes.js.map +1 -1
- package/lib-commonjs/index.js +0 -3
- package/lib-commonjs/index.js.map +1 -1
- package/package.json +6 -6
package/CHANGELOG.json
CHANGED
@@ -2,7 +2,83 @@
|
|
2
2
|
"name": "@fluentui/react-tabster",
|
3
3
|
"entries": [
|
4
4
|
{
|
5
|
-
"date": "
|
5
|
+
"date": "Tue, 20 Jun 2023 12:34:48 GMT",
|
6
|
+
"tag": "@fluentui/react-tabster_v9.8.0",
|
7
|
+
"version": "9.8.0",
|
8
|
+
"comments": {
|
9
|
+
"patch": [
|
10
|
+
{
|
11
|
+
"author": "martinhochel@microsoft.com",
|
12
|
+
"package": "@fluentui/react-tabster",
|
13
|
+
"commit": "cf6b94ba6559236150bc1f1814b023607edaeb20",
|
14
|
+
"comment": "chore: migrate to ts 4.7 which wont emit undefined anymore for optional arguments"
|
15
|
+
}
|
16
|
+
],
|
17
|
+
"minor": [
|
18
|
+
{
|
19
|
+
"author": "jukapsia@microsoft.com",
|
20
|
+
"package": "@fluentui/react-tabster",
|
21
|
+
"commit": "1a277b9c4d55bc1b7c65a73383425b1934ec1dad",
|
22
|
+
"comment": "useArrowNavigationGroup grid-linear axis"
|
23
|
+
},
|
24
|
+
{
|
25
|
+
"author": "beachball",
|
26
|
+
"package": "@fluentui/react-tabster",
|
27
|
+
"comment": "Bump @fluentui/react-shared-contexts to v9.5.1",
|
28
|
+
"commit": "81c9b35e0830297b2aca2cece2ae67b3899c4647"
|
29
|
+
},
|
30
|
+
{
|
31
|
+
"author": "beachball",
|
32
|
+
"package": "@fluentui/react-tabster",
|
33
|
+
"comment": "Bump @fluentui/react-theme to v9.1.9",
|
34
|
+
"commit": "81c9b35e0830297b2aca2cece2ae67b3899c4647"
|
35
|
+
},
|
36
|
+
{
|
37
|
+
"author": "beachball",
|
38
|
+
"package": "@fluentui/react-tabster",
|
39
|
+
"comment": "Bump @fluentui/react-utilities to v9.9.3",
|
40
|
+
"commit": "81c9b35e0830297b2aca2cece2ae67b3899c4647"
|
41
|
+
}
|
42
|
+
]
|
43
|
+
}
|
44
|
+
},
|
45
|
+
{
|
46
|
+
"date": "Wed, 31 May 2023 06:46:20 GMT",
|
47
|
+
"tag": "@fluentui/react-tabster_v9.7.5",
|
48
|
+
"version": "9.7.5",
|
49
|
+
"comments": {
|
50
|
+
"patch": [
|
51
|
+
{
|
52
|
+
"author": "seanmonahan@microsoft.com",
|
53
|
+
"package": "@fluentui/react-tabster",
|
54
|
+
"commit": "d640b972d7ac86bfb76ae6c6329f12cdd33b3b7c",
|
55
|
+
"comment": "chore: Update Griffel to v1.5.7."
|
56
|
+
},
|
57
|
+
{
|
58
|
+
"author": "marcosvmmoura@gmail.com",
|
59
|
+
"package": "@fluentui/react-tabster",
|
60
|
+
"commit": "d6b67f35176ab121fa3c3b7dbef32871d2f785e6",
|
61
|
+
"comment": "fix: createFocusOutlineStyle cannot work with CSS variables"
|
62
|
+
},
|
63
|
+
{
|
64
|
+
"author": "beachball",
|
65
|
+
"package": "@fluentui/react-tabster",
|
66
|
+
"comment": "Bump @fluentui/react-utilities to v9.9.2",
|
67
|
+
"commit": "17ca96c6b7f684f36a5c63e40e78b4986a86c713"
|
68
|
+
}
|
69
|
+
],
|
70
|
+
"none": [
|
71
|
+
{
|
72
|
+
"author": "martinhochel@microsoft.com",
|
73
|
+
"package": "@fluentui/react-tabster",
|
74
|
+
"commit": "4b637ced41e430bf8d79c7fc67c103d5efdfd3a8",
|
75
|
+
"comment": "fix: tweak type errors exposed in ts 4.5"
|
76
|
+
}
|
77
|
+
]
|
78
|
+
}
|
79
|
+
},
|
80
|
+
{
|
81
|
+
"date": "Thu, 25 May 2023 10:00:48 GMT",
|
6
82
|
"tag": "@fluentui/react-tabster_v9.7.4",
|
7
83
|
"version": "9.7.4",
|
8
84
|
"comments": {
|
package/CHANGELOG.md
CHANGED
@@ -1,12 +1,39 @@
|
|
1
1
|
# Change Log - @fluentui/react-tabster
|
2
2
|
|
3
|
-
This log was last generated on
|
3
|
+
This log was last generated on Tue, 20 Jun 2023 12:34:48 GMT and should not be manually modified.
|
4
4
|
|
5
5
|
<!-- Start content -->
|
6
6
|
|
7
|
+
## [9.8.0](https://github.com/microsoft/fluentui/tree/@fluentui/react-tabster_v9.8.0)
|
8
|
+
|
9
|
+
Tue, 20 Jun 2023 12:34:48 GMT
|
10
|
+
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-tabster_v9.7.5..@fluentui/react-tabster_v9.8.0)
|
11
|
+
|
12
|
+
### Minor changes
|
13
|
+
|
14
|
+
- useArrowNavigationGroup grid-linear axis ([PR #28253](https://github.com/microsoft/fluentui/pull/28253) by jukapsia@microsoft.com)
|
15
|
+
- Bump @fluentui/react-shared-contexts to v9.5.1 ([PR #28229](https://github.com/microsoft/fluentui/pull/28229) by beachball)
|
16
|
+
- Bump @fluentui/react-theme to v9.1.9 ([PR #28229](https://github.com/microsoft/fluentui/pull/28229) by beachball)
|
17
|
+
- Bump @fluentui/react-utilities to v9.9.3 ([PR #28229](https://github.com/microsoft/fluentui/pull/28229) by beachball)
|
18
|
+
|
19
|
+
### Patches
|
20
|
+
|
21
|
+
- chore: migrate to ts 4.7 which wont emit undefined anymore for optional arguments ([PR #28067](https://github.com/microsoft/fluentui/pull/28067) by martinhochel@microsoft.com)
|
22
|
+
|
23
|
+
## [9.7.5](https://github.com/microsoft/fluentui/tree/@fluentui/react-tabster_v9.7.5)
|
24
|
+
|
25
|
+
Wed, 31 May 2023 06:46:20 GMT
|
26
|
+
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-tabster_v9.7.4..@fluentui/react-tabster_v9.7.5)
|
27
|
+
|
28
|
+
### Patches
|
29
|
+
|
30
|
+
- chore: Update Griffel to v1.5.7. ([PR #27925](https://github.com/microsoft/fluentui/pull/27925) by seanmonahan@microsoft.com)
|
31
|
+
- fix: createFocusOutlineStyle cannot work with CSS variables ([PR #27966](https://github.com/microsoft/fluentui/pull/27966) by marcosvmmoura@gmail.com)
|
32
|
+
- Bump @fluentui/react-utilities to v9.9.2 ([PR #28054](https://github.com/microsoft/fluentui/pull/28054) by beachball)
|
33
|
+
|
7
34
|
## [9.7.4](https://github.com/microsoft/fluentui/tree/@fluentui/react-tabster_v9.7.4)
|
8
35
|
|
9
|
-
Thu, 25 May 2023
|
36
|
+
Thu, 25 May 2023 10:00:48 GMT
|
10
37
|
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-tabster_v9.7.3..@fluentui/react-tabster_v9.7.4)
|
11
38
|
|
12
39
|
### Patches
|
package/dist/index.d.ts
CHANGED
@@ -78,7 +78,7 @@ export declare interface UseArrowNavigationGroupOptions {
|
|
78
78
|
* Focus will navigate vertically, horizontally or in both directions (grid), defaults to horizontally
|
79
79
|
* @defaultValue vertical
|
80
80
|
*/
|
81
|
-
axis?: 'vertical' | 'horizontal' | 'grid' | 'both';
|
81
|
+
axis?: 'vertical' | 'horizontal' | 'grid' | 'grid-linear' | 'both';
|
82
82
|
/**
|
83
83
|
* Focus will cycle to the first/last elements of the group without stopping
|
84
84
|
*/
|
@@ -108,7 +108,7 @@ export declare interface UseArrowNavigationGroupOptions {
|
|
108
108
|
* A hook that returns the necessary tabster attributes to support groupping.
|
109
109
|
* @param options - Options to configure keyboard navigation
|
110
110
|
*/
|
111
|
-
export declare const useFocusableGroup: (options?: UseFocusableGroupOptions
|
111
|
+
export declare const useFocusableGroup: (options?: UseFocusableGroupOptions) => Types.TabsterDOMAttribute;
|
112
112
|
|
113
113
|
export declare interface UseFocusableGroupOptions {
|
114
114
|
/**
|
@@ -131,7 +131,7 @@ export declare const useFocusFinders: () => {
|
|
131
131
|
export declare function useFocusVisible<TElement extends HTMLElement = HTMLElement>(options?: UseFocusVisibleOptions): React_2.RefObject<TElement>;
|
132
132
|
|
133
133
|
declare type UseFocusVisibleOptions = {
|
134
|
-
targetDocument?:
|
134
|
+
targetDocument?: Document;
|
135
135
|
};
|
136
136
|
|
137
137
|
/**
|
package/lib/focus/constants.js
CHANGED
@@ -2,14 +2,11 @@ export const KEYBOARD_NAV_ATTRIBUTE = 'data-keyboard-nav';
|
|
2
2
|
export const KEYBOARD_NAV_SELECTOR = `:global([${KEYBOARD_NAV_ATTRIBUTE}])`;
|
3
3
|
/**
|
4
4
|
* @internal
|
5
|
-
*/
|
6
|
-
export const FOCUS_VISIBLE_ATTR = 'data-fui-focus-visible';
|
5
|
+
*/ export const FOCUS_VISIBLE_ATTR = 'data-fui-focus-visible';
|
7
6
|
/**
|
8
7
|
* @internal
|
9
|
-
*/
|
10
|
-
export const FOCUS_WITHIN_ATTR = 'data-fui-focus-within';
|
8
|
+
*/ export const FOCUS_WITHIN_ATTR = 'data-fui-focus-within';
|
11
9
|
export const defaultOptions = {
|
12
|
-
|
13
|
-
|
10
|
+
style: {},
|
11
|
+
selector: 'focus'
|
14
12
|
};
|
15
|
-
//# sourceMappingURL=constants.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"sources":["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"],"names":["KEYBOARD_NAV_ATTRIBUTE","KEYBOARD_NAV_SELECTOR","FOCUS_VISIBLE_ATTR","FOCUS_WITHIN_ATTR","defaultOptions","style","selector"],"mappings":"AAAA,OAAO,MAAMA,yBAAyB,oBAA6B;AACnE,OAAO,MAAMC,wBAAwB,CAAC,SAAS,EAAED,uBAAuB,EAAE,CAAC,CAAU;AAErF;;CAEC,GACD,OAAO,MAAME,qBAAqB,yBAAyB;AAE3D;;CAEC,GACD,OAAO,MAAMC,oBAAoB,wBAAwB;AACzD,OAAO,MAAMC,iBAAiB;IAC5BC,OAAO,CAAC;IACRC,UAAU;AACZ,EAAW"}
|
@@ -5,17 +5,13 @@ import { defaultOptions, FOCUS_VISIBLE_ATTR, FOCUS_WITHIN_ATTR } from './constan
|
|
5
5
|
*
|
6
6
|
* @param style - styling applied on focus, defaults to @see getDefaultFocusOutlineStyles
|
7
7
|
* @param options - Configure the style of the focus outline
|
8
|
-
*/
|
9
|
-
|
10
|
-
|
11
|
-
}
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
[`&[${FOCUS_WITHIN_ATTR}]:${selector}`]: style
|
18
|
-
})
|
19
|
-
};
|
8
|
+
*/ export function createCustomFocusIndicatorStyle(style, { selector =defaultOptions.selector } = defaultOptions) {
|
9
|
+
return {
|
10
|
+
...selector === 'focus' && {
|
11
|
+
[`&[${FOCUS_VISIBLE_ATTR}]`]: style
|
12
|
+
},
|
13
|
+
...selector === 'focus-within' && {
|
14
|
+
[`&[${FOCUS_WITHIN_ATTR}]:${selector}`]: style
|
15
|
+
}
|
16
|
+
};
|
20
17
|
}
|
21
|
-
//# sourceMappingURL=createCustomFocusIndicatorStyle.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"sources":["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 * @deprecated The custom focus indicator no longer affects outline styles. Outline is overridden\n * in the default focus indicator function, `createFocusOutlineStyle`.\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 { selector = defaultOptions.selector }: CreateCustomFocusIndicatorStyleOptions = defaultOptions,\n): TStyle extends GriffelStyle ? GriffelStyle : GriffelResetStyle {\n return {\n ...(selector === 'focus' && {\n [`&[${FOCUS_VISIBLE_ATTR}]`]: style,\n }),\n ...(selector === 'focus-within' && {\n [`&[${FOCUS_WITHIN_ATTR}]:${selector}`]: style,\n }),\n };\n}\n"],"names":["defaultOptions","FOCUS_VISIBLE_ATTR","FOCUS_WITHIN_ATTR","createCustomFocusIndicatorStyle","style","selector"],"mappings":"AAAA,SAASA,cAAc,EAAEC,kBAAkB,EAAEC,iBAAiB,QAAQ,cAAc;AAuBpF;;;;;;CAMC,GACD,OAAO,SAASC,gCACdC,KAAa,EACb,EAAEC,UAAWL,eAAeK,QAAQ,CAAA,EAA0C,GAAGL,cAAc,EAC/B;IAChE,OAAO;QACL,GAAIK,aAAa,WAAW;YAC1B,CAAC,CAAC,EAAE,EAAEJ,mBAAmB,CAAC,CAAC,CAAC,EAAEG;QAChC,CAAC;QACD,GAAIC,aAAa,kBAAkB;YACjC,CAAC,CAAC,EAAE,EAAEH,kBAAkB,EAAE,EAAEG,SAAS,CAAC,CAAC,EAAED;QAC3C,CAAC;IACH;AACF,CAAC"}
|
@@ -2,41 +2,44 @@ import { tokens } from '@fluentui/react-theme';
|
|
2
2
|
import { shorthands } from '@griffel/react';
|
3
3
|
import { createCustomFocusIndicatorStyle } from './createCustomFocusIndicatorStyle';
|
4
4
|
import { defaultOptions } from './constants';
|
5
|
+
/**
|
6
|
+
* Get the position of the focus outline
|
7
|
+
*
|
8
|
+
* @param options - Configures the style of the focus outline
|
9
|
+
* @param position - The position of the focus outline
|
10
|
+
* @returns CSS value for the position of the focus outline
|
11
|
+
*/ function getOutlinePosition({ outlineWidth , outlineOffset }, position) {
|
12
|
+
const offsetValue = (outlineOffset === null || outlineOffset === void 0 ? void 0 : outlineOffset[position]) || outlineOffset;
|
13
|
+
if (!outlineOffset) {
|
14
|
+
return `calc(${outlineWidth} * -1)`;
|
15
|
+
}
|
16
|
+
return `calc(0px - ${outlineWidth} - ${offsetValue})`;
|
17
|
+
}
|
5
18
|
/**
|
6
19
|
* NOTE: the element with the focus outline needs to have `position: relative` so that the
|
7
20
|
* pseudo element can be properly positioned.
|
8
21
|
*
|
9
22
|
* @param options - Configures the style of the focus outline
|
10
23
|
* @returns focus outline styles object
|
11
|
-
*/
|
12
|
-
const
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
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
|
-
};
|
24
|
+
*/ const getFocusOutlineStyles = (options)=>{
|
25
|
+
const { outlineRadius , outlineColor , outlineWidth } = options;
|
26
|
+
return {
|
27
|
+
...shorthands.borderColor('transparent'),
|
28
|
+
'::after': {
|
29
|
+
content: '""',
|
30
|
+
position: 'absolute',
|
31
|
+
pointerEvents: 'none',
|
32
|
+
zIndex: 1,
|
33
|
+
...shorthands.borderStyle('solid'),
|
34
|
+
...shorthands.borderWidth(outlineWidth),
|
35
|
+
...shorthands.borderRadius(outlineRadius),
|
36
|
+
...shorthands.borderColor(outlineColor),
|
37
|
+
top: getOutlinePosition(options, 'top'),
|
38
|
+
right: getOutlinePosition(options, 'right'),
|
39
|
+
bottom: getOutlinePosition(options, 'bottom'),
|
40
|
+
left: getOutlinePosition(options, 'left')
|
41
|
+
}
|
42
|
+
};
|
40
43
|
};
|
41
44
|
/**
|
42
45
|
* NOTE: The element with the focus outline needs to have `position: relative` so that the
|
@@ -44,26 +47,20 @@ const getFocusOutlineStyles = options => {
|
|
44
47
|
*
|
45
48
|
* @param options - Configure the style of the focus outline
|
46
49
|
* @returns focus outline styles object for @see makeStyles
|
47
|
-
*/
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
...style
|
65
|
-
}), {
|
66
|
-
selector
|
67
|
-
})
|
68
|
-
});
|
69
|
-
//# sourceMappingURL=createFocusOutlineStyle.js.map
|
50
|
+
*/ export const createFocusOutlineStyle = ({ enableOutline =false , selector =defaultOptions.selector , style =defaultOptions.style } = defaultOptions)=>({
|
51
|
+
':focus': {
|
52
|
+
outlineStyle: enableOutline ? undefined : 'none'
|
53
|
+
},
|
54
|
+
':focus-visible': {
|
55
|
+
outlineStyle: enableOutline ? undefined : 'none'
|
56
|
+
},
|
57
|
+
...createCustomFocusIndicatorStyle(getFocusOutlineStyles({
|
58
|
+
outlineColor: tokens.colorStrokeFocus2,
|
59
|
+
outlineRadius: tokens.borderRadiusMedium,
|
60
|
+
// FIXME: tokens.strokeWidthThick causes some weird bugs
|
61
|
+
outlineWidth: '2px',
|
62
|
+
...style
|
63
|
+
}), {
|
64
|
+
selector
|
65
|
+
})
|
66
|
+
});
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"sources":["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 Omit<CreateCustomFocusIndicatorStyleOptions, 'enableOutline'> {\n style?: Partial<FocusOutlineStyleOptions>;\n\n /**\n * Enables the browser default outline style\n */\n enableOutline?: boolean;\n}\n\n/**\n * Get the position of the focus outline\n *\n * @param options - Configures the style of the focus outline\n * @param position - The position of the focus outline\n * @returns CSS value for the position of the focus outline\n */\nfunction getOutlinePosition(\n { outlineWidth, outlineOffset }: FocusOutlineStyleOptions,\n position: 'top' | 'bottom' | 'left' | 'right',\n) {\n const offsetValue = (outlineOffset as FocusOutlineOffset)?.[position] || outlineOffset;\n\n if (!outlineOffset) {\n return `calc(${outlineWidth} * -1)`;\n }\n\n return `calc(0px - ${outlineWidth} - ${offsetValue})`;\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, outlineWidth } = options;\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: getOutlinePosition(options, 'top'),\n right: getOutlinePosition(options, 'right'),\n bottom: getOutlinePosition(options, 'bottom'),\n left: getOutlinePosition(options, 'left'),\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 enableOutline = false,\n selector = defaultOptions.selector,\n style = defaultOptions.style,\n}: CreateFocusOutlineStyleOptions = defaultOptions): GriffelStyle => ({\n ':focus': {\n outlineStyle: enableOutline ? undefined : 'none',\n },\n ':focus-visible': {\n outlineStyle: enableOutline ? undefined : 'none',\n },\n\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});\n"],"names":["tokens","shorthands","createCustomFocusIndicatorStyle","defaultOptions","getOutlinePosition","outlineWidth","outlineOffset","position","offsetValue","getFocusOutlineStyles","options","outlineRadius","outlineColor","borderColor","content","pointerEvents","zIndex","borderStyle","borderWidth","borderRadius","top","right","bottom","left","createFocusOutlineStyle","enableOutline","selector","style","outlineStyle","undefined","colorStrokeFocus2","borderRadiusMedium"],"mappings":"AAAA,SAASA,MAAM,QAAQ,wBAAwB;AAC/C,SAASC,UAAU,QAAQ,iBAAiB;AAE5C,SACEC,+BAA+B,QAE1B,oCAAoC;AAC3C,SAASC,cAAc,QAAQ,cAAc;AAsB7C;;;;;;CAMC,GACD,SAASC,mBACP,EAAEC,aAAY,EAAEC,cAAa,EAA4B,EACzDC,QAA6C,EAC7C;IAC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AED;QAAS,EACZ;IACH,CAAA,EAAG"}
|
@@ -5,69 +5,67 @@ import { FOCUS_VISIBLE_ATTR } from './constants';
|
|
5
5
|
* @internal
|
6
6
|
* @param scope - Applies the ponyfill to all DOM children
|
7
7
|
* @param targetWindow - window
|
8
|
-
*/
|
9
|
-
|
10
|
-
|
11
|
-
|
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;
|
8
|
+
*/ export function applyFocusVisiblePolyfill(scope, targetWindow) {
|
9
|
+
if (alreadyInScope(scope)) {
|
10
|
+
// Focus visible polyfill already applied at this scope
|
11
|
+
return ()=>undefined;
|
23
12
|
}
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
13
|
+
const state = {
|
14
|
+
current: undefined
|
15
|
+
};
|
16
|
+
const keyborg = createKeyborg(targetWindow);
|
17
|
+
// When navigation mode changes remove the focus-visible selector
|
18
|
+
keyborg.subscribe((isNavigatingWithKeyboard)=>{
|
19
|
+
if (!isNavigatingWithKeyboard && state.current) {
|
20
|
+
removeFocusVisibleClass(state.current);
|
21
|
+
state.current = undefined;
|
22
|
+
}
|
23
|
+
});
|
24
|
+
// Keyborg's focusin event is delegated so it's only registered once on the window
|
25
|
+
// and contains metadata about the focus event
|
26
|
+
const keyborgListener = (e)=>{
|
27
|
+
if (state.current) {
|
28
|
+
removeFocusVisibleClass(state.current);
|
29
|
+
state.current = undefined;
|
30
|
+
}
|
31
|
+
if (keyborg.isNavigatingWithKeyboard() && isHTMLElement(e.target) && e.target) {
|
32
|
+
// Griffel can't create chained global styles so use the parent element for now
|
33
|
+
state.current = e.target;
|
34
|
+
applyFocusVisibleClass(state.current);
|
35
|
+
}
|
36
|
+
};
|
37
|
+
// Make sure that when focus leaves the scope, the focus visible class is removed
|
38
|
+
const blurListener = (e)=>{
|
39
|
+
if (!e.relatedTarget || isHTMLElement(e.relatedTarget) && !scope.contains(e.relatedTarget)) {
|
40
|
+
if (state.current) {
|
41
|
+
removeFocusVisibleClass(state.current);
|
42
|
+
state.current = undefined;
|
43
|
+
}
|
44
|
+
}
|
45
|
+
};
|
46
|
+
scope.addEventListener(KEYBORG_FOCUSIN, keyborgListener);
|
47
|
+
scope.addEventListener('focusout', blurListener);
|
48
|
+
scope.focusVisible = true;
|
49
|
+
// Return disposer
|
50
|
+
return ()=>{
|
51
|
+
scope.removeEventListener(KEYBORG_FOCUSIN, keyborgListener);
|
52
|
+
scope.removeEventListener('focusout', blurListener);
|
53
|
+
delete scope.focusVisible;
|
54
|
+
disposeKeyborg(keyborg);
|
55
|
+
};
|
57
56
|
}
|
58
57
|
function applyFocusVisibleClass(el) {
|
59
|
-
|
58
|
+
el.setAttribute(FOCUS_VISIBLE_ATTR, '');
|
60
59
|
}
|
61
60
|
function removeFocusVisibleClass(el) {
|
62
|
-
|
61
|
+
el.removeAttribute(FOCUS_VISIBLE_ATTR);
|
63
62
|
}
|
64
63
|
function alreadyInScope(el) {
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
64
|
+
if (!el) {
|
65
|
+
return false;
|
66
|
+
}
|
67
|
+
if (el.focusVisible) {
|
68
|
+
return true;
|
69
|
+
}
|
70
|
+
return alreadyInScope(el === null || el === void 0 ? void 0 : el.parentElement);
|
72
71
|
}
|
73
|
-
//# sourceMappingURL=focusVisiblePolyfill.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"sources":["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"],"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"],"mappings":"AAAA,SAASA,aAAa,QAAQ,4BAA4B;AAC1D,SAASC,eAAe,EAAuBC,aAAa,EAAEC,cAAc,QAAQ,UAAU;AAE9F,SAASC,kBAAkB,QAAQ,cAAc;AAoBjD;;;;CAIC,GACD,OAAO,SAASC,0BAA0BC,KAAkB,EAAEC,YAAoB,EAAc;IAC9F,IAAIC,eAAeF,QAAQ;QACzB,uDA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