@fluentui/react-aria 0.0.0-nightly-20220714-0418.1 → 0.0.0-nightly-20221007-1237.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/CHANGELOG.json +160 -8
  2. package/CHANGELOG.md +64 -7
  3. package/dist/index.d.ts +71 -7
  4. package/lib/button/index.js +4 -0
  5. package/lib/button/index.js.map +1 -0
  6. package/lib/button/types.js +2 -0
  7. package/lib/button/types.js.map +1 -0
  8. package/lib/button/useARIAButtonProps.js +129 -0
  9. package/lib/button/useARIAButtonProps.js.map +1 -0
  10. package/lib/button/useARIAButtonShorthand.js +20 -0
  11. package/lib/button/useARIAButtonShorthand.js.map +1 -0
  12. package/lib/index.js +1 -2
  13. package/lib/index.js.map +1 -1
  14. package/lib-commonjs/button/index.js +14 -0
  15. package/lib-commonjs/button/index.js.map +1 -0
  16. package/lib-commonjs/button/types.js +6 -0
  17. package/lib-commonjs/button/types.js.map +1 -0
  18. package/lib-commonjs/button/useARIAButtonProps.js +140 -0
  19. package/lib-commonjs/button/useARIAButtonProps.js.map +1 -0
  20. package/lib-commonjs/button/useARIAButtonShorthand.js +31 -0
  21. package/lib-commonjs/button/useARIAButtonShorthand.js.map +1 -0
  22. package/lib-commonjs/index.js +6 -9
  23. package/lib-commonjs/index.js.map +1 -1
  24. package/package.json +6 -10
  25. package/dist/tsdoc-metadata.json +0 -11
  26. package/lib/hooks/index.js +0 -2
  27. package/lib/hooks/index.js.map +0 -1
  28. package/lib/hooks/useARIAButton.js +0 -103
  29. package/lib/hooks/useARIAButton.js.map +0 -1
  30. package/lib/utils/index.js +0 -2
  31. package/lib/utils/index.js.map +0 -1
  32. package/lib/utils/mergeARIADisabled.js +0 -16
  33. package/lib/utils/mergeARIADisabled.js.map +0 -1
  34. package/lib-commonjs/hooks/index.js +0 -10
  35. package/lib-commonjs/hooks/index.js.map +0 -1
  36. package/lib-commonjs/hooks/useARIAButton.js +0 -114
  37. package/lib-commonjs/hooks/useARIAButton.js.map +0 -1
  38. package/lib-commonjs/utils/index.js +0 -10
  39. package/lib-commonjs/utils/index.js.map +0 -1
  40. package/lib-commonjs/utils/mergeARIADisabled.js +0 -25
  41. package/lib-commonjs/utils/mergeARIADisabled.js.map +0 -1
