@fluentui/react-aria 9.0.2 → 9.1.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 +33 -2
- package/CHANGELOG.md +16 -3
- package/dist/index.d.ts +22 -7
- package/lib/hooks/useARIAButton.js +63 -38
- package/lib/hooks/useARIAButton.js.map +1 -1
- package/lib/index.js +1 -2
- package/lib/index.js.map +1 -1
- package/lib-commonjs/hooks/useARIAButton.js +69 -42
- package/lib-commonjs/hooks/useARIAButton.js.map +1 -1
- package/lib-commonjs/index.js +5 -8
- package/lib-commonjs/index.js.map +1 -1
- package/package.json +3 -2
- package/lib/utils/index.js +0 -2
- package/lib/utils/index.js.map +0 -1
- package/lib/utils/mergeARIADisabled.js +0 -16
- package/lib/utils/mergeARIADisabled.js.map +0 -1
- package/lib-commonjs/utils/index.js +0 -10
- package/lib-commonjs/utils/index.js.map +0 -1
- package/lib-commonjs/utils/mergeARIADisabled.js +0 -25
- package/lib-commonjs/utils/mergeARIADisabled.js.map +0 -1
package/CHANGELOG.json
CHANGED
|
@@ -2,7 +2,38 @@
|
|
|
2
2
|
"name": "@fluentui/react-aria",
|
|
3
3
|
"entries": [
|
|
4
4
|
{
|
|
5
|
-
"date": "
|
|
5
|
+
"date": "Wed, 03 Aug 2022 16:00:04 GMT",
|
|
6
|
+
"tag": "@fluentui/react-aria_v9.1.0",
|
|
7
|
+
"version": "9.1.0",
|
|
8
|
+
"comments": {
|
|
9
|
+
"none": [
|
|
10
|
+
{
|
|
11
|
+
"author": "lingfangao@hotmail.com",
|
|
12
|
+
"package": "@fluentui/react-aria",
|
|
13
|
+
"commit": "99cc385631d04a76ee10ebc143cb9fecd99640b6",
|
|
14
|
+
"comment": "chore: Add `prerelease` as disallowed changetype for 9.0.0 packages"
|
|
15
|
+
}
|
|
16
|
+
],
|
|
17
|
+
"patch": [
|
|
18
|
+
{
|
|
19
|
+
"author": "bernardo.sunderhus@gmail.com",
|
|
20
|
+
"package": "@fluentui/react-aria",
|
|
21
|
+
"commit": "a0e1e0c2780ad6ba73aaeee1aa1525168a4d4045",
|
|
22
|
+
"comment": "feat: treats aria-disabled as disabled state on useARIAButtonProps"
|
|
23
|
+
}
|
|
24
|
+
],
|
|
25
|
+
"minor": [
|
|
26
|
+
{
|
|
27
|
+
"author": "bernardo.sunderhus@gmail.com",
|
|
28
|
+
"package": "@fluentui/react-aria",
|
|
29
|
+
"commit": "1293f53f79ea1dc7429f77e174b2dfdaffa99558",
|
|
30
|
+
"comment": "chore: Splits useARIAButton into useARIAButtonProps and useARIAButtonShorthand."
|
|
31
|
+
}
|
|
32
|
+
]
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
"date": "Thu, 14 Jul 2022 21:21:08 GMT",
|
|
6
37
|
"tag": "@fluentui/react-aria_v9.0.2",
|
|
7
38
|
"version": "9.0.2",
|
|
8
39
|
"comments": {
|
|
@@ -17,7 +48,7 @@
|
|
|
17
48
|
"author": "beachball",
|
|
18
49
|
"package": "@fluentui/react-aria",
|
|
19
50
|
"comment": "Bump @fluentui/react-utilities to v9.0.2",
|
|
20
|
-
"commit": "
|
|
51
|
+
"commit": "79b513146194367544160f364b0a7dd749ed93e4"
|
|
21
52
|
}
|
|
22
53
|
]
|
|
23
54
|
}
|
package/CHANGELOG.md
CHANGED
|
@@ -1,18 +1,31 @@
|
|
|
1
1
|
# Change Log - @fluentui/react-aria
|
|
2
2
|
|
|
3
|
-
This log was last generated on
|
|
3
|
+
This log was last generated on Wed, 03 Aug 2022 16:00:04 GMT and should not be manually modified.
|
|
4
4
|
|
|
5
5
|
<!-- Start content -->
|
|
6
6
|
|
|
7
|
+
## [9.1.0](https://github.com/microsoft/fluentui/tree/@fluentui/react-aria_v9.1.0)
|
|
8
|
+
|
|
9
|
+
Wed, 03 Aug 2022 16:00:04 GMT
|
|
10
|
+
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-aria_v9.0.2..@fluentui/react-aria_v9.1.0)
|
|
11
|
+
|
|
12
|
+
### Minor changes
|
|
13
|
+
|
|
14
|
+
- chore: Splits useARIAButton into useARIAButtonProps and useARIAButtonShorthand. ([PR #24032](https://github.com/microsoft/fluentui/pull/24032) by bernardo.sunderhus@gmail.com)
|
|
15
|
+
|
|
16
|
+
### Patches
|
|
17
|
+
|
|
18
|
+
- feat: treats aria-disabled as disabled state on useARIAButtonProps ([PR #24197](https://github.com/microsoft/fluentui/pull/24197) by bernardo.sunderhus@gmail.com)
|
|
19
|
+
|
|
7
20
|
## [9.0.2](https://github.com/microsoft/fluentui/tree/@fluentui/react-aria_v9.0.2)
|
|
8
21
|
|
|
9
|
-
Thu, 14 Jul 2022 21:
|
|
22
|
+
Thu, 14 Jul 2022 21:21:08 GMT
|
|
10
23
|
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-aria_v9.0.1..@fluentui/react-aria_v9.0.2)
|
|
11
24
|
|
|
12
25
|
### Patches
|
|
13
26
|
|
|
14
27
|
- fix: Fixing bad version bump of @fluentui/react-utilities. ([PR #23920](https://github.com/microsoft/fluentui/pull/23920) by Humberto.Morimoto@microsoft.com)
|
|
15
|
-
- Bump @fluentui/react-utilities to v9.0.2 ([PR #
|
|
28
|
+
- Bump @fluentui/react-utilities to v9.0.2 ([PR #23918](https://github.com/microsoft/fluentui/pull/23918) by beachball)
|
|
16
29
|
|
|
17
30
|
## [9.0.1](https://github.com/microsoft/fluentui/tree/@fluentui/react-aria_v9.0.1)
|
|
18
31
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,26 +1,41 @@
|
|
|
1
1
|
import type { ExtractSlotProps } from '@fluentui/react-utilities';
|
|
2
|
+
import * as React_2 from 'react';
|
|
2
3
|
import type { ResolveShorthandFunction } from '@fluentui/react-utilities';
|
|
3
4
|
import type { Slot } from '@fluentui/react-utilities';
|
|
4
5
|
|
|
5
|
-
export declare type
|
|
6
|
+
export declare type ARIAButtonProps<Type extends 'a' | 'div' | 'button' = 'a' | 'div' | 'button'> = React_2.PropsWithRef<JSX.IntrinsicElements[Type]> & Pick<ARIAButtonSlotProps, 'disabled' | 'disabledFocusable'>;
|
|
7
|
+
|
|
8
|
+
export declare type ARIAButtonSlotProps<AlternateAs extends 'a' | 'div' = 'a' | 'div'> = ExtractSlotProps<Slot<'button', AlternateAs>> & {
|
|
6
9
|
disabled?: boolean;
|
|
10
|
+
/**
|
|
11
|
+
* When set, allows the button to be focusable even when it has been disabled.
|
|
12
|
+
* This is used in scenarios where it is important to keep a consistent tab order
|
|
13
|
+
* for screen reader and keyboard users. The primary example of this
|
|
14
|
+
* pattern is when the disabled button is in a menu or a commandbar and is seldom used for standalone buttons.
|
|
15
|
+
*
|
|
16
|
+
* @default false
|
|
17
|
+
*/
|
|
7
18
|
disabledFocusable?: boolean;
|
|
8
19
|
};
|
|
9
20
|
|
|
10
21
|
/**
|
|
11
22
|
* @internal
|
|
12
|
-
*
|
|
23
|
+
*
|
|
24
|
+
* Button keyboard handling, role, disabled and tabIndex implementation that ensures ARIA spec
|
|
25
|
+
* for multiple scenarios of shorthand properties. Ensuring 1st rule of ARIA for cases
|
|
26
|
+
* where no attribute addition is required.
|
|
13
27
|
*/
|
|
14
|
-
export declare function
|
|
15
|
-
'aria-disabled'?: string | boolean;
|
|
16
|
-
disabled?: boolean;
|
|
17
|
-
}): boolean;
|
|
28
|
+
export declare function useARIAButtonProps<Type extends NonNullable<ARIAButtonSlotProps['as']>>(type?: Type, props?: ARIAButtonProps): React_2.PropsWithRef<JSX.IntrinsicElements[Type]>;
|
|
18
29
|
|
|
19
30
|
/**
|
|
31
|
+
* @internal
|
|
32
|
+
*
|
|
33
|
+
* This function expects to receive a slot, if `as` property is not desired use `useARIAButtonProps` instead
|
|
34
|
+
*
|
|
20
35
|
* Button keyboard handling, role, disabled and tabIndex implementation that ensures ARIA spec
|
|
21
36
|
* for multiple scenarios of shorthand properties. Ensuring 1st rule of ARIA for cases
|
|
22
37
|
* where no attribute addition is required.
|
|
23
38
|
*/
|
|
24
|
-
export declare const
|
|
39
|
+
export declare const useARIAButtonShorthand: ResolveShorthandFunction<ARIAButtonSlotProps>;
|
|
25
40
|
|
|
26
41
|
export { }
|
|
@@ -1,32 +1,35 @@
|
|
|
1
1
|
import { Enter, Space } from '@fluentui/keyboard-keys';
|
|
2
2
|
import { resolveShorthand, useEventCallback } from '@fluentui/react-utilities';
|
|
3
3
|
/**
|
|
4
|
+
* @internal
|
|
5
|
+
*
|
|
4
6
|
* Button keyboard handling, role, disabled and tabIndex implementation that ensures ARIA spec
|
|
5
7
|
* for multiple scenarios of shorthand properties. Ensuring 1st rule of ARIA for cases
|
|
6
8
|
* where no attribute addition is required.
|
|
7
9
|
*/
|
|
8
10
|
|
|
9
|
-
export
|
|
10
|
-
var _a;
|
|
11
|
-
|
|
12
|
-
const shorthandProps = resolveShorthand(shorthand, options);
|
|
11
|
+
export function useARIAButtonProps(type, props) {
|
|
13
12
|
const {
|
|
14
13
|
disabled,
|
|
15
|
-
|
|
14
|
+
tabIndex,
|
|
15
|
+
disabledFocusable = false,
|
|
16
16
|
onClick,
|
|
17
17
|
onKeyDown,
|
|
18
18
|
onKeyUp,
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
['aria-disabled']: ariaDisabled,
|
|
20
|
+
...rest
|
|
21
|
+
} = props !== null && props !== void 0 ? props : {};
|
|
22
|
+
const normalizedARIADisabled = typeof ariaDisabled === 'string' ? ariaDisabled === 'true' : ariaDisabled;
|
|
23
|
+
const isDisabled = disabled || disabledFocusable || normalizedARIADisabled;
|
|
24
|
+
const handleClick = useEventCallback(ev => {
|
|
25
|
+
if (isDisabled) {
|
|
23
26
|
ev.preventDefault();
|
|
24
27
|
ev.stopPropagation();
|
|
25
28
|
} else {
|
|
26
29
|
onClick === null || onClick === void 0 ? void 0 : onClick(ev);
|
|
27
30
|
}
|
|
28
31
|
});
|
|
29
|
-
const
|
|
32
|
+
const handleKeyDown = useEventCallback(ev => {
|
|
30
33
|
onKeyDown === null || onKeyDown === void 0 ? void 0 : onKeyDown(ev);
|
|
31
34
|
|
|
32
35
|
if (ev.isDefaultPrevented()) {
|
|
@@ -35,7 +38,7 @@ export const useARIAButton = (shorthand, options) => {
|
|
|
35
38
|
|
|
36
39
|
const key = ev.key;
|
|
37
40
|
|
|
38
|
-
if (
|
|
41
|
+
if (isDisabled && (key === Enter || key === Space)) {
|
|
39
42
|
ev.preventDefault();
|
|
40
43
|
ev.stopPropagation();
|
|
41
44
|
return;
|
|
@@ -50,7 +53,7 @@ export const useARIAButton = (shorthand, options) => {
|
|
|
50
53
|
ev.currentTarget.click();
|
|
51
54
|
}
|
|
52
55
|
});
|
|
53
|
-
const
|
|
56
|
+
const handleKeyUp = useEventCallback(ev => {
|
|
54
57
|
onKeyUp === null || onKeyUp === void 0 ? void 0 : onKeyUp(ev);
|
|
55
58
|
|
|
56
59
|
if (ev.isDefaultPrevented()) {
|
|
@@ -59,7 +62,7 @@ export const useARIAButton = (shorthand, options) => {
|
|
|
59
62
|
|
|
60
63
|
const key = ev.key;
|
|
61
64
|
|
|
62
|
-
if (
|
|
65
|
+
if (isDisabled && (key === Enter || key === Space)) {
|
|
63
66
|
ev.preventDefault();
|
|
64
67
|
ev.stopPropagation();
|
|
65
68
|
return;
|
|
@@ -69,35 +72,57 @@ export const useARIAButton = (shorthand, options) => {
|
|
|
69
72
|
ev.preventDefault();
|
|
70
73
|
ev.currentTarget.click();
|
|
71
74
|
}
|
|
72
|
-
});
|
|
75
|
+
}); // If a <button> tag is to be rendered we just need to set disabled and aria-disabled correctly
|
|
73
76
|
|
|
74
|
-
if (
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
if
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
77
|
+
if (type === 'button' || type === undefined) {
|
|
78
|
+
return { ...rest,
|
|
79
|
+
tabIndex,
|
|
80
|
+
disabled: disabled && !disabledFocusable,
|
|
81
|
+
'aria-disabled': disabledFocusable ? true : normalizedARIADisabled,
|
|
82
|
+
// onclick should still use internal handler to ensure prevention if disabled
|
|
83
|
+
// if disabledFocusable then there's no requirement for handlers as those events should not be propagated
|
|
84
|
+
onClick: disabledFocusable ? undefined : handleClick,
|
|
85
|
+
onKeyUp: disabledFocusable ? undefined : onKeyUp,
|
|
86
|
+
onKeyDown: disabledFocusable ? undefined : onKeyDown
|
|
87
|
+
};
|
|
88
|
+
} // If an <a> or <div> tag is to be rendered we have to remove disabled and type,
|
|
89
|
+
// and set aria-disabled, role and tabIndex.
|
|
90
|
+
else {
|
|
91
|
+
const nextProps = {
|
|
92
|
+
role: 'button',
|
|
93
|
+
...rest,
|
|
94
|
+
// If it's not a <button> than listeners are required even with disabledFocusable
|
|
95
|
+
// Since you cannot assure the default behavior of the element
|
|
96
|
+
// E.g: <a> will redirect on click
|
|
97
|
+
onClick: handleClick,
|
|
98
|
+
onKeyUp: handleKeyUp,
|
|
99
|
+
onKeyDown: handleKeyDown,
|
|
100
|
+
'aria-disabled': disabled || disabledFocusable || normalizedARIADisabled,
|
|
101
|
+
tabIndex: disabled && !disabledFocusable ? undefined : tabIndex !== null && tabIndex !== void 0 ? tabIndex : 0
|
|
102
|
+
};
|
|
96
103
|
|
|
104
|
+
if (type === 'a' && isDisabled) {
|
|
105
|
+
nextProps.href = undefined;
|
|
106
|
+
}
|
|
97
107
|
|
|
98
|
-
|
|
108
|
+
return nextProps;
|
|
99
109
|
}
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* @internal
|
|
113
|
+
*
|
|
114
|
+
* This function expects to receive a slot, if `as` property is not desired use `useARIAButtonProps` instead
|
|
115
|
+
*
|
|
116
|
+
* Button keyboard handling, role, disabled and tabIndex implementation that ensures ARIA spec
|
|
117
|
+
* for multiple scenarios of shorthand properties. Ensuring 1st rule of ARIA for cases
|
|
118
|
+
* where no attribute addition is required.
|
|
119
|
+
*/
|
|
120
|
+
|
|
121
|
+
export const useARIAButtonShorthand = (slot, options) => {
|
|
122
|
+
var _a;
|
|
100
123
|
|
|
101
|
-
|
|
124
|
+
const shorthand = resolveShorthand(slot, options);
|
|
125
|
+
const shorthandARIAButton = useARIAButtonProps((_a = shorthand === null || shorthand === void 0 ? void 0 : shorthand.as) !== null && _a !== void 0 ? _a : 'button', shorthand);
|
|
126
|
+
return shorthand && shorthandARIAButton;
|
|
102
127
|
};
|
|
103
128
|
//# sourceMappingURL=useARIAButton.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["hooks/useARIAButton.ts"],"names":[],"mappings":"AAAA,SAAS,KAAT,EAAgB,KAAhB,QAA6B,yBAA7B;AACA,SAAS,gBAAT,EAA2B,gBAA3B,QAAmD,2BAAnD;
|
|
1
|
+
{"version":3,"sources":["hooks/useARIAButton.ts"],"names":[],"mappings":"AAAA,SAAS,KAAT,EAAgB,KAAhB,QAA6B,yBAA7B;AACA,SAAS,gBAAT,EAA2B,gBAA3B,QAAmD,2BAAnD;AAwBA;;;;;;AAMG;;AACH,OAAM,SAAU,kBAAV,CACJ,IADI,EAEJ,KAFI,EAEmB;EAEvB,MAAM;IACJ,QADI;IAEJ,QAFI;IAGJ,iBAAiB,GAAG,KAHhB;IAIJ,OAJI;IAKJ,SALI;IAMJ,OANI;IAOJ,CAAC,eAAD,GAAmB,YAPf;IAQJ,GAAG;EARC,IASF,KAAK,KAAA,IAAL,IAAA,KAAK,KAAA,KAAA,CAAL,GAAA,KAAA,GAAS,EATb;EAWA,MAAM,sBAAsB,GAAG,OAAO,YAAP,KAAwB,QAAxB,GAAmC,YAAY,KAAK,MAApD,GAA6D,YAA5F;EAEA,MAAM,UAAU,GAAG,QAAQ,IAAI,iBAAZ,IAAiC,sBA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mB,GAAG,kBAAkB,CAAC,CAAA,EAAA,GAAA,SAAS,KAAA,IAAT,IAAA,SAAS,KAAA,KAAA,CAAT,GAAS,KAAA,CAAT,GAAA,SAAS,CAAE,EAAX,MAAa,IAAb,IAAa,EAAA,KAAA,KAAA,CAAb,GAAa,EAAb,GAAiB,QAAlB,EAA4B,SAA5B,CAA9C;EACA,OAAO,SAAS,IAAI,mBAApB;AACD,CAJM","sourcesContent":["import { Enter, Space } from '@fluentui/keyboard-keys';\nimport { resolveShorthand, useEventCallback } from '@fluentui/react-utilities';\nimport type { ExtractSlotProps, ResolveShorthandFunction, Slot } from '@fluentui/react-utilities';\nimport * as React from 'react';\n\nexport type ARIAButtonSlotProps<AlternateAs extends 'a' | 'div' = 'a' | 'div'> = ExtractSlotProps<\n Slot<'button', AlternateAs>\n> & {\n disabled?: boolean;\n /**\n * When set, allows the button to be focusable even when it has been disabled.\n * This is used in scenarios where it is important to keep a consistent tab order\n * for screen reader and keyboard users. The primary example of this\n * pattern is when the disabled button is in a menu or a commandbar and is seldom used for standalone buttons.\n *\n * @default false\n */\n disabledFocusable?: boolean;\n};\n\nexport type ARIAButtonProps<Type extends 'a' | 'div' | 'button' = 'a' | 'div' | 'button'> = React.PropsWithRef<\n JSX.IntrinsicElements[Type]\n> &\n Pick<ARIAButtonSlotProps, 'disabled' | 'disabledFocusable'>;\n\n/**\n * @internal\n *\n * Button keyboard handling, role, disabled and tabIndex implementation that ensures ARIA spec\n * for multiple scenarios of shorthand properties. Ensuring 1st rule of ARIA for cases\n * where no attribute addition is required.\n */\nexport function useARIAButtonProps<Type extends NonNullable<ARIAButtonSlotProps['as']>>(\n type?: Type,\n props?: ARIAButtonProps,\n): React.PropsWithRef<JSX.IntrinsicElements[Type]> {\n const {\n disabled,\n tabIndex,\n disabledFocusable = false,\n onClick,\n onKeyDown,\n onKeyUp,\n ['aria-disabled']: ariaDisabled,\n ...rest\n } = props ?? {};\n\n const normalizedARIADisabled = typeof ariaDisabled === 'string' ? ariaDisabled === 'true' : ariaDisabled;\n\n const isDisabled = disabled || disabledFocusable || normalizedARIADisabled;\n\n const handleClick: ARIAButtonProps['onClick'] = useEventCallback(ev => {\n if (isDisabled) {\n ev.preventDefault();\n ev.stopPropagation();\n } else {\n onClick?.(ev);\n }\n });\n\n const handleKeyDown: ARIAButtonProps['onKeyDown'] = useEventCallback(ev => {\n onKeyDown?.(ev);\n\n if (ev.isDefaultPrevented()) {\n return;\n }\n\n const key = ev.key;\n\n if (isDisabled && (key === Enter || key === Space)) {\n ev.preventDefault();\n ev.stopPropagation();\n return;\n }\n\n if (key === Space) {\n ev.preventDefault();\n return;\n }\n\n // If enter is pressed, activate the button\n else if (key === Enter) {\n ev.preventDefault();\n ev.currentTarget.click();\n }\n });\n\n const handleKeyUp: ARIAButtonProps['onKeyUp'] = useEventCallback(ev => {\n onKeyUp?.(ev);\n\n if (ev.isDefaultPrevented()) {\n return;\n }\n\n const key = ev.key;\n\n if (isDisabled && (key === Enter || key === Space)) {\n ev.preventDefault();\n ev.stopPropagation();\n return;\n }\n\n if (key === Space) {\n ev.preventDefault();\n ev.currentTarget.click();\n }\n });\n\n // If a <button> tag is to be rendered we just need to set disabled and aria-disabled correctly\n if (type === 'button' || type === undefined) {\n return {\n ...rest,\n tabIndex,\n disabled: disabled && !disabledFocusable,\n 'aria-disabled': disabledFocusable ? true : normalizedARIADisabled,\n // onclick should still use internal handler to ensure prevention if disabled\n // if disabledFocusable then there's no requirement for handlers as those events should not be propagated\n onClick: disabledFocusable ? undefined : handleClick,\n onKeyUp: disabledFocusable ? undefined : onKeyUp,\n onKeyDown: disabledFocusable ? undefined : onKeyDown,\n } as React.PropsWithRef<JSX.IntrinsicElements[Type]>;\n }\n\n // If an <a> or <div> tag is to be rendered we have to remove disabled and type,\n // and set aria-disabled, role and tabIndex.\n else {\n const nextProps = {\n role: 'button',\n ...rest,\n // If it's not a <button> than listeners are required even with disabledFocusable\n // Since you cannot assure the default behavior of the element\n // E.g: <a> will redirect on click\n onClick: handleClick,\n onKeyUp: handleKeyUp,\n onKeyDown: handleKeyDown,\n 'aria-disabled': disabled || disabledFocusable || normalizedARIADisabled,\n tabIndex: disabled && !disabledFocusable ? undefined : tabIndex ?? 0,\n } as React.PropsWithRef<JSX.IntrinsicElements[Type]>;\n\n if (type === 'a' && isDisabled) {\n (nextProps as JSX.IntrinsicElements['a']).href = undefined;\n }\n\n return nextProps;\n }\n}\n\n/**\n * @internal\n *\n * This function expects to receive a slot, if `as` property is not desired use `useARIAButtonProps` instead\n *\n * Button keyboard handling, role, disabled and tabIndex implementation that ensures ARIA spec\n * for multiple scenarios of shorthand properties. Ensuring 1st rule of ARIA for cases\n * where no attribute addition is required.\n */\nexport const useARIAButtonShorthand: ResolveShorthandFunction<ARIAButtonSlotProps> = (slot, options) => {\n const shorthand = resolveShorthand(slot, options);\n const shorthandARIAButton = useARIAButtonProps(shorthand?.as ?? 'button', shorthand);\n return shorthand && shorthandARIAButton;\n};\n"],"sourceRoot":"../src/"}
|
package/lib/index.js
CHANGED
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"../src/","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"../src/","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC","sourcesContent":["export { useARIAButtonShorthand, useARIAButtonProps } from './hooks/index';\nexport type { ARIAButtonSlotProps, ARIAButtonProps } from './hooks/index';\n"]}
|
|
@@ -3,39 +3,42 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.useARIAButtonShorthand = exports.useARIAButtonProps = void 0;
|
|
7
7
|
|
|
8
8
|
const keyboard_keys_1 = /*#__PURE__*/require("@fluentui/keyboard-keys");
|
|
9
9
|
|
|
10
10
|
const react_utilities_1 = /*#__PURE__*/require("@fluentui/react-utilities");
|
|
11
11
|
/**
|
|
12
|
+
* @internal
|
|
13
|
+
*
|
|
12
14
|
* Button keyboard handling, role, disabled and tabIndex implementation that ensures ARIA spec
|
|
13
15
|
* for multiple scenarios of shorthand properties. Ensuring 1st rule of ARIA for cases
|
|
14
16
|
* where no attribute addition is required.
|
|
15
17
|
*/
|
|
16
18
|
|
|
17
19
|
|
|
18
|
-
|
|
19
|
-
var _a;
|
|
20
|
-
|
|
21
|
-
const shorthandProps = react_utilities_1.resolveShorthand(shorthand, options);
|
|
20
|
+
function useARIAButtonProps(type, props) {
|
|
22
21
|
const {
|
|
23
22
|
disabled,
|
|
24
|
-
|
|
23
|
+
tabIndex,
|
|
24
|
+
disabledFocusable = false,
|
|
25
25
|
onClick,
|
|
26
26
|
onKeyDown,
|
|
27
27
|
onKeyUp,
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
28
|
+
['aria-disabled']: ariaDisabled,
|
|
29
|
+
...rest
|
|
30
|
+
} = props !== null && props !== void 0 ? props : {};
|
|
31
|
+
const normalizedARIADisabled = typeof ariaDisabled === 'string' ? ariaDisabled === 'true' : ariaDisabled;
|
|
32
|
+
const isDisabled = disabled || disabledFocusable || normalizedARIADisabled;
|
|
33
|
+
const handleClick = react_utilities_1.useEventCallback(ev => {
|
|
34
|
+
if (isDisabled) {
|
|
32
35
|
ev.preventDefault();
|
|
33
36
|
ev.stopPropagation();
|
|
34
37
|
} else {
|
|
35
38
|
onClick === null || onClick === void 0 ? void 0 : onClick(ev);
|
|
36
39
|
}
|
|
37
40
|
});
|
|
38
|
-
const
|
|
41
|
+
const handleKeyDown = react_utilities_1.useEventCallback(ev => {
|
|
39
42
|
onKeyDown === null || onKeyDown === void 0 ? void 0 : onKeyDown(ev);
|
|
40
43
|
|
|
41
44
|
if (ev.isDefaultPrevented()) {
|
|
@@ -44,7 +47,7 @@ const useARIAButton = (shorthand, options) => {
|
|
|
44
47
|
|
|
45
48
|
const key = ev.key;
|
|
46
49
|
|
|
47
|
-
if (
|
|
50
|
+
if (isDisabled && (key === keyboard_keys_1.Enter || key === keyboard_keys_1.Space)) {
|
|
48
51
|
ev.preventDefault();
|
|
49
52
|
ev.stopPropagation();
|
|
50
53
|
return;
|
|
@@ -59,7 +62,7 @@ const useARIAButton = (shorthand, options) => {
|
|
|
59
62
|
ev.currentTarget.click();
|
|
60
63
|
}
|
|
61
64
|
});
|
|
62
|
-
const
|
|
65
|
+
const handleKeyUp = react_utilities_1.useEventCallback(ev => {
|
|
63
66
|
onKeyUp === null || onKeyUp === void 0 ? void 0 : onKeyUp(ev);
|
|
64
67
|
|
|
65
68
|
if (ev.isDefaultPrevented()) {
|
|
@@ -68,7 +71,7 @@ const useARIAButton = (shorthand, options) => {
|
|
|
68
71
|
|
|
69
72
|
const key = ev.key;
|
|
70
73
|
|
|
71
|
-
if (
|
|
74
|
+
if (isDisabled && (key === keyboard_keys_1.Enter || key === keyboard_keys_1.Space)) {
|
|
72
75
|
ev.preventDefault();
|
|
73
76
|
ev.stopPropagation();
|
|
74
77
|
return;
|
|
@@ -78,37 +81,61 @@ const useARIAButton = (shorthand, options) => {
|
|
|
78
81
|
ev.preventDefault();
|
|
79
82
|
ev.currentTarget.click();
|
|
80
83
|
}
|
|
81
|
-
});
|
|
84
|
+
}); // If a <button> tag is to be rendered we just need to set disabled and aria-disabled correctly
|
|
85
|
+
|
|
86
|
+
if (type === 'button' || type === undefined) {
|
|
87
|
+
return { ...rest,
|
|
88
|
+
tabIndex,
|
|
89
|
+
disabled: disabled && !disabledFocusable,
|
|
90
|
+
'aria-disabled': disabledFocusable ? true : normalizedARIADisabled,
|
|
91
|
+
// onclick should still use internal handler to ensure prevention if disabled
|
|
92
|
+
// if disabledFocusable then there's no requirement for handlers as those events should not be propagated
|
|
93
|
+
onClick: disabledFocusable ? undefined : handleClick,
|
|
94
|
+
onKeyUp: disabledFocusable ? undefined : onKeyUp,
|
|
95
|
+
onKeyDown: disabledFocusable ? undefined : onKeyDown
|
|
96
|
+
};
|
|
97
|
+
} // If an <a> or <div> tag is to be rendered we have to remove disabled and type,
|
|
98
|
+
// and set aria-disabled, role and tabIndex.
|
|
99
|
+
else {
|
|
100
|
+
const nextProps = {
|
|
101
|
+
role: 'button',
|
|
102
|
+
...rest,
|
|
103
|
+
// If it's not a <button> than listeners are required even with disabledFocusable
|
|
104
|
+
// Since you cannot assure the default behavior of the element
|
|
105
|
+
// E.g: <a> will redirect on click
|
|
106
|
+
onClick: handleClick,
|
|
107
|
+
onKeyUp: handleKeyUp,
|
|
108
|
+
onKeyDown: handleKeyDown,
|
|
109
|
+
'aria-disabled': disabled || disabledFocusable || normalizedARIADisabled,
|
|
110
|
+
tabIndex: disabled && !disabledFocusable ? undefined : tabIndex !== null && tabIndex !== void 0 ? tabIndex : 0
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
if (type === 'a' && isDisabled) {
|
|
114
|
+
nextProps.href = undefined;
|
|
115
|
+
}
|
|
82
116
|
|
|
83
|
-
|
|
84
|
-
// If a <button> tag is to be rendered we just need to set disabled and aria-disabled correctly
|
|
85
|
-
if (shorthandProps.as === 'button' || shorthandProps.as === undefined) {
|
|
86
|
-
shorthandProps.disabled = disabled && !disabledFocusable;
|
|
87
|
-
shorthandProps['aria-disabled'] = disabledFocusable ? true : undefined; // Undefine events if disabledFocusable is passed in
|
|
88
|
-
|
|
89
|
-
if (disabledFocusable) {
|
|
90
|
-
shorthandProps.onClick = undefined;
|
|
91
|
-
shorthandProps.onKeyDown = undefined;
|
|
92
|
-
shorthandProps.onKeyUp = undefined;
|
|
93
|
-
}
|
|
94
|
-
} // If an <a> tag is to be rendered we have to remove disabled and type, and set aria-disabled, role and tabIndex.
|
|
95
|
-
else {
|
|
96
|
-
delete shorthandProps.disabled;
|
|
97
|
-
shorthandProps['aria-disabled'] = disabled || disabledFocusable;
|
|
98
|
-
shorthandProps.href = disabled ? undefined : shorthandProps.href;
|
|
99
|
-
shorthandProps.onClick = onClickHandler;
|
|
100
|
-
shorthandProps.onKeyDown = onKeyDownHandler;
|
|
101
|
-
shorthandProps.onKeyUp = onKeyupHandler;
|
|
102
|
-
shorthandProps.role = (_a = shorthandProps.role) !== null && _a !== void 0 ? _a : 'button';
|
|
103
|
-
shorthandProps.tabIndex = disabled && !disabledFocusable ? undefined : tabIndex !== null && tabIndex !== void 0 ? tabIndex : 0;
|
|
104
|
-
} // Remove non-DOM disabledFocusable prop
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
delete shorthandProps.disabledFocusable;
|
|
117
|
+
return nextProps;
|
|
108
118
|
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
exports.useARIAButtonProps = useARIAButtonProps;
|
|
122
|
+
/**
|
|
123
|
+
* @internal
|
|
124
|
+
*
|
|
125
|
+
* This function expects to receive a slot, if `as` property is not desired use `useARIAButtonProps` instead
|
|
126
|
+
*
|
|
127
|
+
* Button keyboard handling, role, disabled and tabIndex implementation that ensures ARIA spec
|
|
128
|
+
* for multiple scenarios of shorthand properties. Ensuring 1st rule of ARIA for cases
|
|
129
|
+
* where no attribute addition is required.
|
|
130
|
+
*/
|
|
131
|
+
|
|
132
|
+
const useARIAButtonShorthand = (slot, options) => {
|
|
133
|
+
var _a;
|
|
109
134
|
|
|
110
|
-
|
|
135
|
+
const shorthand = react_utilities_1.resolveShorthand(slot, options);
|
|
136
|
+
const shorthandARIAButton = useARIAButtonProps((_a = shorthand === null || shorthand === void 0 ? void 0 : shorthand.as) !== null && _a !== void 0 ? _a : 'button', shorthand);
|
|
137
|
+
return shorthand && shorthandARIAButton;
|
|
111
138
|
};
|
|
112
139
|
|
|
113
|
-
exports.
|
|
140
|
+
exports.useARIAButtonShorthand = useARIAButtonShorthand;
|
|
114
141
|
//# sourceMappingURL=useARIAButton.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["hooks/useARIAButton.ts"],"names":[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enter, Space } from '@fluentui/keyboard-keys';\nimport { resolveShorthand, useEventCallback } from '@fluentui/react-utilities';\nimport type { ExtractSlotProps, ResolveShorthandFunction, Slot } from '@fluentui/react-utilities';\nimport * as React from 'react';\n\nexport type ARIAButtonSlotProps<AlternateAs extends 'a' | 'div' = 'a' | 'div'> = ExtractSlotProps<\n Slot<'button', AlternateAs>\n> & {\n disabled?: boolean;\n /**\n * When set, allows the button to be focusable even when it has been disabled.\n * This is used in scenarios where it is important to keep a consistent tab order\n * for screen reader and keyboard users. The primary example of this\n * pattern is when the disabled button is in a menu or a commandbar and is seldom used for standalone buttons.\n *\n * @default false\n */\n disabledFocusable?: boolean;\n};\n\nexport type ARIAButtonProps<Type extends 'a' | 'div' | 'button' = 'a' | 'div' | 'button'> = React.PropsWithRef<\n JSX.IntrinsicElements[Type]\n> &\n Pick<ARIAButtonSlotProps, 'disabled' | 'disabledFocusable'>;\n\n/**\n * @internal\n *\n * Button keyboard handling, role, disabled and tabIndex implementation that ensures ARIA spec\n * for multiple scenarios of shorthand properties. Ensuring 1st rule of ARIA for cases\n * where no attribute addition is required.\n */\nexport function useARIAButtonProps<Type extends NonNullable<ARIAButtonSlotProps['as']>>(\n type?: Type,\n props?: ARIAButtonProps,\n): React.PropsWithRef<JSX.IntrinsicElements[Type]> {\n const {\n disabled,\n tabIndex,\n disabledFocusable = false,\n onClick,\n onKeyDown,\n onKeyUp,\n ['aria-disabled']: ariaDisabled,\n ...rest\n } = props ?? {};\n\n const normalizedARIADisabled = typeof ariaDisabled === 'string' ? ariaDisabled === 'true' : ariaDisabled;\n\n const isDisabled = disabled || disabledFocusable || normalizedARIADisabled;\n\n const handleClick: ARIAButtonProps['onClick'] = useEventCallback(ev => {\n if (isDisabled) {\n ev.preventDefault();\n ev.stopPropagation();\n } else {\n onClick?.(ev);\n }\n });\n\n const handleKeyDown: ARIAButtonProps['onKeyDown'] = useEventCallback(ev => {\n onKeyDown?.(ev);\n\n if (ev.isDefaultPrevented()) {\n return;\n }\n\n const key = ev.key;\n\n if (isDisabled && (key === Enter || key === Space)) {\n ev.preventDefault();\n ev.stopPropagation();\n return;\n }\n\n if (key === Space) {\n ev.preventDefault();\n return;\n }\n\n // If enter is pressed, activate the button\n else if (key === Enter) {\n ev.preventDefault();\n ev.currentTarget.click();\n }\n });\n\n const handleKeyUp: ARIAButtonProps['onKeyUp'] = useEventCallback(ev => {\n onKeyUp?.(ev);\n\n if (ev.isDefaultPrevented()) {\n return;\n }\n\n const key = ev.key;\n\n if (isDisabled && (key === Enter || key === Space)) {\n ev.preventDefault();\n ev.stopPropagation();\n return;\n }\n\n if (key === Space) {\n ev.preventDefault();\n ev.currentTarget.click();\n }\n });\n\n // If a <button> tag is to be rendered we just need to set disabled and aria-disabled correctly\n if (type === 'button' || type === undefined) {\n return {\n ...rest,\n tabIndex,\n disabled: disabled && !disabledFocusable,\n 'aria-disabled': disabledFocusable ? true : normalizedARIADisabled,\n // onclick should still use internal handler to ensure prevention if disabled\n // if disabledFocusable then there's no requirement for handlers as those events should not be propagated\n onClick: disabledFocusable ? undefined : handleClick,\n onKeyUp: disabledFocusable ? undefined : onKeyUp,\n onKeyDown: disabledFocusable ? undefined : onKeyDown,\n } as React.PropsWithRef<JSX.IntrinsicElements[Type]>;\n }\n\n // If an <a> or <div> tag is to be rendered we have to remove disabled and type,\n // and set aria-disabled, role and tabIndex.\n else {\n const nextProps = {\n role: 'button',\n ...rest,\n // If it's not a <button> than listeners are required even with disabledFocusable\n // Since you cannot assure the default behavior of the element\n // E.g: <a> will redirect on click\n onClick: handleClick,\n onKeyUp: handleKeyUp,\n onKeyDown: handleKeyDown,\n 'aria-disabled': disabled || disabledFocusable || normalizedARIADisabled,\n tabIndex: disabled && !disabledFocusable ? undefined : tabIndex ?? 0,\n } as React.PropsWithRef<JSX.IntrinsicElements[Type]>;\n\n if (type === 'a' && isDisabled) {\n (nextProps as JSX.IntrinsicElements['a']).href = undefined;\n }\n\n return nextProps;\n }\n}\n\n/**\n * @internal\n *\n * This function expects to receive a slot, if `as` property is not desired use `useARIAButtonProps` instead\n *\n * Button keyboard handling, role, disabled and tabIndex implementation that ensures ARIA spec\n * for multiple scenarios of shorthand properties. Ensuring 1st rule of ARIA for cases\n * where no attribute addition is required.\n */\nexport const useARIAButtonShorthand: ResolveShorthandFunction<ARIAButtonSlotProps> = (slot, options) => {\n const shorthand = resolveShorthand(slot, options);\n const shorthandARIAButton = useARIAButtonProps(shorthand?.as ?? 'button', shorthand);\n return shorthand && shorthandARIAButton;\n};\n"],"sourceRoot":"../src/"}
|
package/lib-commonjs/index.js
CHANGED
|
@@ -3,23 +3,20 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.useARIAButtonProps = exports.useARIAButtonShorthand = void 0;
|
|
7
7
|
|
|
8
8
|
var index_1 = /*#__PURE__*/require("./hooks/index");
|
|
9
9
|
|
|
10
|
-
Object.defineProperty(exports, "
|
|
10
|
+
Object.defineProperty(exports, "useARIAButtonShorthand", {
|
|
11
11
|
enumerable: true,
|
|
12
12
|
get: function () {
|
|
13
|
-
return index_1.
|
|
13
|
+
return index_1.useARIAButtonShorthand;
|
|
14
14
|
}
|
|
15
15
|
});
|
|
16
|
-
|
|
17
|
-
var index_2 = /*#__PURE__*/require("./utils/index");
|
|
18
|
-
|
|
19
|
-
Object.defineProperty(exports, "mergeARIADisabled", {
|
|
16
|
+
Object.defineProperty(exports, "useARIAButtonProps", {
|
|
20
17
|
enumerable: true,
|
|
21
18
|
get: function () {
|
|
22
|
-
return
|
|
19
|
+
return index_1.useARIAButtonProps;
|
|
23
20
|
}
|
|
24
21
|
});
|
|
25
22
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["index.ts"],"names":[],"mappings":";;;;;;;AAAA,IAAA,OAAA,gBAAA,OAAA,CAAA,eAAA,CAAA;;AAAS,MAAA,CAAA,cAAA,CAAA,OAAA,EAAA,
|
|
1
|
+
{"version":3,"sources":["index.ts"],"names":[],"mappings":";;;;;;;AAAA,IAAA,OAAA,gBAAA,OAAA,CAAA,eAAA,CAAA;;AAAS,MAAA,CAAA,cAAA,CAAA,OAAA,EAAA,wBAAA,EAAA;EAAA,UAAA,EAAA,IAAA;EAAA,GAAA,EAAA,YAAA;IAAA,OAAA,OAAA,CAAA,sBAAA;EAAsB;AAAtB,CAAA;AAAwB,MAAA,CAAA,cAAA,CAAA,OAAA,EAAA,oBAAA,EAAA;EAAA,UAAA,EAAA,IAAA;EAAA,GAAA,EAAA,YAAA;IAAA,OAAA,OAAA,CAAA,kBAAA;EAAkB;AAAlB,CAAA","sourcesContent":["export { useARIAButtonShorthand, useARIAButtonProps } from './hooks/index';\nexport type { ARIAButtonSlotProps, ARIAButtonProps } from './hooks/index';\n"],"sourceRoot":"../src/"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluentui/react-aria",
|
|
3
|
-
"version": "9.0
|
|
3
|
+
"version": "9.1.0",
|
|
4
4
|
"description": "React helper to ensure ARIA",
|
|
5
5
|
"main": "lib-commonjs/index.js",
|
|
6
6
|
"module": "lib/index.js",
|
|
@@ -42,7 +42,8 @@
|
|
|
42
42
|
},
|
|
43
43
|
"beachball": {
|
|
44
44
|
"disallowedChangeTypes": [
|
|
45
|
-
"major"
|
|
45
|
+
"major",
|
|
46
|
+
"prerelease"
|
|
46
47
|
]
|
|
47
48
|
},
|
|
48
49
|
"exports": {
|
package/lib/utils/index.js
DELETED
package/lib/utils/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"../src/","sources":["utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC","sourcesContent":["export * from './mergeARIADisabled';\n"]}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @internal
|
|
3
|
-
* Merges disabled declaration with `aria-disabled`
|
|
4
|
-
*/
|
|
5
|
-
export function mergeARIADisabled(shorthand) {
|
|
6
|
-
var _a;
|
|
7
|
-
|
|
8
|
-
const disabled = (_a = shorthand.disabled) !== null && _a !== void 0 ? _a : shorthand['aria-disabled'];
|
|
9
|
-
|
|
10
|
-
if (typeof disabled === 'string') {
|
|
11
|
-
return disabled === 'false' ? false : true;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
return disabled !== null && disabled !== void 0 ? disabled : false;
|
|
15
|
-
}
|
|
16
|
-
//# sourceMappingURL=mergeARIADisabled.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["utils/mergeARIADisabled.ts"],"names":[],"mappings":"AAAA;;;AAGG;AACH,OAAM,SAAU,iBAAV,CAA4B,SAA5B,EAAiG;;;EACrG,MAAM,QAAQ,GAAG,CAAA,EAAA,GAAA,SAAS,CAAC,QAAV,MAAkB,IAAlB,IAAkB,EAAA,KAAA,KAAA,CAAlB,GAAkB,EAAlB,GAAsB,SAAS,CAAC,eAAD,CAAhD;;EACA,IAAI,OAAO,QAAP,KAAoB,QAAxB,EAAkC;IAChC,OAAO,QAAQ,KAAK,OAAb,GAAuB,KAAvB,GAA+B,IAAtC;EACD;;EACD,OAAO,QAAQ,KAAA,IAAR,IAAA,QAAQ,KAAA,KAAA,CAAR,GAAA,QAAA,GAAY,KAAnB;AACD","sourcesContent":["/**\n * @internal\n * Merges disabled declaration with `aria-disabled`\n */\nexport function mergeARIADisabled(shorthand: { 'aria-disabled'?: string | boolean; disabled?: boolean }) {\n const disabled = shorthand.disabled ?? shorthand['aria-disabled'];\n if (typeof disabled === 'string') {\n return disabled === 'false' ? false : true;\n }\n return disabled ?? false;\n}\n"],"sourceRoot":"../src/"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["utils/index.ts"],"names":[],"mappings":";;;;;;;;AAAA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,qBAAA,CAAA,EAAA,OAAA","sourcesContent":["export * from './mergeARIADisabled';\n"],"sourceRoot":"../src/"}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.mergeARIADisabled = void 0;
|
|
7
|
-
/**
|
|
8
|
-
* @internal
|
|
9
|
-
* Merges disabled declaration with `aria-disabled`
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
function mergeARIADisabled(shorthand) {
|
|
13
|
-
var _a;
|
|
14
|
-
|
|
15
|
-
const disabled = (_a = shorthand.disabled) !== null && _a !== void 0 ? _a : shorthand['aria-disabled'];
|
|
16
|
-
|
|
17
|
-
if (typeof disabled === 'string') {
|
|
18
|
-
return disabled === 'false' ? false : true;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
return disabled !== null && disabled !== void 0 ? disabled : false;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
exports.mergeARIADisabled = mergeARIADisabled;
|
|
25
|
-
//# sourceMappingURL=mergeARIADisabled.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["utils/mergeARIADisabled.ts"],"names":[],"mappings":";;;;;;AAAA;;;AAGG;;AACH,SAAgB,iBAAhB,CAAkC,SAAlC,EAAuG;;;EACrG,MAAM,QAAQ,GAAG,CAAA,EAAA,GAAA,SAAS,CAAC,QAAV,MAAkB,IAAlB,IAAkB,EAAA,KAAA,KAAA,CAAlB,GAAkB,EAAlB,GAAsB,SAAS,CAAC,eAAD,CAAhD;;EACA,IAAI,OAAO,QAAP,KAAoB,QAAxB,EAAkC;IAChC,OAAO,QAAQ,KAAK,OAAb,GAAuB,KAAvB,GAA+B,IAAtC;EACD;;EACD,OAAO,QAAQ,KAAA,IAAR,IAAA,QAAQ,KAAA,KAAA,CAAR,GAAA,QAAA,GAAY,KAAnB;AACD;;AAND,OAAA,CAAA,iBAAA,GAAA,iBAAA","sourcesContent":["/**\n * @internal\n * Merges disabled declaration with `aria-disabled`\n */\nexport function mergeARIADisabled(shorthand: { 'aria-disabled'?: string | boolean; disabled?: boolean }) {\n const disabled = shorthand.disabled ?? shorthand['aria-disabled'];\n if (typeof disabled === 'string') {\n return disabled === 'false' ? false : true;\n }\n return disabled ?? false;\n}\n"],"sourceRoot":"../src/"}
|