@fluentui/react-aria 9.0.2 → 9.2.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.
Files changed (41) hide show
  1. package/CHANGELOG.json +88 -2
  2. package/CHANGELOG.md +32 -3
  3. package/dist/index.d.ts +71 -7
  4. package/lib/hooks/useARIAButton/index.js +4 -0
  5. package/lib/hooks/useARIAButton/index.js.map +1 -0
  6. package/lib/hooks/useARIAButton/types.js +2 -0
  7. package/lib/hooks/useARIAButton/types.js.map +1 -0
  8. package/lib/hooks/useARIAButton/useARIAButtonProps.js +131 -0
  9. package/lib/hooks/useARIAButton/useARIAButtonProps.js.map +1 -0
  10. package/lib/hooks/useARIAButton/useARIAButtonShorthand.js +20 -0
  11. package/lib/hooks/useARIAButton/useARIAButtonShorthand.js.map +1 -0
  12. package/lib/index.js +1 -2
  13. package/lib/index.js.map +1 -1
  14. package/lib-commonjs/hooks/useARIAButton/index.js +14 -0
  15. package/lib-commonjs/hooks/useARIAButton/index.js.map +1 -0
  16. package/lib-commonjs/hooks/useARIAButton/types.js +6 -0
  17. package/lib-commonjs/hooks/useARIAButton/types.js.map +1 -0
  18. package/lib-commonjs/hooks/useARIAButton/useARIAButtonProps.js +142 -0
  19. package/lib-commonjs/hooks/useARIAButton/useARIAButtonProps.js.map +1 -0
  20. package/lib-commonjs/hooks/useARIAButton/useARIAButtonShorthand.js +31 -0
  21. package/lib-commonjs/hooks/useARIAButton/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 -5
  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
package/CHANGELOG.json CHANGED
@@ -2,7 +2,93 @@
2
2
  "name": "@fluentui/react-aria",
3
3
  "entries": [
4
4
  {
5
- "date": "Thu, 14 Jul 2022 21:18:43 GMT",
5
+ "date": "Thu, 15 Sep 2022 09:45:09 GMT",
6
+ "tag": "@fluentui/react-aria_v9.2.0",
7
+ "version": "9.2.0",
8
+ "comments": {
9
+ "none": [
10
+ {
11
+ "author": "bernardo.sunderhus@gmail.com",
12
+ "package": "@fluentui/react-aria",
13
+ "commit": "bf151e71e0ffa5de5c44cc722e629cdeb7abdbb2",
14
+ "comment": "chore: re-organize useARIAButton into its own folder"
15
+ },
16
+ {
17
+ "author": "martinhochel@microsoft.com",
18
+ "package": "@fluentui/react-aria",
19
+ "commit": "e6cf183695d6d67a24e038c49a876224e5ed35e5",
20
+ "comment": "chore: update package scaffold"
21
+ }
22
+ ],
23
+ "patch": [
24
+ {
25
+ "author": "martinhochel@microsoft.com",
26
+ "package": "@fluentui/react-aria",
27
+ "commit": "16aa65dcae8f75c6a221225fd0eb43800650ac66",
28
+ "comment": "docs(react-aria): re-generate api.md"
29
+ },
30
+ {
31
+ "author": "bernardo.sunderhus@gmail.com",
32
+ "package": "@fluentui/react-aria",
33
+ "commit": "de08c96226ec5d425f705c22c5d94dbac5811eb6",
34
+ "comment": "chore(react-aria): improve internal typings"
35
+ },
36
+ {
37
+ "author": "bernardo.sunderhus@gmail.com",
38
+ "package": "@fluentui/react-aria",
39
+ "commit": "0547583ebcebe746110e5ef8d0599b0972b1f4c6",
40
+ "comment": "feat: upgrade typings on useARIAButtonProps to be more specific"
41
+ }
42
+ ],
43
+ "minor": [
44
+ {
45
+ "author": "bernardo.sunderhus@gmail.com",
46
+ "package": "@fluentui/react-aria",
47
+ "commit": "81191d9a45e629126a416e7202af3e241cd5e0fc",
48
+ "comment": "feat: add helper types to assist DOM element handling"
49
+ },
50
+ {
51
+ "author": "beachball",
52
+ "package": "@fluentui/react-aria",
53
+ "comment": "Bump @fluentui/react-utilities to v9.1.0",
54
+ "commit": "a33448fe4a0f4117686c378f80b893d1406d95a8"
55
+ }
56
+ ]
57
+ }
58
+ },
59
+ {
60
+ "date": "Wed, 03 Aug 2022 16:03:37 GMT",
61
+ "tag": "@fluentui/react-aria_v9.1.0",
62
+ "version": "9.1.0",
63
+ "comments": {
64
+ "none": [
65
+ {
66
+ "author": "lingfangao@hotmail.com",
67
+ "package": "@fluentui/react-aria",
68
+ "commit": "99cc385631d04a76ee10ebc143cb9fecd99640b6",
69
+ "comment": "chore: Add `prerelease` as disallowed changetype for 9.0.0 packages"
70
+ }
71
+ ],
72
+ "patch": [
73
+ {
74
+ "author": "bernardo.sunderhus@gmail.com",
75
+ "package": "@fluentui/react-aria",
76
+ "commit": "a0e1e0c2780ad6ba73aaeee1aa1525168a4d4045",
77
+ "comment": "feat: treats aria-disabled as disabled state on useARIAButtonProps"
78
+ }
79
+ ],
80
+ "minor": [
81
+ {
82
+ "author": "bernardo.sunderhus@gmail.com",
83
+ "package": "@fluentui/react-aria",
84
+ "commit": "1293f53f79ea1dc7429f77e174b2dfdaffa99558",
85
+ "comment": "chore: Splits useARIAButton into useARIAButtonProps and useARIAButtonShorthand."
86
+ }
87
+ ]
88
+ }
89
+ },
90
+ {
91
+ "date": "Thu, 14 Jul 2022 21:21:08 GMT",
6
92
  "tag": "@fluentui/react-aria_v9.0.2",
7
93
  "version": "9.0.2",
8
94
  "comments": {
@@ -17,7 +103,7 @@
17
103
  "author": "beachball",
18
104
  "package": "@fluentui/react-aria",
19
105
  "comment": "Bump @fluentui/react-utilities to v9.0.2",
20
- "commit": "802bc4e3730a88b0fc61b5bf42ef7fc6b6543fe2"
106
+ "commit": "79b513146194367544160f364b0a7dd749ed93e4"
21
107
  }
22
108
  ]
23
109
  }
