@fluentui/react-tabster 9.7.3 → 9.7.5
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 +51 -1
- package/CHANGELOG.md +22 -2
- package/dist/index.d.ts +1 -1
- 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 +32 -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 +2 -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 +3 -3
package/CHANGELOG.json
CHANGED
@@ -2,7 +2,57 @@
|
|
2
2
|
"name": "@fluentui/react-tabster",
|
3
3
|
"entries": [
|
4
4
|
{
|
5
|
-
"date": "Wed,
|
5
|
+
"date": "Wed, 31 May 2023 06:43:03 GMT",
|
6
|
+
"tag": "@fluentui/react-tabster_v9.7.5",
|
7
|
+
"version": "9.7.5",
|
8
|
+
"comments": {
|
9
|
+
"patch": [
|
10
|
+
{
|
11
|
+
"author": "seanmonahan@microsoft.com",
|
12
|
+
"package": "@fluentui/react-tabster",
|
13
|
+
"commit": "d640b972d7ac86bfb76ae6c6329f12cdd33b3b7c",
|
14
|
+
"comment": "chore: Update Griffel to v1.5.7."
|
15
|
+
},
|
16
|
+
{
|
17
|
+
"author": "marcosvmmoura@gmail.com",
|
18
|
+
"package": "@fluentui/react-tabster",
|
19
|
+
"commit": "d6b67f35176ab121fa3c3b7dbef32871d2f785e6",
|
20
|
+
"comment": "fix: createFocusOutlineStyle cannot work with CSS variables"
|
21
|
+
},
|
22
|
+
{
|
23
|
+
"author": "beachball",
|
24
|
+
"package": "@fluentui/react-tabster",
|
25
|
+
"comment": "Bump @fluentui/react-utilities to v9.9.2",
|
26
|
+
"commit": "17ca96c6b7f684f36a5c63e40e78b4986a86c713"
|
27
|
+
}
|
28
|
+
],
|
29
|
+
"none": [
|
30
|
+
{
|
31
|
+
"author": "martinhochel@microsoft.com",
|
32
|
+
"package": "@fluentui/react-tabster",
|
33
|
+
"commit": "4b637ced41e430bf8d79c7fc67c103d5efdfd3a8",
|
34
|
+
"comment": "fix: tweak type errors exposed in ts 4.5"
|
35
|
+
}
|
36
|
+
]
|
37
|
+
}
|
38
|
+
},
|
39
|
+
{
|
40
|
+
"date": "Thu, 25 May 2023 10:00:48 GMT",
|
41
|
+
"tag": "@fluentui/react-tabster_v9.7.4",
|
42
|
+
"version": "9.7.4",
|
43
|
+
"comments": {
|
44
|
+
"patch": [
|
45
|
+
{
|
46
|
+
"author": "beachball",
|
47
|
+
"package": "@fluentui/react-tabster",
|
48
|
+
"comment": "Bump @fluentui/react-utilities to v9.9.1",
|
49
|
+
"commit": "8f7c1b7591b3e665ae39e1b22ab0f0b28fb795c4"
|
50
|
+
}
|
51
|
+
]
|
52
|
+
}
|
53
|
+
},
|
54
|
+
{
|
55
|
+
"date": "Wed, 24 May 2023 20:45:35 GMT",
|
6
56
|
"tag": "@fluentui/react-tabster_v9.7.3",
|
7
57
|
"version": "9.7.3",
|
8
58
|
"comments": {
|
package/CHANGELOG.md
CHANGED
@@ -1,12 +1,32 @@
|
|
1
1
|
# Change Log - @fluentui/react-tabster
|
2
2
|
|
3
|
-
This log was last generated on Wed,
|
3
|
+
This log was last generated on Wed, 31 May 2023 06:43:03 GMT and should not be manually modified.
|
4
4
|
|
5
5
|
<!-- Start content -->
|
6
6
|
|
7
|
+
## [9.7.5](https://github.com/microsoft/fluentui/tree/@fluentui/react-tabster_v9.7.5)
|
8
|
+
|
9
|
+
Wed, 31 May 2023 06:43:03 GMT
|
10
|
+
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-tabster_v9.7.4..@fluentui/react-tabster_v9.7.5)
|
11
|
+
|
12
|
+
### Patches
|
13
|
+
|
14
|
+
- chore: Update Griffel to v1.5.7. ([PR #27925](https://github.com/microsoft/fluentui/pull/27925) by seanmonahan@microsoft.com)
|
15
|
+
- fix: createFocusOutlineStyle cannot work with CSS variables ([PR #27966](https://github.com/microsoft/fluentui/pull/27966) by marcosvmmoura@gmail.com)
|
16
|
+
- Bump @fluentui/react-utilities to v9.9.2 ([PR #28054](https://github.com/microsoft/fluentui/pull/28054) by beachball)
|
17
|
+
|
18
|
+
## [9.7.4](https://github.com/microsoft/fluentui/tree/@fluentui/react-tabster_v9.7.4)
|
19
|
+
|
20
|
+
Thu, 25 May 2023 10:00:48 GMT
|
21
|
+
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-tabster_v9.7.3..@fluentui/react-tabster_v9.7.4)
|
22
|
+
|
23
|
+
### Patches
|
24
|
+
|
25
|
+
- Bump @fluentui/react-utilities to v9.9.1 ([PR #27988](https://github.com/microsoft/fluentui/pull/27988) by beachball)
|
26
|
+
|
7
27
|
## [9.7.3](https://github.com/microsoft/fluentui/tree/@fluentui/react-tabster_v9.7.3)
|
8
28
|
|
9
|
-
Wed, 24 May 2023 20:
|
29
|
+
Wed, 24 May 2023 20:45:35 GMT
|
10
30
|
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-tabster_v9.7.2..@fluentui/react-tabster_v9.7.3)
|
11
31
|
|
12
32
|
### Patches
|
package/dist/index.d.ts
CHANGED
@@ -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;IACA,MAAMC,cAAc,CAAA,AAACF,0BAAAA,2BAAD,KAAA,IAAA,AAACA,aAAsC,CAACC,SAAS,AAAD,KAAKD;IAEzE,IAAI,CAACA,eAAe;QAClB,OAAO,CAAC,KAAK,EAAED,aAAa,MAAM,CAAC;IACrC,CAAC;IAED,OAAO,CAAC,WAAW,EAAEA,aAAa,GAAG,EAAEG,YAAY,CAAC,CAAC;AACvD;AAEA;;;;;;CAMC,GACD,MAAMC,wBAAwB,CAACC,UAAoD;IACjF,MAAM,EAAEC,cAAa,EAAEC,aAAY,EAAEP,aAAY,EAAE,GAAGK;IAEtD,OAAO;QACL,GAAGT,WAAWY,WAAW,CAAC,cAAc;QACxC,WAAW;YACTC,SAAS;YACTP,UAAU;YACVQ,eAAe;YACfC,QAAQ;YAER,GAAGf,WAAWgB,WAAW,CAAC,QAAQ;YAClC,GAAGhB,WAAWiB,WAAW,CAACb,aAAa;YACvC,GAAGJ,WAAWkB,YAAY,CAACR,cAAc;YACzC,GAAGV,WAAWY,WAAW,CAACD,aAAa;YAEvCQ,KAAKhB,mBAAmBM,SAAS;YACjCW,OAAOjB,mBAAmBM,SAAS;YACnCY,QAAQlB,mBAAmBM,SAAS;YACpCa,MAAMnB,mBAAmBM,SAAS;QACpC;IACF;AACF;AAEA;;;;;;CAMC,GACD,OAAO,MAAMc,0BAA0B,CAAC,EACtCC,eAAgB,KAAK,CAAA,EACrBC,UAAWvB,eAAeuB,QAAQ,CAAA,EAClCC,OAAQxB,eAAewB,KAAK,CAAA,EACG,GAAGxB,cAAc,GAAoB,CAAA;QACpE,UAAU;YACRyB,cAAcH,gBAAgBI,YAAY,MAAM;QAClD;QACA,kBAAkB;YAChBD,cAAcH,gBAAgBI,YAAY,MAAM;QAClD;QAEA,GAAG3B,gCACDO,sBAAsB;YACpBG,cAAcZ,OAAO8B,iBAAiB;YACtCnB,eAAeX,OAAO+B,kBAAkB;YACxC,wDAAwD;YACxD1B,cAAc;YACd,GAAGsB,KAAK;QACV,IACA;YAAED;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,uDAAuD;QACvD,OAAO,IAAMG;IACf,CAAC;IAED,MAAMC,QAA2B;QAC/BC,SAASF;IACX;IAEA,MAAMG,UAAUV,cAAcK;IAE9B,iEAAiE;IACjEK,QAAQC,SAAS,CAACC,CAAAA,2BAA4B;QAC5C,IAAI,CAACA,4BAA4BJ,MAAMC,OAAO,EAAE;YAC9CI,wBAAwBL,MAAMC,OAAO;YACrCD,MAAMC,OAAO,GAAGF;QAClB,CAAC;IACH;IAEA,kFAAkF;IAClF,8CAA8C;IAC9C,MAAMO,kBAAkB,CAACC,IAA2B;QAClD,IAAIP,MAAMC,OAAO,EAAE;YACjBI,wBAAwBL,MAAMC,OAAO;YACrCD,MAAMC,OAAO,GAAGF;QAClB,CAAC;QAED,IAAIG,QAAQE,wBAAwB,MAAMd,cAAciB,EAAEC,MAAM,KAAKD,EAAEC,MAAM,EAAE;YAC7E,+EAA+E;YAC/ER,MAAMC,OAAO,GAAGM,EAAEC,MAAM;YACxBC,uBAAuBT,MAAMC,OAAO;QACtC,CAAC;IACH;IAEA,iFAAiF;IACjF,MAAMS,eAAe,CAACH,IAAkB;QACtC,IAAI,CAACA,EAAEI,aAAa,IAAKrB,cAAciB,EAAEI,aAAa,KAAK,CAACf,MAAMgB,QAAQ,CAACL,EAAEI,aAAa,GAAI;YAC5F,IAAIX,MAAMC,OAAO,EAAE;gBACjBI,wBAAwBL,MAAMC,OAAO;gBACrCD,MAAMC,OAAO,GAAGF;YAClB,CAAC;QACH,CAAC;IACH;IAEAH,MAAMiB,gBAAgB,CAACtB,iBAAiBe;IACxCV,MAAMiB,gBAAgB,CAAC,YAAYH;IAClCd,MAA2CkB,YAAY,GAAG,IAAI;IAE/D,kBAAkB;IAClB,OAAO,IAAM;QACXlB,MAAMmB,mBAAmB,CAACxB,iBAAiBe;QAC3CV,MAAMmB,mBAAmB,CAAC,YAAYL;QACtC,OAAO,AAACd,MAA2CkB,YAAY;QAC/DrB,eAAeS;IACjB;AACF,CAAC;AAED,SAASO,uBAAuBO,EAAe,EAAE;IAC/CA,GAAGC,YAAY,CAACvB,oBAAoB;AACtC;AAEA,SAASW,wBAAwBW,EAAe,EAAE;IAChDA,GAAGE,eAAe,CAACxB;AACrB;AAEA,SAASI,eAAekB,EAAkC,EAAW;IACnE,IAAI,CAACA,IAAI;QACP,OAAO,KAAK;IACd,CAAC;IAED,IAAI,AAACA,GAAwCF,YAAY,EAAE;QACzD,OAAO,IAAI;IACb,CAAC;IAED,OAAOhB,eAAekB,eAAAA,gBAAAA,KAAAA,IAAAA,GAAIG,aAAa;AACzC"}
|
@@ -4,48 +4,46 @@ import { FOCUS_WITHIN_ATTR } from './constants';
|
|
4
4
|
* A ponyfill that allows `:focus-within` to support visibility based on keyboard/mouse navigation
|
5
5
|
* like `:focus-visible` https://github.com/WICG/focus-visible/issues/151
|
6
6
|
* @returns ref to the element that uses `:focus-within` styles
|
7
|
-
*/
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
}
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
}
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
}
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
};
|
7
|
+
*/ export function applyFocusWithinPolyfill(element, win) {
|
8
|
+
const keyborg = createKeyborg(win);
|
9
|
+
// When navigation mode changes to mouse, remove the focus-within selector
|
10
|
+
keyborg.subscribe((isNavigatingWithKeyboard)=>{
|
11
|
+
if (!isNavigatingWithKeyboard) {
|
12
|
+
removeFocusWithinClass(element);
|
13
|
+
}
|
14
|
+
});
|
15
|
+
// Keyborg's focusin event is delegated so it's only registered once on the window
|
16
|
+
// and contains metadata about the focus event
|
17
|
+
const keyborgListener = (e)=>{
|
18
|
+
if (keyborg.isNavigatingWithKeyboard() && isHTMLElement(e.target)) {
|
19
|
+
// Griffel can't create chained global styles so use the parent element for now
|
20
|
+
applyFocusWithinClass(element);
|
21
|
+
}
|
22
|
+
};
|
23
|
+
// Make sure that when focus leaves the scope, the focus within class is removed
|
24
|
+
const blurListener = (e)=>{
|
25
|
+
if (!e.relatedTarget || isHTMLElement(e.relatedTarget) && !element.contains(e.relatedTarget)) {
|
26
|
+
removeFocusWithinClass(element);
|
27
|
+
}
|
28
|
+
};
|
29
|
+
element.addEventListener(KEYBORG_FOCUSIN, keyborgListener);
|
30
|
+
element.addEventListener('focusout', blurListener);
|
31
|
+
// Return disposer
|
32
|
+
return ()=>{
|
33
|
+
element.removeEventListener(KEYBORG_FOCUSIN, keyborgListener);
|
34
|
+
element.removeEventListener('focusout', blurListener);
|
35
|
+
disposeKeyborg(keyborg);
|
36
|
+
};
|
38
37
|
}
|
39
38
|
function applyFocusWithinClass(el) {
|
40
|
-
|
39
|
+
el.setAttribute(FOCUS_WITHIN_ATTR, '');
|
41
40
|
}
|
42
41
|
function removeFocusWithinClass(el) {
|
43
|
-
|
42
|
+
el.removeAttribute(FOCUS_WITHIN_ATTR);
|
44
43
|
}
|
45
44
|
function isHTMLElement(target) {
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
45
|
+
if (!target) {
|
46
|
+
return false;
|
47
|
+
}
|
48
|
+
return Boolean(target && typeof target === 'object' && 'classList' in target && 'contains' in target);
|
50
49
|
}
|
51
|
-
//# sourceMappingURL=focusWithinPolyfill.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"sources":["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"],"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"],"mappings":"AAAA,SAASA,eAAe,EAAuBC,aAAa,EAAEC,cAAc,QAAQ,UAAU;AAC9F,SAASC,iBAAiB,QAAQ,cAAc;AAShD;;;;CAIC,GACD,OAAO,SAASC,yBAAyBC,OAAoB,EAAEC,GAAW,EAAc;IACtF,MAAMC,UAAUN,cAAcK;IAE9B,0EAA0E;IAC1EC,QAAQC,SAAS,CAACC,CAAAA,2BAA4B;QAC5C,IAAI,CAACA,0BAA0B;YAC7BC,uBAAuBL;QACzB,CAAC;IACH;IAEA,kFAAkF;IAClF,8CAA8C;IAC9C,MAAMM,kBAAkB,CAACC,IAA2B;QAClD,IAAIL,QAAQE,wBAAwB,MAAMI,cAAcD,EAAEE,MAAM,GAAG;YACjE,+EAA+E;YAC/EC,sBAAsBV;QACxB,CAAC;IACH;IAEA,gFAAgF;IAChF,MAAMW,eAAe,CAACJ,IAAkB;QACtC,IAAI,CAACA,EAAEK,aAAa,IAAKJ,cAAcD,EAAEK,aAAa,KAAK,CAACZ,QAAQa,QAAQ,CAACN,EAAEK,aAAa,GAAI;YAC9FP,uBAAuBL;QACzB,CAAC;IACH;IAEAA,QAAQc,gBAAgB,CAACnB,iBAAiBW;IAC1CN,QAAQc,gBAAgB,CAAC,YAAYH;IAErC,kBAAkB;IAClB,OAAO,IAAM;QACXX,QAAQe,mBAAmB,CAACpB,iBAAiBW;QAC7CN,QAAQe,mBAAmB,CAAC,YAAYJ;QACxCd,eAAeK;IACjB;AACF,CAAC;AAED,SAASQ,sBAAsBM,EAAe,EAAE;IAC9CA,GAAGC,YAAY,CAACnB,mBAAmB;AACrC;AAEA,SAASO,uBAAuBW,EAAe,EAAE;IAC/CA,GAAGE,eAAe,CAACpB;AACrB;AAEA,SAASU,cAAcC,MAA0B,EAAyB;IACxE,IAAI,CAACA,QAAQ;QACX,OAAO,KAAK;IACd,CAAC;IACD,OAAOU,QAAQV,UAAU,OAAOA,WAAW,YAAY,eAAeA,UAAU,cAAcA;AAChG"}
|
package/lib/focus/index.js
CHANGED