@@ -0,0 +1,140 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useARIAButtonProps = void 0;
7
+
8
+ const keyboard_keys_1 = /*#__PURE__*/require("@fluentui/keyboard-keys");
9
+
10
+ const react_utilities_1 = /*#__PURE__*/require("@fluentui/react-utilities");
11
+ /**
12
+ * @internal
13
+ *
14
+ * Button keyboard handling, role, disabled and tabIndex implementation that ensures ARIA spec
15
+ * for multiple scenarios of non native button elements. Ensuring 1st rule of ARIA for cases
16
+ * where no attribute addition is required.
17
+ *
18
+ * @param type - the proper scenario to be interpreted by the hook.
19
+ * 1. `button` - Minimal interference from the hook, as semantic button already supports most of the states
20
+ * 2. `a` or `div` - Proper keyboard/mouse handling plus other support to ensure ARIA behavior
21
+ * @param props - the props to be passed down the line to the desired element.
22
+ * This hook will encapsulate proper properties, such as `onClick`, `onKeyDown`, `onKeyUp`, etc,.
23
+ *
24
+ * @example
25
+ * ```tsx
26
+ * const buttonProps = useARIAButtonProps('a', {
27
+ * href: './some-route'
28
+ * onClick: () => console.log('this should run both on click and Space and Enter')
29
+ * })
30
+ *
31
+ * // ...
32
+ *
33
+ * return (
34
+ * <a {...buttonProps}>This anchor will behave as a proper button</a>
35
+ * )
36
+ * ```
37
+ */
38
+
39
+
40
+ function useARIAButtonProps(type, props) {
41
+ const {
42
+ disabled,
43
+ disabledFocusable = false,
44
+ ['aria-disabled']: ariaDisabled,
45
+ onClick,
46
+ onKeyDown,
47
+ onKeyUp,
48
+ ...rest
49
+ } = props !== null && props !== void 0 ? props : {};
50
+ const normalizedARIADisabled = typeof ariaDisabled === 'string' ? ariaDisabled === 'true' : ariaDisabled;
51
+ const isDisabled = disabled || disabledFocusable || normalizedARIADisabled;
52
+ const handleClick = react_utilities_1.useEventCallback(ev => {
53
+ if (isDisabled) {
54
+ ev.preventDefault();
55
+ ev.stopPropagation();
56
+ } else {
57
+ onClick === null || onClick === void 0 ? void 0 : onClick(ev);
58
+ }
59
+ });
60
+ const handleKeyDown = react_utilities_1.useEventCallback(ev => {
61
+ onKeyDown === null || onKeyDown === void 0 ? void 0 : onKeyDown(ev);
62
+
63
+ if (ev.isDefaultPrevented()) {
64
+ return;
65
+ }
66
+
67
+ const key = ev.key;
68
+
69
+ if (isDisabled && (key === keyboard_keys_1.Enter || key === keyboard_keys_1.Space)) {
70
+ ev.preventDefault();
71
+ ev.stopPropagation();
72
+ return;
73
+ }
74
+
75
+ if (key === keyboard_keys_1.Space) {
76
+ ev.preventDefault();
77
+ return;
78
+ } // If enter is pressed, activate the button
79
+ else if (key === keyboard_keys_1.Enter) {
80
+ ev.preventDefault();
81
+ ev.currentTarget.click();
82
+ }
83
+ });
84
+ const handleKeyUp = react_utilities_1.useEventCallback(ev => {
85
+ onKeyUp === null || onKeyUp === void 0 ? void 0 : onKeyUp(ev);
86
+
87
+ if (ev.isDefaultPrevented()) {
88
+ return;
89
+ }
90
+
91
+ const key = ev.key;
92
+
93
+ if (isDisabled && (key === keyboard_keys_1.Enter || key === keyboard_keys_1.Space)) {
94
+ ev.preventDefault();
95
+ ev.stopPropagation();
96
+ return;
97
+ }
98
+
99
+ if (key === keyboard_keys_1.Space) {
100
+ ev.preventDefault();
101
+ ev.currentTarget.click();
102
+ }
103
+ }); // If a <button> tag is to be rendered we just need to set disabled and aria-disabled correctly
104
+
105
+ if (type === 'button' || type === undefined) {
106
+ return { ...rest,
107
+ disabled: disabled && !disabledFocusable,
108
+ 'aria-disabled': disabledFocusable ? true : normalizedARIADisabled,
109
+ // onclick should still use internal handler to ensure prevention if disabled
110
+ // if disabledFocusable then there's no requirement for handlers as those events should not be propagated
111
+ onClick: disabledFocusable ? undefined : handleClick,
112
+ onKeyUp: disabledFocusable ? undefined : onKeyUp,
113
+ onKeyDown: disabledFocusable ? undefined : onKeyDown
114
+ };
115
+ } // If an <a> or <div> tag is to be rendered we have to remove disabled and type,
116
+ // and set aria-disabled, role and tabIndex.
117
+ else {
118
+ const resultProps = {
119
+ role: 'button',
120
+ tabIndex: disabled && !disabledFocusable ? undefined : 0,
121
+ ...rest,
122
+ // If it's not a <button> than listeners are required even with disabledFocusable
123
+ // Since you cannot assure the default behavior of the element
124
+ // E.g: <a> will redirect on click
125
+ onClick: handleClick,
126
+ onKeyUp: handleKeyUp,
127
+ onKeyDown: handleKeyDown,
128
+ 'aria-disabled': disabled || disabledFocusable || normalizedARIADisabled
129
+ };
130
+
131
+ if (type === 'a' && isDisabled) {
132
+ resultProps.href = undefined;
133
+ }
134
+
135
+ return resultProps;
136
+ }
137
+ }
138
+
139
+ exports.useARIAButtonProps = useARIAButtonProps;
140
+ //# sourceMappingURL=useARIAButtonProps.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/button/useARIAButtonProps.ts"],"names":[],"mappings":";;;;;;;AAAA,MAAA,eAAA,gBAAA,OAAA,CAAA,yBAAA,CAAA;;AACA,MAAA,iBAAA,gBAAA,OAAA,CAAA,2BAAA,CAAA;AAIA;;;;;;;;;;;;;;;;;;;;;;;;;;AA0BG;;;AACH,SAAgB,kBAAhB,CACE,IADF,EAEE,KAFF,EAEe;EAEb,MAAM;IAAE,QAAF;IAAY,iBAAiB,GAAG,KAAhC;IAAuC,CAAC,eAAD,GAAmB,YAA1D;IAAwE,OAAxE;IAAiF,SAAjF;IAA4F,OAA5F;IAAqG,GAAG;EAAxG,IACJ,KAAK,KAAA,IAAL,IAAA,KAAK,KAAA,KAAA,CAAL,GAAA,KAAA,GAAS,EADX;EAGA,MAAM,sBAAsB,GAAG,OAAO,YAAP,KAAwB,QAAxB,GAAmC,YAAY,KAAK,MAApD,GAA6D,YAA5F;EAEA,MAAM,UAAU,GAAG,Q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back } from '@fluentui/react-utilities';\nimport * as React from 'react';\nimport type { ARIAButtonElementIntersection, ARIAButtonProps, ARIAButtonResultProps, ARIAButtonType } from './types';\n\n/**\n * @internal\n *\n * Button keyboard handling, role, disabled and tabIndex implementation that ensures ARIA spec\n * for multiple scenarios of non native button elements. Ensuring 1st rule of ARIA for cases\n * where no attribute addition is required.\n *\n * @param type - the proper scenario to be interpreted by the hook.\n * 1. `button` - Minimal interference from the hook, as semantic button already supports most of the states\n * 2. `a` or `div` - Proper keyboard/mouse handling plus other support to ensure ARIA behavior\n * @param props - the props to be passed down the line to the desired element.\n * This hook will encapsulate proper properties, such as `onClick`, `onKeyDown`, `onKeyUp`, etc,.\n *\n * @example\n * ```tsx\n * const buttonProps = useARIAButtonProps('a', {\n * href: './some-route'\n * onClick: () => console.log('this should run both on click and Space and Enter')\n * })\n *\n * // ...\n *\n * return (\n * <a {...buttonProps}>This anchor will behave as a proper button</a>\n * )\n * ```\n */\nexport function useARIAButtonProps<Type extends ARIAButtonType, Props extends ARIAButtonProps<Type>>(\n type?: Type,\n props?: Props,\n): ARIAButtonResultProps<Type, Props> {\n const { disabled, disabledFocusable = false, ['aria-disabled']: ariaDisabled, onClick, onKeyDown, onKeyUp, ...rest } =\n props ?? {};\n\n const normalizedARIADisabled = typeof ariaDisabled === 'string' ? ariaDisabled === 'true' : ariaDisabled;\n\n const isDisabled = disabled || disabledFocusable || normalizedARIADisabled;\n\n const handleClick = useEventCallback((ev: React.MouseEvent<ARIAButtonElementIntersection>) => {\n if (isDisabled) {\n ev.preventDefault();\n ev.stopPropagation();\n } else {\n onClick?.(ev);\n }\n });\n\n const handleKeyDown = useEventCallback((ev: React.KeyboardEvent<ARIAButtonElementIntersection>) => {\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 = useEventCallback((ev: React.KeyboardEvent<ARIAButtonElementIntersection>) => {\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 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 ARIAButtonResultProps<Type, Props>;\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 resultProps = {\n role: 'button',\n tabIndex: disabled && !disabledFocusable ? undefined : 0,\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 } as ARIAButtonResultProps<Type, Props>;\n\n if (type === 'a' && isDisabled) {\n (resultProps as ARIAButtonResultProps<'a', Props>).href = undefined;\n }\n\n return resultProps;\n }\n}\n"],"sourceRoot":""}
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useARIAButtonShorthand = void 0;
7
+
8
+ const react_utilities_1 = /*#__PURE__*/require("@fluentui/react-utilities");
9
+
10
+ const useARIAButtonProps_1 = /*#__PURE__*/require("./useARIAButtonProps");
11
+ /**
12
+ * @internal
13
+ *
14
+ * This function expects to receive a slot, if `as` property is not desired use `useARIAButtonProps` instead
15
+ *
16
+ * Button keyboard handling, role, disabled and tabIndex implementation that ensures ARIA spec
17
+ * for multiple scenarios of shorthand properties. Ensuring 1st rule of ARIA for cases
18
+ * where no attribute addition is required.
19
+ */
20
+
21
+
22
+ const useARIAButtonShorthand = (slot, options) => {
23
+ var _a;
24
+
25
+ const shorthand = react_utilities_1.resolveShorthand(slot, options);
26
+ const shorthandARIAButton = useARIAButtonProps_1.useARIAButtonProps((_a = shorthand === null || shorthand === void 0 ? void 0 : shorthand.as) !== null && _a !== void 0 ? _a : 'button', shorthand);
27
+ return shorthand && shorthandARIAButton;
28
+ };
29
+
30
+ exports.useARIAButtonShorthand = useARIAButtonShorthand;
31
+ //# sourceMappingURL=useARIAButtonShorthand.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/button/useARIAButtonShorthand.ts"],"names":[],"mappings":";;;;;;;AAAA,MAAA,iBAAA,gBAAA,OAAA,CAAA,2BAAA,CAAA;;AACA,MAAA,oBAAA,gBAAA,OAAA,CAAA,sBAAA,CAAA;AAIA;;;;;;;;AAQG;;;AACI,MAAM,sBAAsB,GAAkD,CAAC,IAAD,EAAO,OAAP,KAAkB;;;EACrG,MAAM,SAAS,GAAG,iBAAA,CAAA,gBAAA,CAAiB,IAAjB,EAAuB,OAAvB,CAAlB;EACA,MAAM,mBAAmB,GAAG,oBAAA,CAAA,kBAAA,CAAoD,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,QAArE,EAA+E,SAA/E,CAA5B;EACA,OAAO,SAAS,IAAI,mBAApB;AACD,CAJM;;AAAM,OAAA,CAAA,sBAAA,GAAsB,sBAAtB","sourcesContent":["import { resolveShorthand } from '@fluentui/react-utilities';\nimport { useARIAButtonProps } from './useARIAButtonProps';\nimport type { ResolveShorthandFunction } from '@fluentui/react-utilities';\nimport type { ARIAButtonProps, ARIAButtonSlotProps, ARIAButtonType } from './types';\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<ARIAButtonType, ARIAButtonProps>(shorthand?.as ?? 'button', shorthand);\n return shorthand && shorthandARIAButton;\n};\n"],"sourceRoot":""}
@@ -3,23 +3,20 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.mergeARIADisabled = exports.useARIAButton = void 0;
6
+ exports.useARIAButtonProps = exports.useARIAButtonShorthand = void 0;
7
7
 