package/CHANGELOG.md CHANGED
@@ -1,18 +1,47 @@
1
1
  # Change Log - @fluentui/react-aria
2
2
 
3
- This log was last generated on Thu, 14 Jul 2022 21:18:43 GMT and should not be manually modified.
3
+ This log was last generated on Thu, 15 Sep 2022 09:45:09 GMT and should not be manually modified.
4
4
 
5
5
  <!-- Start content -->
6
6
 
7
+ ## [9.2.0](https://github.com/microsoft/fluentui/tree/@fluentui/react-aria_v9.2.0)
8
+
9
+ Thu, 15 Sep 2022 09:45:09 GMT
10
+ [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-aria_v9.1.0..@fluentui/react-aria_v9.2.0)
11
+
12
+ ### Minor changes
13
+
14
+ - feat: add helper types to assist DOM element handling ([PR #24722](https://github.com/microsoft/fluentui/pull/24722) by bernardo.sunderhus@gmail.com)
15
+ - Bump @fluentui/react-utilities to v9.1.0 ([PR #24808](https://github.com/microsoft/fluentui/pull/24808) by beachball)
16
+
17
+ ### Patches
18
+
19
+ - docs(react-aria): re-generate api.md ([PR #23369](https://github.com/microsoft/fluentui/pull/23369) by martinhochel@microsoft.com)
20
+ - chore(react-aria): improve internal typings ([PR #24742](https://github.com/microsoft/fluentui/pull/24742) by bernardo.sunderhus@gmail.com)
21
+ - feat: upgrade typings on useARIAButtonProps to be more specific ([PR #24177](https://github.com/microsoft/fluentui/pull/24177) by bernardo.sunderhus@gmail.com)
22
+
23
+ ## [9.1.0](https://github.com/microsoft/fluentui/tree/@fluentui/react-aria_v9.1.0)
24
+
25
+ Wed, 03 Aug 2022 16:03:37 GMT
26
+ [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-aria_v9.0.2..@fluentui/react-aria_v9.1.0)
27
+
28
+ ### Minor changes
29
+
30
+ - chore: Splits useARIAButton into useARIAButtonProps and useARIAButtonShorthand. ([PR #24032](https://github.com/microsoft/fluentui/pull/24032) by bernardo.sunderhus@gmail.com)
31
+
32
+ ### Patches
33
+
34
+ - feat: treats aria-disabled as disabled state on useARIAButtonProps ([PR #24197](https://github.com/microsoft/fluentui/pull/24197) by bernardo.sunderhus@gmail.com)
35
+
7
36
  ## [9.0.2](https://github.com/microsoft/fluentui/tree/@fluentui/react-aria_v9.0.2)
8
37
 
9
- Thu, 14 Jul 2022 21:18:43 GMT
38
+ Thu, 14 Jul 2022 21:21:08 GMT
10
39
  [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-aria_v9.0.1..@fluentui/react-aria_v9.0.2)
11
40
 
12
41
  ### Patches
13
42
 
14
43
  - 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 #23920](https://github.com/microsoft/fluentui/pull/23920) by beachball)
44
+ - Bump @fluentui/react-utilities to v9.0.2 ([PR #23918](https://github.com/microsoft/fluentui/pull/23918) by beachball)
16
45
 
17
46
  ## [9.0.1](https://github.com/microsoft/fluentui/tree/@fluentui/react-aria_v9.0.1)
18
47
 
package/dist/index.d.ts CHANGED
@@ -1,26 +1,90 @@
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 ARIAButtonSlotProps = ExtractSlotProps<Slot<'button', 'a'>> & {
6
+ /**
7
+ * @internal
8
+ * Props that will be modified internally by `useARIAButtonProps` by each case.
9
+ * This typing is to ensure a well specified return value for `useARIAbButtonProps`
10
+ */
11
+ declare type ARIAButtonAlteredProps<Type extends ARIAButtonType> = (Type extends 'button' ? Pick<JSX.IntrinsicElements['button'], 'onClick' | 'onKeyDown' | 'onKeyUp' | 'disabled' | 'aria-disabled' | 'tabIndex'> : never) | (Type extends 'a' ? Pick<JSX.IntrinsicElements['a'], 'onClick' | 'onKeyDown' | 'onKeyUp' | 'aria-disabled' | 'tabIndex' | 'role' | 'href'> : never) | (Type extends 'div' ? Pick<JSX.IntrinsicElements['div'], 'onClick' | 'onKeyDown' | 'onKeyUp' | 'aria-disabled' | 'tabIndex' | 'role'> : never);
12
+
13
+ /**
14
+ * @internal
15
+ */
16
+ export declare type ARIAButtonElement<AlternateAs extends 'a' | 'div' = 'a' | 'div'> = HTMLButtonElement | (AlternateAs extends 'a' ? HTMLAnchorElement : never) | (AlternateAs extends 'div' ? HTMLDivElement : never);
17
+
18
+ /**
19
+ * @internal
20
+ */
21
+ export declare type ARIAButtonElementIntersection<AlternateAs extends 'a' | 'div' = 'a' | 'div'> = UnionToIntersection<ARIAButtonElement<AlternateAs>>;
22
+
23
+ /**
24
+ * Props expected by `useARIAButtonProps` hooks
25
+ */
26
+ export declare type ARIAButtonProps<Type extends ARIAButtonType = ARIAButtonType> = React_2.PropsWithRef<JSX.IntrinsicElements[Type]> & {
6
27
  disabled?: boolean;
28
+ /**
29
+ * When set, allows the button to be focusable even when it has been disabled.
30
+ * This is used in scenarios where it is important to keep a consistent tab order
31
+ * for screen reader and keyboard users. The primary example of this
32
+ * pattern is when the disabled button is in a menu or a commandbar and is seldom used for standalone buttons.
33
+ *
34
+ * @default false
35
+ */
7
36
  disabledFocusable?: boolean;
8
37
  };
9
38
 
39
+ /**
40
+ * Merge of props provided by the user and props provided internally.
41
+ */
42
+ export declare type ARIAButtonResultProps<Type extends ARIAButtonType, Props> = Props & UnionToIntersection<ARIAButtonAlteredProps<Type>>;
43
+
44
+ export declare type ARIAButtonSlotProps<AlternateAs extends 'a' | 'div' = 'a' | 'div'> = ExtractSlotProps<Slot<'button', AlternateAs>> & Pick<ARIAButtonProps<ARIAButtonType>, 'disabled' | 'disabledFocusable'>;
45
+
46
+ export declare type ARIAButtonType = 'button' | 'a' | 'div';
47
+
48
+ declare type UnionToIntersection<U> = (U extends unknown ? (x: U) => U : never) extends (x: infer I) => U ? I : never;
49
+
10
50
  /**
11
51
  * @internal
12
- * Merges disabled declaration with `aria-disabled`
52
+ *
53
+ * Button keyboard handling, role, disabled and tabIndex implementation that ensures ARIA spec
54
+ * for multiple scenarios of non native button elements. Ensuring 1st rule of ARIA for cases
55
+ * where no attribute addition is required.
56
+ *
57
+ * @param type - the proper scenario to be interpreted by the hook.
58
+ * 1. `button` - Minimal interference from the hook, as semantic button already supports most of the states
59
+ * 2. `a` or `div` - Proper keyboard/mouse handling plus other support to ensure ARIA behavior
60
+ * @param props - the props to be passed down the line to the desired element.
61
+ * This hook will encapsulate proper properties, such as `onClick`, `onKeyDown`, `onKeyUp`, etc,.
62
+ *
63
+ * @example
64
+ * ```tsx
65
+ * const buttonProps = useARIAButtonProps('a', {
66
+ * href: './some-route'
67
+ * onClick: () => console.log('this should run both on click and Space and Enter')
68
+ * })
69
+ *
70
+ * // ...
71
+ *
72
+ * return (
73
+ * <a {...buttonProps}>This anchor will behave as a proper button</a>
74
+ * )
75
+ * ```
13
76
  */
14
- export declare function mergeARIADisabled(shorthand: {
15
- 'aria-disabled'?: string | boolean;
16
- disabled?: boolean;
17
- }): boolean;
77
+ export declare function useARIAButtonProps<Type extends ARIAButtonType, Props extends ARIAButtonProps<Type>>(type?: Type, props?: Props): ARIAButtonResultProps<Type, Props>;
18
78
 
19
79
  /**
80
+ * @internal
81
+ *
82
+ * This function expects to receive a slot, if `as` property is not desired use `useARIAButtonProps` instead
83
+ *
20
84
  * Button keyboard handling, role, disabled and tabIndex implementation that ensures ARIA spec
21
85
  * for multiple scenarios of shorthand properties. Ensuring 1st rule of ARIA for cases
22
86
  * where no attribute addition is required.
23
87
  */
24
- export declare const useARIAButton: ResolveShorthandFunction<ARIAButtonSlotProps>;
88
+ export declare const useARIAButtonShorthand: ResolveShorthandFunction<ARIAButtonSlotProps>;
25
89
 
26
90
  export { }
@@ -0,0 +1,4 @@
1
+ export * from './useARIAButtonProps';
2
+ export * from './useARIAButtonShorthand';
3
+ export * from './types';
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"../src/","sources":["hooks/useARIAButton/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC;AACrC,cAAc,0BAA0B,CAAC;AACzC,cAAc,SAAS,CAAC","sourcesContent":["export * from './useARIAButtonProps';\nexport * from './useARIAButtonShorthand';\nexport * from './types';\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"../src/","sources":["hooks/useARIAButton/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { ExtractSlotProps, Slot } from '@fluentui/react-utilities';\nimport * as React from 'react';\n\ntype UnionToIntersection<U> = (U extends unknown ? (x: U) => U : never) extends (x: infer I) => U ? I : never;\n\nexport type ARIAButtonType = 'button' | 'a' | 'div';\n\n/**\n * @internal\n */\nexport type ARIAButtonElement<AlternateAs extends 'a' | 'div' = 'a' | 'div'> =\n | HTMLButtonElement\n | (AlternateAs extends 'a' ? HTMLAnchorElement : never)\n | (AlternateAs extends 'div' ? HTMLDivElement : never);\n\n/**\n * @internal\n */\nexport type ARIAButtonElementIntersection<AlternateAs extends 'a' | 'div' = 'a' | 'div'> = UnionToIntersection<\n ARIAButtonElement<AlternateAs>\n>;\n\n/**\n * Props expected by `useARIAButtonProps` hooks\n */\nexport type ARIAButtonProps<Type extends ARIAButtonType = ARIAButtonType> = React.PropsWithRef<\n JSX.IntrinsicElements[Type]\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 ARIAButtonSlotProps<AlternateAs extends 'a' | 'div' = 'a' | 'div'> = ExtractSlotProps<\n Slot<'button', AlternateAs>\n> &\n Pick<ARIAButtonProps<ARIAButtonType>, 'disabled' | 'disabledFocusable'>;\n\n/**\n * @internal\n * Props that will be modified internally by `useARIAButtonProps` by each case.\n * This typing is to ensure a well specified return value for `useARIAbButtonProps`\n */\nexport type ARIAButtonAlteredProps<Type extends ARIAButtonType> =\n | (Type extends 'button'\n ? Pick<\n JSX.IntrinsicElements['button'],\n 'onClick' | 'onKeyDown' | 'onKeyUp' | 'disabled' | 'aria-disabled' | 'tabIndex'\n >\n : never)\n | (Type extends 'a'\n ? Pick<\n JSX.IntrinsicElements['a'],\n 'onClick' | 'onKeyDown' | 'onKeyUp' | 'aria-disabled' | 'tabIndex' | 'role' | 'href'\n >\n : never)\n | (Type extends 'div'\n ? Pick<JSX.IntrinsicElements['div'], 'onClick' | 'onKeyDown' | 'onKeyUp' | 'aria-disabled' | 'tabIndex' | 'role'>\n : never);\n\n/**\n * Merge of props provided by the user and props provided internally.\n */\nexport type ARIAButtonResultProps<Type extends ARIAButtonType, Props> = Props &\n UnionToIntersection<ARIAButtonAlteredProps<Type>>;\n"]}
@@ -0,0 +1,131 @@
1
+ import { Enter, Space } from '@fluentui/keyboard-keys';
2
+ import { useEventCallback } from '@fluentui/react-utilities';
3
+ /**
4
+ * @internal
5
+ *
6
+ * Button keyboard handling, role, disabled and tabIndex implementation that ensures ARIA spec
7
+ * for multiple scenarios of non native button elements. Ensuring 1st rule of ARIA for cases
8
+ * where no attribute addition is required.
9
+ *
10
+ * @param type - the proper scenario to be interpreted by the hook.
11
+ * 1. `button` - Minimal interference from the hook, as semantic button already supports most of the states
12
+ * 2. `a` or `div` - Proper keyboard/mouse handling plus other support to ensure ARIA behavior
13
+ * @param props - the props to be passed down the line to the desired element.
14
+ * This hook will encapsulate proper properties, such as `onClick`, `onKeyDown`, `onKeyUp`, etc,.
15
+ *
16
+ * @example
17
+ * ```tsx
18
+ * const buttonProps = useARIAButtonProps('a', {
19
+ * href: './some-route'
20
+ * onClick: () => console.log('this should run both on click and Space and Enter')
21
+ * })
22
+ *
23
+ * // ...
24
+ *
25
+ * return (
26
+ * <a {...buttonProps}>This anchor will behave as a proper button</a>
27
+ * )
28
+ * ```
29
+ */
30
+
31
+ export function useARIAButtonProps(type, props) {
32
+ const {
33
+ disabled,
34
+ tabIndex,
35
+ disabledFocusable = false,
36
+ onClick,
37
+ onKeyDown,
38
+ onKeyUp,
39
+ ['aria-disabled']: ariaDisabled,
40
+ ...rest
41
+ } = props !== null && props !== void 0 ? props : {};
42
+ const normalizedARIADisabled = typeof ariaDisabled === 'string' ? ariaDisabled === 'true' : ariaDisabled;
43
+ const isDisabled = disabled || disabledFocusable || normalizedARIADisabled;
44
+ const handleClick = useEventCallback(ev => {
45
+ if (isDisabled) {
46
+ ev.preventDefault();
47
+ ev.stopPropagation();
48
+ } else {
49
+ onClick === null || onClick === void 0 ? void 0 : onClick(ev);
50
+ }
51
+ });
52
+ const handleKeyDown = useEventCallback(ev => {
53
+ onKeyDown === null || onKeyDown === void 0 ? void 0 : onKeyDown(ev);
54
+
55
+ if (ev.isDefaultPrevented()) {
56
+ return;
57
+ }
58
+
59
+ const key = ev.key;
60
+
61
+ if (isDisabled && (key === Enter || key === Space)) {
62
+ ev.preventDefault();
63
+ ev.stopPropagation();
64
+ return;
65
+ }
66
+
67
+ if (key === Space) {
68
+ ev.preventDefault();
69
+ return;
70
+ } // If enter is pressed, activate the button
71
+ else if (key === Enter) {
72
+ ev.preventDefault();
73
+ ev.currentTarget.click();
74
+ }
75
+ });
76
+ const handleKeyUp = useEventCallback(ev => {
77
+ onKeyUp === null || onKeyUp === void 0 ? void 0 : onKeyUp(ev);
78
+
79
+ if (ev.isDefaultPrevented()) {
80
+ return;
81
+ }
82
+
83
+ const key = ev.key;
84
+
85
+ if (isDisabled && (key === Enter || key === Space)) {
86
+ ev.preventDefault();
87
+ ev.stopPropagation();
88
+ return;
89
+ }
90
+
91
+ if (key === Space) {
92
+ ev.preventDefault();
93
+ ev.currentTarget.click();
94
+ }
95
+ }); // If a <button> tag is to be rendered we just need to set disabled and aria-disabled correctly
96
+
97
+ if (type === 'button' || type === undefined) {
98
+ return { ...rest,
99
+ tabIndex,
100
+ disabled: disabled && !disabledFocusable,
101
+ 'aria-disabled': disabledFocusable ? true : normalizedARIADisabled,
102
+ // onclick should still use internal handler to ensure prevention if disabled
103
+ // if disabledFocusable then there's no requirement for handlers as those events should not be propagated
104
+ onClick: disabledFocusable ? undefined : handleClick,
105
+ onKeyUp: disabledFocusable ? undefined : onKeyUp,
106
+ onKeyDown: disabledFocusable ? undefined : onKeyDown
107
+ };
108
+ } // If an <a> or <div> tag is to be rendered we have to remove disabled and type,
109
+ // and set aria-disabled, role and tabIndex.
110
+ else {
111
+ const resultProps = {
112
+ role: 'button',
113
+ ...rest,
114
+ // If it's not a <button> than listeners are required even with disabledFocusable
115
+ // Since you cannot assure the default behavior of the element
116
+ // E.g: <a> will redirect on click
117
+ onClick: handleClick,
118
+ onKeyUp: handleKeyUp,
119
+ onKeyDown: handleKeyDown,
120
+ 'aria-disabled': disabled || disabledFocusable || normalizedARIADisabled,
121
+ tabIndex: disabled && !disabledFocusable ? undefined : tabIndex !== null && tabIndex !== void 0 ? tabIndex : 0
122
+ };
123
+
124
+ if (type === 'a' && isDisabled) {
125
+ resultProps.href = undefined;
126
+ }
127
+
128
+ return resultProps;
129
+ }
130
+ }
131
+ //# sourceMappingURL=useARIAButtonProps.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["hooks/useARIAButton/useARIAButtonProps.ts"],"names":[],"mappings":"AAAA,SAAS,KAAT,EAAgB,KAAhB,QAA6B,yBAA7B;AACA,SAAS,gBAAT,QAAiC,2BAAjC;AAIA;;;;;;;;;;;;;;;;;;;;;;;;;;AA0BG;;AACH,OAAM,SAAU,kBAAV,CACJ,IADI,EAEJ,KAFI,E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A6C,QAAQ,KAAA,IAAR,IAAA,QAAQ,KAAA,KAAA,CAAR,GAAA,QAAA,GAAY;IAVjD,CAApB;;IAaA,IAAI,IAAI,KAAK,GAAT,IAAgB,UAApB,EAAgC;MAC7B,WAAiD,CAAC,IAAlD,GAAyD,SAAzD;IACF;;IAED,OAAO,WAAP;EACD;AACF","sourcesContent":["import { Enter, Space } from '@fluentui/keyboard-keys';\nimport { useEventCallback } 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 {\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 = 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 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 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 ...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 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":"../src/"}
@@ -0,0 +1,20 @@
1
+ import { resolveShorthand } from '@fluentui/react-utilities';
2
+ import { useARIAButtonProps } from './useARIAButtonProps';
3
+ /**
4
+ * @internal
5
+ *
6
+ * This function expects to receive a slot, if `as` property is not desired use `useARIAButtonProps` instead
7
+ *
8
+ * Button keyboard handling, role, disabled and tabIndex implementation that ensures ARIA spec
9
+ * for multiple scenarios of shorthand properties. Ensuring 1st rule of ARIA for cases
10
+ * where no attribute addition is required.
11
+ */
12
+
13
+ export const useARIAButtonShorthand = (slot, options) => {
14
+ var _a;
15
+
16
+ const shorthand = resolveShorthand(slot, options);
17
+ const shorthandARIAButton = useARIAButtonProps((_a = shorthand === null || shorthand === void 0 ? void 0 : shorthand.as) !== null && _a !== void 0 ? _a : 'button', shorthand);
18
+ return shorthand && shorthandARIAButton;
19
+ };
20
+ //# sourceMappingURL=useARIAButtonShorthand.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["hooks/useARIAButton/useARIAButtonShorthand.ts"],"names":[],"mappings":"AAAA,SAAS,gBAAT,QAAiC,2BAAjC;AACA,SAAS,kBAAT,QAAmC,sBAAnC;AAIA;;;;;;;;AAQG;;AACH,OAAO,MAAM,sBAAsB,GAAkD,CAAC,IAAD,EAAO,OAAP,KAAkB;;;EACrG,MAAM,SAAS,GAAG,gBAAgB,CAAC,IAAD,EAAO,OAAP,CAAlC;EACA,MAAM,mBAAmB,GAAG,kBAAkB,CAAkC,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,QAAnD,EAA6D,SAA7D,CAA9C;EACA,OAAO,SAAS,IAAI,mBAApB;AACD,CAJM","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":"../src/"}
package/lib/index.js CHANGED
@@ -1,3 +1,2 @@
1
- export { useARIAButton } from './hooks/index';
2
- export { mergeARIADisabled } from './utils/index';
1
+ export { useARIAButtonShorthand, useARIAButtonProps } from './hooks/useARIAButton/index';
3
2
  //# sourceMappingURL=index.js.map
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"../src/","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAE9C,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC","sourcesContent":["export { useARIAButton } from './hooks/index';\nexport type { ARIAButtonSlotProps } from './hooks/index';\nexport { mergeARIADisabled } from './utils/index';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"../src/","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC","sourcesContent":["export { useARIAButtonShorthand, useARIAButtonProps } from './hooks/useARIAButton/index';\nexport type {\n ARIAButtonSlotProps,\n ARIAButtonProps,\n ARIAButtonResultProps,\n ARIAButtonType,\n ARIAButtonElement,\n ARIAButtonElementIntersection,\n} from './hooks/useARIAButton/index';\n"]}
@@ -0,0 +1,14 @@
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("./useARIAButtonProps"), exports);
10
+
11
+ tslib_1.__exportStar(require("./useARIAButtonShorthand"), exports);
12
+
13
+ tslib_1.__exportStar(require("./types"), exports);
14
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["hooks/useARIAButton/index.ts"],"names":[],"mappings":";;;;;;;;AAAA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,sBAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,0BAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,SAAA,CAAA,EAAA,OAAA","sourcesContent":["export * from './useARIAButtonProps';\nexport * from './useARIAButtonShorthand';\nexport * from './types';\n"],"sourceRoot":"../src/"}
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","sourceRoot":"../src/"}
@@ -0,0 +1,142 @@
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
+ tabIndex,
44
+ disabledFocusable = false,
45
+ onClick,
46
+ onKeyDown,
47
+ onKeyUp,
48
+ ['aria-disabled']: ariaDisabled,
49
+ ...rest
50
+ } = props !== null && props !== void 0 ? props : {};
51
+ const normalizedARIADisabled = typeof ariaDisabled === 'string' ? ariaDisabled === 'true' : ariaDisabled;
52
+ const isDisabled = disabled || disabledFocusable || normalizedARIADisabled;
53
+ const handleClick = react_utilities_1.useEventCallback(ev => {
54
+ if (isDisabled) {
55
+ ev.preventDefault();
56
+ ev.stopPropagation();
57
+ } else {
58
+ onClick === null || onClick === void 0 ? void 0 : onClick(ev);
59
+ }
60
+ });
61
+ const handleKeyDown = react_utilities_1.useEventCallback(ev => {
62
+ onKeyDown === null || onKeyDown === void 0 ? void 0 : onKeyDown(ev);
63
+
64
+ if (ev.isDefaultPrevented()) {
65
+ return;
66
+ }
67
+
68
+ const key = ev.key;
69
+
70
+ if (isDisabled && (key === keyboard_keys_1.Enter || key === keyboard_keys_1.Space)) {
71
+ ev.preventDefault();
72
+ ev.stopPropagation();
73
+ return;
74
+ }
75
+
76
+ if (key === keyboard_keys_1.Space) {
77
+ ev.preventDefault();
78
+ return;
79
+ } // If enter is pressed, activate the button
80
+ else if (key === keyboard_keys_1.Enter) {
81
+ ev.preventDefault();
82
+ ev.currentTarget.click();
83
+ }
84
+ });
85
+ const handleKeyUp = react_utilities_1.useEventCallback(ev => {
86
+ onKeyUp === null || onKeyUp === void 0 ? void 0 : onKeyUp(ev);
87
+
88
+ if (ev.isDefaultPrevented()) {
89
+ return;
90
+ }
91
+
92
+ const key = ev.key;
93
+
94
+ if (isDisabled && (key === keyboard_keys_1.Enter || key === keyboard_keys_1.Space)) {
95
+ ev.preventDefault();
96
+ ev.stopPropagation();
97
+ return;
98
+ }
99
+
100
+ if (key === keyboard_keys_1.Space) {
101
+ ev.preventDefault();
102
+ ev.currentTarget.click();
103
+ }
104
+ }); // If a <button> tag is to be rendered we just need to set disabled and aria-disabled correctly
105
+
106
+ if (type === 'button' || type === undefined) {
107
+ return { ...rest,
108
+ tabIndex,
109
+ disabled: disabled && !disabledFocusable,
110
+ 'aria-disabled': disabledFocusable ? true : normalizedARIADisabled,
111
+ // onclick should still use internal handler to ensure prevention if disabled
112
+ // if disabledFocusable then there's no requirement for handlers as those events should not be propagated
113
+ onClick: disabledFocusable ? undefined : handleClick,
114
+ onKeyUp: disabledFocusable ? undefined : onKeyUp,
115
+ onKeyDown: disabledFocusable ? undefined : onKeyDown
116
+ };
117
+ } // If an <a> or <div> tag is to be rendered we have to remove disabled and type,
118
+ // and set aria-disabled, role and tabIndex.
119
+ else {
120
+ const resultProps = {
121
+ role: 'button',
122
+ ...rest,
123
+ // If it's not a <button> than listeners are required even with disabledFocusable
124
+ // Since you cannot assure the default behavior of the element
125
+ // E.g: <a> will redirect on click
126
+ onClick: handleClick,
127
+ onKeyUp: handleKeyUp,
128
+ onKeyDown: handleKeyDown,
129
+ 'aria-disabled': disabled || disabledFocusable || normalizedARIADisabled,
130
+ tabIndex: disabled && !disabledFocusable ? undefined : tabIndex !== null && tabIndex !== void 0 ? tabIndex : 0
131
+ };
132
+
133
+ if (type === 'a' && isDisabled) {
134
+ resultProps.href = undefined;
135
+ }
136
+
137
+ return resultProps;
138
+ }
139
+ }
140
+
141
+ exports.useARIAButtonProps = useARIAButtonProps;
142
+ //# sourceMappingURL=useARIAButtonProps.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["hooks/useARIAButton/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;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,sBAApD;EAEA,MAAM,WAAW,GAAG,iBAAA,CAAA,gBAAA,CAAkB,EAAD,IAAwD;IAC3F,IAAI,UAAJ,EAAgB;MACd,EAAE,CAAC,cAAH;MACA,EAAE,CAAC,eAAH;IACD,CAHD,MAGO;MACL,OAAO,KAAA,IAAP,IAAA,OAAO,KAAA,KAAA,CAAP,GAAO,KAAA,CAAP,GAAA,OAAO,CAAG,EAAH,CAAP;IACD;EACF,CAPmB,CAApB;EASA,MAAM,aAAa,GAAG,iBAAA,CAAA,gBAAA,CAAkB,EAAD,IAA2D;IAChG,SA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AAlC,EAA6C;IAC3C,OAAO,EACL,GAAG,IADE;MAEL,QAFK;MAGL,QAAQ,EAAE,QAAQ,IAAI,CAAC,iBAHlB;MAIL,iBAAiB,iBAAiB,GAAG,IAAH,GAAU,sBAJvC;MAKL;MACA;MACA,OAAO,EAAE,iBAAiB,GAAG,SAAH,GAAe,WAPpC;MAQL,OAAO,EAAE,iBAAiB,GAAG,SAAH,GAAe,OARpC;MASL,SAAS,EAAE,iBAAiB,GAAG,SAAH,GAAe;IATtC,CAAP;EAWD,CAZD,CAcA;EACA;EAfA,KAgBK;IACH,MAAM,WAAW,GAAG;MAClB,IAAI,EAAE,QADY;MAElB,GAAG,IAFe;MAGlB;MACA;MACA;MACA,OAAO,EAAE,WANS;MAOlB,OAAO,EAAE,WAPS;MAQlB,SAAS,EAAE,aARO;MASlB,iBAAiB,QAAQ,IAAI,iBAAZ,IAAiC,sBAThC;MAUlB,QAAQ,EAAE,QAAQ,IAAI,CAAC,iBAAb,GAAiC,SAAjC,GAA6C,QAAQ,KAAA,IAAR,IAAA,QAAQ,KAAA,KAAA,CAAR,GAAA,QAAA,GAAY;IAVjD,CAApB;;IAaA,IAAI,IAAI,KAAK,GAAT,IAAgB,UAApB,EAAgC;MAC7B,WAAiD,CAAC,IAAlD,GAAyD,SAAzD;IACF;;IAED,OAAO,WAAP;EACD;AACF;;AAjHD,OAAA,CAAA,kBAAA,GAAA,kBAAA","sourcesContent":["import { Enter, Space } from '@fluentui/keyboard-keys';\nimport { useEventCallback } 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 {\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 = 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 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 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 ...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 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":"../src/"}
@@ -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":["hooks/useARIAButton/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":"../src/"}
@@ -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("./hooks/useARIAButton/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":["index.ts"],"names":[],"mappings":";;;;;;;AAAA,IAAA,OAAA,gBAAA,OAAA,CAAA,6BAAA,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/useARIAButton/index';\nexport type {\n ARIAButtonSlotProps,\n ARIAButtonProps,\n ARIAButtonResultProps,\n ARIAButtonType,\n ARIAButtonElement,\n ARIAButtonElementIntersection,\n} from './hooks/useARIAButton/index';\n"],"sourceRoot":"../src/"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluentui/react-aria",
3
- "version": "9.0.2",
3
+ "version": "9.2.0",
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": {
@@ -31,7 +31,7 @@
31
31
  },
32
32
  "dependencies": {
33
33
  "@fluentui/keyboard-keys": "^9.0.0",
34
- "@fluentui/react-utilities": "^9.0.2",
34
+ "@fluentui/react-utilities": "^9.1.0",
35
35
  "tslib": "^2.1.0"
36
36
  },
37
37
  "peerDependencies": {
@@ -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": {
@@ -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,MAAM,aAAa,GAAkD,CAAC,SAAD,EAAY,OAAZ,KAAuB;;;EACjG,MAAM,cAAc,GAAG,gBAAgB,CAAC,SAAD,EAAY,OAAZ,CAAvC;EAEA,MAAM;IAAE,QAAF;IAAY,iBAAZ;IAA+B,OAA/B;IAAwC,SAAxC;IAAmD,OAAnD;IAA4D;EAA5D,IAA0E,cAAc,IAC5F,EADF;EAGA,MAAM,cAAc,GAAmC,gBAAgB,CAAC,EAAE,IAAG;IAC3E,IAAI,QAAQ,IAAI,iBAAhB,EAAmC;MACjC,EAAE,CAAC,cAAH;MACA,EAAE,CAAC,eAAH;IACD,CAHD,MAGO;MACL,OAAO,KAAA,IAAP,IAAA,OAAO,KAAA,KAAA,CAAP,G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F,CAnBsE,CAAvE;;EAqBA,IAAI,cAAJ,EAAoB;IAClB;IACA,IAAI,cAAc,CAAC,EAAf,KAAsB,QAAtB,IAAkC,cAAc,CAAC,EAAf,KAAsB,SAA5D,EAAuE;MACrE,cAAc,CAAC,QAAf,GAA0B,QAAQ,IAAI,CAAC,iBAAvC;MACA,cAAc,CAAC,eAAD,CAAd,GAAkC,iBAAiB,GAAG,IAAH,GAAU,SAA7D,CAFqE,CAIrE;;MACA,IAAI,iBAAJ,EAAuB;QACrB,cAAc,CAAC,OAAf,GAAyB,SAAzB;QACA,cAAc,CAAC,SAAf,GAA2B,SAA3B;QACA,cAAc,CAAC,OAAf,GAAyB,SAAzB;MACD;IACF,CAVD,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","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.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["hooks/useARIAButton.ts"],"names":[],"mappings":";;;;;;;AAAA,MAAA,eAAA,gBAAA,OAAA,CAAA,yBAAA,CAAA;;AACA,MAAA,iBAAA,gBAAA,OAAA,CAAA,2BAAA,CAAA;AAQA;;;;AAIG;;;AACI,MAAM,aAAa,GAAkD,CAAC,SAAD,EAAY,OAAZ,KAAuB;;;EACjG,MAAM,cAAc,GAAG,iBAAA,CAAA,gBAAA,CAAiB,SAAjB,EAA4B,OAA5B,CAAvB;EAEA,MAAM;IAAE,QAAF;IAAY,iBAAZ;IAA+B,OAA/B;IAAwC,SAAxC;IAAmD,OAAnD;IAA4D;EAA5D,IAA0E,cAAc,IAC5F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,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/"}