8
- var index_1 = /*#__PURE__*/require("./hooks/index");
8
+ var index_1 = /*#__PURE__*/require("./button/index");
9
9
 
10
- Object.defineProperty(exports, "useARIAButton", {
10
+ Object.defineProperty(exports, "useARIAButtonShorthand", {
11
11
  enumerable: true,
12
12
  get: function () {
13
- return index_1.useARIAButton;
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 index_2.mergeARIADisabled;
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,eAAA,EAAA;EAAA,UAAA,EAAA,IAAA;EAAA,GAAA,EAAA,YAAA;IAAA,OAAA,OAAA,CAAA,aAAA;EAAa;AAAb,CAAA;;AAET,IAAA,OAAA,gBAAA,OAAA,CAAA,eAAA,CAAA;;AAAS,MAAA,CAAA,cAAA,CAAA,OAAA,EAAA,mBAAA,EAAA;EAAA,UAAA,EAAA,IAAA;EAAA,GAAA,EAAA,YAAA;IAAA,OAAA,OAAA,CAAA,iBAAA;EAAiB;AAAjB,CAAA","sourcesContent":["export { useARIAButton } from './hooks/index';\nexport type { ARIAButtonSlotProps } from './hooks/index';\nexport { mergeARIADisabled } from './utils/index';\n"],"sourceRoot":"../src/"}
1
+ {"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;AAAA,IAAA,OAAA,gBAAA,OAAA,CAAA,gBAAA,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 './button/index';\nexport type {\n ARIAButtonSlotProps,\n ARIAButtonProps,\n ARIAButtonResultProps,\n ARIAButtonType,\n ARIAButtonElement,\n ARIAButtonElementIntersection,\n} from './button/index';\n"],"sourceRoot":""}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluentui/react-aria",
3
- "version": "0.0.0-nightly-20220714-0418.1",
3
+ "version": "0.0.0-nightly-20221007-1237.1",
4
4
  "description": "React helper to ensure ARIA",
5
5
  "main": "lib-commonjs/index.js",
6
6
  "module": "lib/index.js",
@@ -20,8 +20,8 @@
20
20
  "start": "yarn storybook",
21
21
  "test": "jest --passWithNoTests",
22
22
  "docs": "api-extractor run --config=config/api-extractor.local.json --local",
23
- "build:local": "tsc -p ./tsconfig.lib.json --module esnext --emitDeclarationOnly && node ../../../scripts/typescript/normalize-import --output ./dist/packages/react-components/react-aria/src && yarn docs",
24
- "storybook": "node ../../../scripts/storybook/runner",
23
+ "build:local": "tsc -p ./tsconfig.lib.json --module esnext --emitDeclarationOnly && node ../../../scripts/typescript/normalize-import --output ./dist/types/types/packages/react-components/react-aria/src && yarn docs",
24
+ "storybook": "start-storybook",
25
25
  "type-check": "tsc -b tsconfig.json"
26
26
  },
27
27
  "devDependencies": {
@@ -30,8 +30,8 @@
30
30
  "@fluentui/scripts": "^1.0.0"
31
31
  },
32
32
  "dependencies": {
33
- "@fluentui/keyboard-keys": "^0.0.0-nightly-20220714-0418.1",
34
- "@fluentui/react-utilities": "^0.0.0-nightly-20220714-0418.1",
33
+ "@fluentui/keyboard-keys": "^0.0.0-nightly-20221007-1237.1",
34
+ "@fluentui/react-utilities": "^0.0.0-nightly-20221007-1237.1",
35
35
  "tslib": "^2.1.0"
36
36
  },
37
37
  "peerDependencies": {
@@ -40,11 +40,7 @@
40
40
  "react": ">=16.8.0 <18.0.0",
41
41
  "react-dom": ">=16.8.0 <18.0.0"
42
42
  },
43
- "beachball": {
44
- "disallowedChangeTypes": [
45
- "major"
46
- ]
47
- },
43
+ "beachball": {},
48
44
  "exports": {
49
45
  ".": {
50
46
  "types": "./lib/index.d.ts",
@@ -1,11 +0,0 @@
1
- // This file is read by tools that parse documentation comments conforming to the TSDoc standard.
2
- // It should be published with your NPM package. It should not be tracked by Git.
3
- {
4
- "tsdocVersion": "0.12",
5
- "toolPackages": [
6
- {
7
- "packageName": "@microsoft/api-extractor",
8
- "packageVersion": "7.18.1"
9
- }
10
- ]
11
- }
@@ -1,2 +0,0 @@
1
- export * from './useARIAButton';
2
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"../src/","sources":["hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC","sourcesContent":["export * from './useARIAButton';\n"]}
@@ -1,103 +0,0 @@
1
- import { Enter, Space } from '@fluentui/keyboard-keys';
2
- import { resolveShorthand, useEventCallback } from '@fluentui/react-utilities';
3
- /**
4
- * Button keyboard handling, role, disabled and tabIndex implementation that ensures ARIA spec
5
- * for multiple scenarios of shorthand properties. Ensuring 1st rule of ARIA for cases
6
- * where no attribute addition is required.
7
- */
8
-
9
- export const useARIAButton = (shorthand, options) => {
10
- var _a;
11
-
12
- const shorthandProps = resolveShorthand(shorthand, options);
13
- const {
14
- disabled,
15
- disabledFocusable,
16
- onClick,
17
- onKeyDown,
18
- onKeyUp,
19
- tabIndex
20
- } = shorthandProps || {};
21
- const onClickHandler = useEventCallback(ev => {
22
- if (disabled || disabledFocusable) {
23
- ev.preventDefault();
24
- ev.stopPropagation();
25
- } else {
26
- onClick === null || onClick === void 0 ? void 0 : onClick(ev);
27
- }
28
- });
29
- const onKeyDownHandler = useEventCallback(ev => {
30
- onKeyDown === null || onKeyDown === void 0 ? void 0 : onKeyDown(ev);
31
-
32
- if (ev.isDefaultPrevented()) {
33
- return;
34
- }
35
-
36
- const key = ev.key;
37
-
38
- if ((disabled || disabledFocusable) && (key === Enter || key === Space)) {
39
- ev.preventDefault();
40
- ev.stopPropagation();
41
- return;
42
- }
43
-
44
- if (key === Space) {
45
- ev.preventDefault();
46
- return;
47
- } // If enter is pressed, activate the button
48
- else if (key === Enter) {
49
- ev.preventDefault();
50
- ev.currentTarget.click();
51
- }
52
- });
53
- const onKeyupHandler = useEventCallback(ev => {
54
- onKeyUp === null || onKeyUp === void 0 ? void 0 : onKeyUp(ev);
55
-
56
- if (ev.isDefaultPrevented()) {
57
- return;
58
- }
59
-
60
- const key = ev.key;
61
-
62
- if ((disabled || disabledFocusable) && (key === Enter || key === Space)) {
63
- ev.preventDefault();
64
- ev.stopPropagation();
65
- return;
66
- }
67
-
68
- if (key === Space) {
69
- ev.preventDefault();
70
- ev.currentTarget.click();
71
- }
72
- });
73
-
74
- if (shorthandProps) {
75
- // If a <button> tag is to be rendered we just need to set disabled and aria-disabled correctly
76
- if (shorthandProps.as === 'button' || shorthandProps.as === undefined) {
77
- shorthandProps.disabled = disabled && !disabledFocusable;
78
- shorthandProps['aria-disabled'] = disabledFocusable ? true : undefined; // Undefine events if disabledFocusable is passed in
79
-
80
- if (disabledFocusable) {
81
- shorthandProps.onClick = undefined;
82
- shorthandProps.onKeyDown = undefined;
83
- shorthandProps.onKeyUp = undefined;
84
- }
85
- } // If an <a> tag is to be rendered we have to remove disabled and type, and set aria-disabled, role and tabIndex.
86
- else {
87
- delete shorthandProps.disabled;
88
- shorthandProps['aria-disabled'] = disabled || disabledFocusable;
89
- shorthandProps.href = disabled ? undefined : shorthandProps.href;
90
- shorthandProps.onClick = onClickHandler;
91
- shorthandProps.onKeyDown = onKeyDownHandler;
92
- shorthandProps.onKeyUp = onKeyupHandler;
93
- shorthandProps.role = (_a = shorthandProps.role) !== null && _a !== void 0 ? _a : 'button';
94
- shorthandProps.tabIndex = disabled && !disabledFocusable ? undefined : tabIndex !== null && tabIndex !== void 0 ? tabIndex : 0;
95
- } // Remove non-DOM disabledFocusable prop
96
-
97
-
98
- delete shorthandProps.disabledFocusable;
99
- }
100
-
101
- return shorthandProps;
102
- };
103
- //# sourceMappingURL=useARIAButton.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["hooks/useARIAButton.ts"],"names":[],"mappings":"AAAA,SAAS,KAAT,EAAgB,KAAhB,QAA6B,yBAA7B;AACA,SAAS,gBAAT,EAA2B,gBAA3B,QAAmD,2BAAnD;AAQA;;;;AAIG;;AACH,OAAO,MA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AAA,GAAA,cAAc,CAAC,IAAf,MAAmB,IAAnB,IAAmB,EAAA,KAAA,KAAA,CAAnB,GAAmB,EAAnB,GAAuB,QAA7C;MACA,cAAc,CAAC,QAAf,GAA0B,QAAQ,IAAI,CAAC,iBAAb,GAAiC,SAAjC,GAA6C,QAAQ,KAAA,IAAR,IAAA,QAAQ,KAAA,KAAA,CAAR,GAAA,QAAA,GAAY,CAAnF;IACD,CA1BiB,CA4BlB;;;IACA,OAAO,cAAc,CAAC,iBAAtB;EACD;;EAED,OAAO,cAAP;AACD,CAhGM","sourcesContent":["import { Enter, Space } from '@fluentui/keyboard-keys';\nimport { resolveShorthand, useEventCallback } from '@fluentui/react-utilities';\nimport type { ExtractSlotProps, ResolveShorthandFunction, Slot } from '@fluentui/react-utilities';\n\nexport type ARIAButtonSlotProps = ExtractSlotProps<Slot<'button', 'a'>> & {\n disabled?: boolean;\n disabledFocusable?: boolean;\n};\n\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 useARIAButton: ResolveShorthandFunction<ARIAButtonSlotProps> = (shorthand, options) => {\n const shorthandProps = resolveShorthand(shorthand, options);\n\n const { disabled, disabledFocusable, onClick, onKeyDown, onKeyUp, tabIndex } = (shorthandProps ||\n {}) as ARIAButtonSlotProps;\n\n const onClickHandler: ARIAButtonSlotProps['onClick'] = useEventCallback(ev => {\n if (disabled || disabledFocusable) {\n ev.preventDefault();\n ev.stopPropagation();\n } else {\n onClick?.(ev);\n }\n });\n\n const onKeyDownHandler: ARIAButtonSlotProps['onKeyDown'] = useEventCallback(ev => {\n onKeyDown?.(ev);\n\n if (ev.isDefaultPrevented()) {\n return;\n }\n\n const key = ev.key;\n\n if ((disabled || disabledFocusable) && (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 onKeyupHandler: ARIAButtonSlotProps['onKeyUp'] = useEventCallback(ev => {\n onKeyUp?.(ev);\n\n if (ev.isDefaultPrevented()) {\n return;\n }\n\n const key = ev.key;\n\n if ((disabled || disabledFocusable) && (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 (shorthandProps) {\n // If a <button> tag is to be rendered we just need to set disabled and aria-disabled correctly\n if (shorthandProps.as === 'button' || shorthandProps.as === undefined) {\n shorthandProps.disabled = disabled && !disabledFocusable;\n shorthandProps['aria-disabled'] = disabledFocusable ? true : undefined;\n\n // Undefine events if disabledFocusable is passed in\n if (disabledFocusable) {\n shorthandProps.onClick = undefined;\n shorthandProps.onKeyDown = undefined;\n shorthandProps.onKeyUp = undefined;\n }\n }\n\n // If an <a> tag is to be rendered we have to remove disabled and type, and set aria-disabled, role and tabIndex.\n else {\n delete shorthandProps.disabled;\n shorthandProps['aria-disabled'] = disabled || disabledFocusable;\n (shorthandProps as JSX.IntrinsicElements['a']).href = disabled\n ? undefined\n : (shorthandProps as JSX.IntrinsicElements['a']).href;\n shorthandProps.onClick = onClickHandler;\n shorthandProps.onKeyDown = onKeyDownHandler;\n shorthandProps.onKeyUp = onKeyupHandler;\n shorthandProps.role = shorthandProps.role ?? 'button';\n shorthandProps.tabIndex = disabled && !disabledFocusable ? undefined : tabIndex ?? 0;\n }\n\n // Remove non-DOM disabledFocusable prop\n delete shorthandProps.disabledFocusable;\n }\n\n return shorthandProps;\n};\n"],"sourceRoot":"../src/"}
@@ -1,2 +0,0 @@
1
- export * from './mergeARIADisabled';
2
- //# sourceMappingURL=index.js.map
@@ -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,10 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
-
7
- const tslib_1 = /*#__PURE__*/require("tslib");
8
-
9
- tslib_1.__exportStar(require("./useARIAButton"), exports);
10
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["hooks/index.ts"],"names":[],"mappings":";;;;;;;;AAAA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,iBAAA,CAAA,EAAA,OAAA","sourcesContent":["export * from './useARIAButton';\n"],"sourceRoot":"../src/"}
@@ -1,114 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.useARIAButton = void 0;
7
-
8
- const keyboard_keys_1 = /*#__PURE__*/require("@fluentui/keyboard-keys");
9
-
10
- const react_utilities_1 = /*#__PURE__*/require("@fluentui/react-utilities");
11
- /**
12
- * Button keyboard handling, role, disabled and tabIndex implementation that ensures ARIA spec
13
- * for multiple scenarios of shorthand properties. Ensuring 1st rule of ARIA for cases
14
- * where no attribute addition is required.
15
- */
16
-
17
-
18
- const useARIAButton = (shorthand, options) => {
19
- var _a;
20
-
21
- const shorthandProps = react_utilities_1.resolveShorthand(shorthand, options);
22
- const {
23
- disabled,
24
- disabledFocusable,
25
- onClick,
26
- onKeyDown,
27
- onKeyUp,
28
- tabIndex
29
- } = shorthandProps || {};
30
- const onClickHandler = react_utilities_1.useEventCallback(ev => {
31
- if (disabled || disabledFocusable) {
32
- ev.preventDefault();
33
- ev.stopPropagation();
34
- } else {
35
- onClick === null || onClick === void 0 ? void 0 : onClick(ev);
36
- }
37
- });
38
- const onKeyDownHandler = react_utilities_1.useEventCallback(ev => {
39
- onKeyDown === null || onKeyDown === void 0 ? void 0 : onKeyDown(ev);
40
-
41
- if (ev.isDefaultPrevented()) {
42
- return;
43
- }
44
-
45
- const key = ev.key;
46
-
47
- if ((disabled || disabledFocusable) && (key === keyboard_keys_1.Enter || key === keyboard_keys_1.Space)) {
48
- ev.preventDefault();
49
- ev.stopPropagation();
50
- return;
51
- }
52
-
53
- if (key === keyboard_keys_1.Space) {
54
- ev.preventDefault();
55
- return;
56
- } // If enter is pressed, activate the button
57
- else if (key === keyboard_keys_1.Enter) {
58
- ev.preventDefault();
59
- ev.currentTarget.click();
60
- }
61
- });
62
- const onKeyupHandler = react_utilities_1.useEventCallback(ev => {
63
- onKeyUp === null || onKeyUp === void 0 ? void 0 : onKeyUp(ev);
64
-
65
- if (ev.isDefaultPrevented()) {
66
- return;
67
- }
68
-
69
- const key = ev.key;
70
-
71
- if ((disabled || disabledFocusable) && (key === keyboard_keys_1.Enter || key === keyboard_keys_1.Space)) {
72
- ev.preventDefault();
73
- ev.stopPropagation();
74
- return;
75
- }
76
-
77
- if (key === keyboard_keys_1.Space) {
78
- ev.preventDefault();
79
- ev.currentTarget.click();
80
- }
81
- });
82
-
83
- if (shorthandProps) {
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;
108
- }
109
-
110
- return shorthandProps;
111
- };
112
-
113
- exports.useARIAButton = useARIAButton;
114
- //# sourceMappingURL=useARIAButton.js.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D,CAYA;IAZA,KAaK;MACH,OAAO,cAAc,CAAC,QAAtB;MACA,cAAc,CAAC,eAAD,CAAd,GAAkC,QAAQ,IAAI,iBAA9C;MACC,cAA6C,CAAC,IAA9C,GAAqD,QAAQ,GAC1D,SAD0D,GAEzD,cAA6C,CAAC,IAFlD;MAGD,cAAc,CAAC,OAAf,GAAyB,cAAzB;MACA,cAAc,CAAC,SAAf,GAA2B,gBAA3B;MACA,cAAc,CAAC,OAAf,GAAyB,cAAzB;MACA,cAAc,CAAC,IAAf,GAAsB,CAAA,EAAA,GAAA,cAAc,CAAC,IAAf,MAAmB,IAAnB,IAAmB,EAAA,KAAA,KAAA,CAAnB,GAAmB,EAAnB,GAAuB,QAA7C;MACA,cAAc,CAAC,QAAf,GAA0B,QAAQ,IAAI,CAAC,iBAAb,GAAiC,SAAjC,GAA6C,QAAQ,KAAA,IAAR,IAAA,QAAQ,KAAA,KAAA,CAAR,GAAA,QAAA,GAAY,CAAnF;IACD,CA1BiB,CA4BlB;;;IACA,OAAO,cAAc,CAAC,iBAAtB;EACD;;EAED,OAAO,cAAP;AACD,CAhGM;;AAAM,OAAA,CAAA,aAAA,GAAa,aAAb","sourcesContent":["import { Enter, Space } from '@fluentui/keyboard-keys';\nimport { resolveShorthand, useEventCallback } from '@fluentui/react-utilities';\nimport type { ExtractSlotProps, ResolveShorthandFunction, Slot } from '@fluentui/react-utilities';\n\nexport type ARIAButtonSlotProps = ExtractSlotProps<Slot<'button', 'a'>> & {\n disabled?: boolean;\n disabledFocusable?: boolean;\n};\n\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 useARIAButton: ResolveShorthandFunction<ARIAButtonSlotProps> = (shorthand, options) => {\n const shorthandProps = resolveShorthand(shorthand, options);\n\n const { disabled, disabledFocusable, onClick, onKeyDown, onKeyUp, tabIndex } = (shorthandProps ||\n {}) as ARIAButtonSlotProps;\n\n const onClickHandler: ARIAButtonSlotProps['onClick'] = useEventCallback(ev => {\n if (disabled || disabledFocusable) {\n ev.preventDefault();\n ev.stopPropagation();\n } else {\n onClick?.(ev);\n }\n });\n\n const onKeyDownHandler: ARIAButtonSlotProps['onKeyDown'] = useEventCallback(ev => {\n onKeyDown?.(ev);\n\n if (ev.isDefaultPrevented()) {\n return;\n }\n\n const key = ev.key;\n\n if ((disabled || disabledFocusable) && (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 onKeyupHandler: ARIAButtonSlotProps['onKeyUp'] = useEventCallback(ev => {\n onKeyUp?.(ev);\n\n if (ev.isDefaultPrevented()) {\n return;\n }\n\n const key = ev.key;\n\n if ((disabled || disabledFocusable) && (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 (shorthandProps) {\n // If a <button> tag is to be rendered we just need to set disabled and aria-disabled correctly\n if (shorthandProps.as === 'button' || shorthandProps.as === undefined) {\n shorthandProps.disabled = disabled && !disabledFocusable;\n shorthandProps['aria-disabled'] = disabledFocusable ? true : undefined;\n\n // Undefine events if disabledFocusable is passed in\n if (disabledFocusable) {\n shorthandProps.onClick = undefined;\n shorthandProps.onKeyDown = undefined;\n shorthandProps.onKeyUp = undefined;\n }\n }\n\n // If an <a> tag is to be rendered we have to remove disabled and type, and set aria-disabled, role and tabIndex.\n else {\n delete shorthandProps.disabled;\n shorthandProps['aria-disabled'] = disabled || disabledFocusable;\n (shorthandProps as JSX.IntrinsicElements['a']).href = disabled\n ? undefined\n : (shorthandProps as JSX.IntrinsicElements['a']).href;\n shorthandProps.onClick = onClickHandler;\n shorthandProps.onKeyDown = onKeyDownHandler;\n shorthandProps.onKeyUp = onKeyupHandler;\n shorthandProps.role = shorthandProps.role ?? 'button';\n shorthandProps.tabIndex = disabled && !disabledFocusable ? undefined : tabIndex ?? 0;\n }\n\n // Remove non-DOM disabledFocusable prop\n delete shorthandProps.disabledFocusable;\n }\n\n return shorthandProps;\n};\n"],"sourceRoot":"../src/"}
@@ -1,10 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
-
7
- const tslib_1 = /*#__PURE__*/require("tslib");
8
-
9
- tslib_1.__exportStar(require("./mergeARIADisabled"), exports);
10
- //# sourceMappingURL=index.js.map
@@ -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/"}