@fluentui/react-aria 9.1.0 → 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 (31) hide show
  1. package/CHANGELOG.json +56 -1
  2. package/CHANGELOG.md +18 -2
  3. package/dist/index.d.ts +53 -4
  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.js → useARIAButton/useARIAButtonProps.js} +26 -23
  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 -1
  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.js → useARIAButton/useARIAButtonProps.js} +26 -25
  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 +1 -1
  23. package/lib-commonjs/index.js.map +1 -1
  24. package/package.json +4 -4
  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.map +0 -1
  29. package/lib-commonjs/hooks/index.js +0 -10
  30. package/lib-commonjs/hooks/index.js.map +0 -1
  31. package/lib-commonjs/hooks/useARIAButton.js.map +0 -1
package/CHANGELOG.json CHANGED
@@ -2,7 +2,62 @@
2
2
  "name": "@fluentui/react-aria",
3
3
  "entries": [
4
4
  {
5
- "date": "Wed, 03 Aug 2022 16:00:04 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",
6
61
  "tag": "@fluentui/react-aria_v9.1.0",
7
62
  "version": "9.1.0",
8
63
  "comments": {
package/CHANGELOG.md CHANGED
@@ -1,12 +1,28 @@
1
1
  # Change Log - @fluentui/react-aria
2
2
 
3
- This log was last generated on Wed, 03 Aug 2022 16:00:04 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
+
7
23
  ## [9.1.0](https://github.com/microsoft/fluentui/tree/@fluentui/react-aria_v9.1.0)
8
24
 
9
- Wed, 03 Aug 2022 16:00:04 GMT
25
+ Wed, 03 Aug 2022 16:03:37 GMT
10
26
  [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-aria_v9.0.2..@fluentui/react-aria_v9.1.0)
11
27
 
12
28
  ### Minor changes
package/dist/index.d.ts CHANGED
@@ -3,9 +3,27 @@ import * as React_2 from 'react';
3
3
  import type { ResolveShorthandFunction } from '@fluentui/react-utilities';
4
4
  import type { Slot } from '@fluentui/react-utilities';
5
5
 
6
- export declare type ARIAButtonProps<Type extends 'a' | 'div' | 'button' = 'a' | 'div' | 'button'> = React_2.PropsWithRef<JSX.IntrinsicElements[Type]> & Pick<ARIAButtonSlotProps, 'disabled' | 'disabledFocusable'>;
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>>;
7
22
 
8
- export declare type ARIAButtonSlotProps<AlternateAs extends 'a' | 'div' = 'a' | 'div'> = ExtractSlotProps<Slot<'button', AlternateAs>> & {
23
+ /**
24
+ * Props expected by `useARIAButtonProps` hooks
25
+ */
26
+ export declare type ARIAButtonProps<Type extends ARIAButtonType = ARIAButtonType> = React_2.PropsWithRef<JSX.IntrinsicElements[Type]> & {
9
27
  disabled?: boolean;
10
28
  /**
11
29
  * When set, allows the button to be focusable even when it has been disabled.
@@ -18,14 +36,45 @@ export declare type ARIAButtonSlotProps<AlternateAs extends 'a' | 'div' = 'a' |
18
36
  disabledFocusable?: boolean;
19
37
  };
20
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
+
21
50
  /**
22
51
  * @internal
23
52
  *
24
53
  * Button keyboard handling, role, disabled and tabIndex implementation that ensures ARIA spec
25
- * for multiple scenarios of shorthand properties. Ensuring 1st rule of ARIA for cases
54
+ * for multiple scenarios of non native button elements. Ensuring 1st rule of ARIA for cases
26
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
+ * ```
27
76
  */
28
- export declare function useARIAButtonProps<Type extends NonNullable<ARIAButtonSlotProps['as']>>(type?: Type, props?: ARIAButtonProps): React_2.PropsWithRef<JSX.IntrinsicElements[Type]>;
77
+ export declare function useARIAButtonProps<Type extends ARIAButtonType, Props extends ARIAButtonProps<Type>>(type?: Type, props?: Props): ARIAButtonResultProps<Type, Props>;
29
78
 
30
79
  /**
31
80
  * @internal
@@ -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"]}
@@ -1,11 +1,31 @@
1
1
  import { Enter, Space } from '@fluentui/keyboard-keys';
2
- import { resolveShorthand, useEventCallback } from '@fluentui/react-utilities';
2
+ import { useEventCallback } from '@fluentui/react-utilities';
3
3
  /**
4
4
  * @internal
5
5
  *
6
6
  * Button keyboard handling, role, disabled and tabIndex implementation that ensures ARIA spec
7
- * for multiple scenarios of shorthand properties. Ensuring 1st rule of ARIA for cases
7
+ * for multiple scenarios of non native button elements. Ensuring 1st rule of ARIA for cases
8
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
+ * ```
9
29
  */
10
30
 
11
31
  export function useARIAButtonProps(type, props) {
@@ -88,7 +108,7 @@ export function useARIAButtonProps(type, props) {
88
108
  } // If an <a> or <div> tag is to be rendered we have to remove disabled and type,
89
109
  // and set aria-disabled, role and tabIndex.
90
110
  else {
91
- const nextProps = {
111
+ const resultProps = {
92
112
  role: 'button',
93
113
  ...rest,
94
114
  // If it's not a <button> than listeners are required even with disabledFocusable
@@ -102,27 +122,10 @@ export function useARIAButtonProps(type, props) {
102
122
  };
103
123
 
104
124
  if (type === 'a' && isDisabled) {
105
- nextProps.href = undefined;
125
+ resultProps.href = undefined;
106
126
  }
107
127
 
108
- return nextProps;
128
+ return resultProps;
109
129
  }
110
130
  }
111
- /**
112
- * @internal
113
- *
114
- * This function expects to receive a slot, if `as` property is not desired use `useARIAButtonProps` instead
115
- *
116
- * Button keyboard handling, role, disabled and tabIndex implementation that ensures ARIA spec
117
- * for multiple scenarios of shorthand properties. Ensuring 1st rule of ARIA for cases
118
- * where no attribute addition is required.
119
- */
120
-
121
- export const useARIAButtonShorthand = (slot, options) => {
122
- var _a;
123
-
124
- const shorthand = resolveShorthand(slot, options);
125
- const shorthandARIAButton = useARIAButtonProps((_a = shorthand === null || shorthand === void 0 ? void 0 : shorthand.as) !== null && _a !== void 0 ? _a : 'button', shorthand);
126
- return shorthand && shorthandARIAButton;
127
- };
128
- //# sourceMappingURL=useARIAButton.js.map
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,EAES;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,gBAAgB,CAAE,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,CAPmC,CAApC;EASA,MAAM,aAAa,GAAG,gBAAgB,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AE,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","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,2 +1,2 @@
1
- export { useARIAButtonShorthand, useARIAButtonProps } from './hooks/index';
1
+ export { useARIAButtonShorthand, useARIAButtonProps } from './hooks/useARIAButton/index';
2
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,sBAAsB,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC","sourcesContent":["export { useARIAButtonShorthand, useARIAButtonProps } from './hooks/index';\nexport type { ARIAButtonSlotProps, ARIAButtonProps } from './hooks/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/"}
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.useARIAButtonShorthand = exports.useARIAButtonProps = void 0;
6
+ exports.useARIAButtonProps = void 0;
7
7
 
8
8
  const keyboard_keys_1 = /*#__PURE__*/require("@fluentui/keyboard-keys");
9
9
 
@@ -12,8 +12,28 @@ const react_utilities_1 = /*#__PURE__*/require("@fluentui/react-utilities");
12
12
  * @internal
13
13
  *
14
14
  * Button keyboard handling, role, disabled and tabIndex implementation that ensures ARIA spec
15
- * for multiple scenarios of shorthand properties. Ensuring 1st rule of ARIA for cases
15
+ * for multiple scenarios of non native button elements. Ensuring 1st rule of ARIA for cases
16
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
+ * ```
17
37
  */
18
38
 
19
39
 
@@ -97,7 +117,7 @@ function useARIAButtonProps(type, props) {
97
117
  } // If an <a> or <div> tag is to be rendered we have to remove disabled and type,
98
118
  // and set aria-disabled, role and tabIndex.
99
119
  else {
100
- const nextProps = {
120
+ const resultProps = {
101
121
  role: 'button',
102
122
  ...rest,
103
123
  // If it's not a <button> than listeners are required even with disabledFocusable
@@ -111,31 +131,12 @@ function useARIAButtonProps(type, props) {
111
131
  };
112
132
 
113
133
  if (type === 'a' && isDisabled) {
114
- nextProps.href = undefined;
134
+ resultProps.href = undefined;
115
135
  }
116
136
 
117
- return nextProps;
137
+ return resultProps;
118
138
  }
119
139
  }
120
140
 
121
141
  exports.useARIAButtonProps = useARIAButtonProps;
122
- /**
123
- * @internal
124
- *
125
- * This function expects to receive a slot, if `as` property is not desired use `useARIAButtonProps` instead
126
- *
127
- * Button keyboard handling, role, disabled and tabIndex implementation that ensures ARIA spec
128
- * for multiple scenarios of shorthand properties. Ensuring 1st rule of ARIA for cases
129
- * where no attribute addition is required.
130
- */
131
-
132
- const useARIAButtonShorthand = (slot, options) => {
133
- var _a;
134
-
135
- const shorthand = react_utilities_1.resolveShorthand(slot, options);
136
- const shorthandARIAButton = useARIAButtonProps((_a = shorthand === null || shorthand === void 0 ? void 0 : shorthand.as) !== null && _a !== void 0 ? _a : 'button', shorthand);
137
- return shorthand && shorthandARIAButton;
138
- };
139
-
140
- exports.useARIAButtonShorthand = useARIAButtonShorthand;
141
- //# sourceMappingURL=useARIAButton.js.map
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;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AAQ,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/"}
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
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
10
  Object.defineProperty(exports, "useARIAButtonShorthand", {
11
11
  enumerable: true,
@@ -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,wBAAA,EAAA;EAAA,UAAA,EAAA,IAAA;EAAA,GAAA,EAAA,YAAA;IAAA,OAAA,OAAA,CAAA,sBAAA;EAAsB;AAAtB,CAAA;AAAwB,MAAA,CAAA,cAAA,CAAA,OAAA,EAAA,oBAAA,EAAA;EAAA,UAAA,EAAA,IAAA;EAAA,GAAA,EAAA,YAAA;IAAA,OAAA,OAAA,CAAA,kBAAA;EAAkB;AAAlB,CAAA","sourcesContent":["export { useARIAButtonShorthand, useARIAButtonProps } from './hooks/index';\nexport type { ARIAButtonSlotProps, ARIAButtonProps } from './hooks/index';\n"],"sourceRoot":"../src/"}
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.1.0",
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": {
@@ -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 +0,0 @@
1
- {"version":3,"sources":["hooks/useARIAButton.ts"],"names":[],"mappings":"AAAA,SAAS,KAAT,EAAgB,KAAhB,Q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MAQhB,SAAS,EAAE,aARK;MAShB,iBAAiB,QAAQ,IAAI,iBAAZ,IAAiC,sBATlC;MAUhB,QAAQ,EAAE,QAAQ,IAAI,CAAC,iBAAb,GAAiC,SAAjC,GAA6C,QAAQ,KAAA,IAAR,IAAA,QAAQ,KAAA,KAAA,CAAR,GAAA,QAAA,GAAY;IAVnD,CAAlB;;IAaA,IAAI,IAAI,KAAK,GAAT,IAAgB,UAApB,EAAgC;MAC7B,SAAwC,CAAC,IAAzC,GAAgD,SAAhD;IACF;;IAED,OAAO,SAAP;EACD;AACF;AAED;;;;;;;;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,CAAC,CAAA,EAAA,GAAA,SAAS,KAAA,IAAT,IAAA,SAAS,KAAA,KAAA,CAAT,GAAS,KAAA,CAAT,GAAA,SAAS,CAAE,EAAX,MAAa,IAAb,IAAa,EAAA,KAAA,KAAA,CAAb,GAAa,EAAb,GAAiB,QAAlB,EAA4B,SAA5B,CAA9C;EACA,OAAO,SAAS,IAAI,mBAApB;AACD,CAJM","sourcesContent":["import { Enter, Space } from '@fluentui/keyboard-keys';\nimport { resolveShorthand, useEventCallback } from '@fluentui/react-utilities';\nimport type { ExtractSlotProps, ResolveShorthandFunction, Slot } from '@fluentui/react-utilities';\nimport * as React from 'react';\n\nexport type ARIAButtonSlotProps<AlternateAs extends 'a' | 'div' = 'a' | 'div'> = ExtractSlotProps<\n Slot<'button', AlternateAs>\n> & {\n disabled?: boolean;\n /**\n * When set, allows the button to be focusable even when it has been disabled.\n * This is used in scenarios where it is important to keep a consistent tab order\n * for screen reader and keyboard users. The primary example of this\n * pattern is when the disabled button is in a menu or a commandbar and is seldom used for standalone buttons.\n *\n * @default false\n */\n disabledFocusable?: boolean;\n};\n\nexport type ARIAButtonProps<Type extends 'a' | 'div' | 'button' = 'a' | 'div' | 'button'> = React.PropsWithRef<\n JSX.IntrinsicElements[Type]\n> &\n Pick<ARIAButtonSlotProps, 'disabled' | 'disabledFocusable'>;\n\n/**\n * @internal\n *\n * Button keyboard handling, role, disabled and tabIndex implementation that ensures ARIA spec\n * for multiple scenarios of shorthand properties. Ensuring 1st rule of ARIA for cases\n * where no attribute addition is required.\n */\nexport function useARIAButtonProps<Type extends NonNullable<ARIAButtonSlotProps['as']>>(\n type?: Type,\n props?: ARIAButtonProps,\n): React.PropsWithRef<JSX.IntrinsicElements[Type]> {\n const {\n disabled,\n tabIndex,\n disabledFocusable = false,\n onClick,\n onKeyDown,\n onKeyUp,\n ['aria-disabled']: ariaDisabled,\n ...rest\n } = props ?? {};\n\n const normalizedARIADisabled = typeof ariaDisabled === 'string' ? ariaDisabled === 'true' : ariaDisabled;\n\n const isDisabled = disabled || disabledFocusable || normalizedARIADisabled;\n\n const handleClick: ARIAButtonProps['onClick'] = useEventCallback(ev => {\n if (isDisabled) {\n ev.preventDefault();\n ev.stopPropagation();\n } else {\n onClick?.(ev);\n }\n });\n\n const handleKeyDown: ARIAButtonProps['onKeyDown'] = useEventCallback(ev => {\n onKeyDown?.(ev);\n\n if (ev.isDefaultPrevented()) {\n return;\n }\n\n const key = ev.key;\n\n if (isDisabled && (key === Enter || key === Space)) {\n ev.preventDefault();\n ev.stopPropagation();\n return;\n }\n\n if (key === Space) {\n ev.preventDefault();\n return;\n }\n\n // If enter is pressed, activate the button\n else if (key === Enter) {\n ev.preventDefault();\n ev.currentTarget.click();\n }\n });\n\n const handleKeyUp: ARIAButtonProps['onKeyUp'] = useEventCallback(ev => {\n onKeyUp?.(ev);\n\n if (ev.isDefaultPrevented()) {\n return;\n }\n\n const key = ev.key;\n\n if (isDisabled && (key === Enter || key === Space)) {\n ev.preventDefault();\n ev.stopPropagation();\n return;\n }\n\n if (key === Space) {\n ev.preventDefault();\n ev.currentTarget.click();\n }\n });\n\n // If a <button> tag is to be rendered we just need to set disabled and aria-disabled correctly\n if (type === 'button' || type === undefined) {\n return {\n ...rest,\n tabIndex,\n disabled: disabled && !disabledFocusable,\n 'aria-disabled': disabledFocusable ? true : normalizedARIADisabled,\n // onclick should still use internal handler to ensure prevention if disabled\n // if disabledFocusable then there's no requirement for handlers as those events should not be propagated\n onClick: disabledFocusable ? undefined : handleClick,\n onKeyUp: disabledFocusable ? undefined : onKeyUp,\n onKeyDown: disabledFocusable ? undefined : onKeyDown,\n } as React.PropsWithRef<JSX.IntrinsicElements[Type]>;\n }\n\n // If an <a> or <div> tag is to be rendered we have to remove disabled and type,\n // and set aria-disabled, role and tabIndex.\n else {\n const nextProps = {\n role: 'button',\n ...rest,\n // If it's not a <button> than listeners are required even with disabledFocusable\n // Since you cannot assure the default behavior of the element\n // E.g: <a> will redirect on click\n onClick: handleClick,\n onKeyUp: handleKeyUp,\n onKeyDown: handleKeyDown,\n 'aria-disabled': disabled || disabledFocusable || normalizedARIADisabled,\n tabIndex: disabled && !disabledFocusable ? undefined : tabIndex ?? 0,\n } as React.PropsWithRef<JSX.IntrinsicElements[Type]>;\n\n if (type === 'a' && isDisabled) {\n (nextProps as JSX.IntrinsicElements['a']).href = undefined;\n }\n\n return nextProps;\n }\n}\n\n/**\n * @internal\n *\n * This function expects to receive a slot, if `as` property is not desired use `useARIAButtonProps` instead\n *\n * Button keyboard handling, role, disabled and tabIndex implementation that ensures ARIA spec\n * for multiple scenarios of shorthand properties. Ensuring 1st rule of ARIA for cases\n * where no attribute addition is required.\n */\nexport const useARIAButtonShorthand: ResolveShorthandFunction<ARIAButtonSlotProps> = (slot, options) => {\n const shorthand = resolveShorthand(slot, options);\n const shorthandARIAButton = useARIAButtonProps(shorthand?.as ?? 'button', shorthand);\n return shorthand && shorthandARIAButton;\n};\n"],"sourceRoot":"../src/"}
@@ -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 +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;AAwBA;;;;;;AAMG;;;AACH,SAAgB,kBAAhB,CACE,IADF,EAEE,KAFF,EAEyB;EAEvB,MAAM;IACJ,QADI;IAEJ,QAFI;IAGJ,iBAAiB,GAAG,KAHhB;IAIJ,OAJI;IAKJ,SALI;IAMJ,OANI;IAOJ,CAAC,eAAD,GAAmB,YAPf;IAQJ,GAAG;EARC,IASF,KAAK,KAAA,IAAL,IAAA,KAAK,KAAA,KAAA,CAAL,GAAA,KAAA,GAAS,EATb;EAWA,MAAM,sBAAsB,GAAG,OAAO,YAAP,KAAwB,QAAxB,GAAmC,YAAY,KAAK,MAApD,GAA6D,YAA5F;EAEA,MAAM,UAAU,GAAG,QAAQ,IAAI,iBAAZ,IAAiC,sBAApD;EAEA,MAAM,WAAW,GAA+B,iBAAA,CAAA,gBAAA,CAAiB,EAAE,IAAG;IACpE,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,CAP+C,CAAhD;EASA,MAAM,aAAa,GAAiC,iBAAA,CAAA,gBAAA,CAAiB,EAAE,I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AAA,CAAb,GAAa,EAAb,GAAiB,QAAlB,EAA4B,SAA5B,CAA9C;EACA,OAAO,SAAS,IAAI,mBAApB;AACD,CAJM;;AAAM,OAAA,CAAA,sBAAA,GAAsB,sBAAtB","sourcesContent":["import { Enter, Space } from '@fluentui/keyboard-keys';\nimport { resolveShorthand, useEventCallback } from '@fluentui/react-utilities';\nimport type { ExtractSlotProps, ResolveShorthandFunction, Slot } from '@fluentui/react-utilities';\nimport * as React from 'react';\n\nexport type ARIAButtonSlotProps<AlternateAs extends 'a' | 'div' = 'a' | 'div'> = ExtractSlotProps<\n Slot<'button', AlternateAs>\n> & {\n disabled?: boolean;\n /**\n * When set, allows the button to be focusable even when it has been disabled.\n * This is used in scenarios where it is important to keep a consistent tab order\n * for screen reader and keyboard users. The primary example of this\n * pattern is when the disabled button is in a menu or a commandbar and is seldom used for standalone buttons.\n *\n * @default false\n */\n disabledFocusable?: boolean;\n};\n\nexport type ARIAButtonProps<Type extends 'a' | 'div' | 'button' = 'a' | 'div' | 'button'> = React.PropsWithRef<\n JSX.IntrinsicElements[Type]\n> &\n Pick<ARIAButtonSlotProps, 'disabled' | 'disabledFocusable'>;\n\n/**\n * @internal\n *\n * Button keyboard handling, role, disabled and tabIndex implementation that ensures ARIA spec\n * for multiple scenarios of shorthand properties. Ensuring 1st rule of ARIA for cases\n * where no attribute addition is required.\n */\nexport function useARIAButtonProps<Type extends NonNullable<ARIAButtonSlotProps['as']>>(\n type?: Type,\n props?: ARIAButtonProps,\n): React.PropsWithRef<JSX.IntrinsicElements[Type]> {\n const {\n disabled,\n tabIndex,\n disabledFocusable = false,\n onClick,\n onKeyDown,\n onKeyUp,\n ['aria-disabled']: ariaDisabled,\n ...rest\n } = props ?? {};\n\n const normalizedARIADisabled = typeof ariaDisabled === 'string' ? ariaDisabled === 'true' : ariaDisabled;\n\n const isDisabled = disabled || disabledFocusable || normalizedARIADisabled;\n\n const handleClick: ARIAButtonProps['onClick'] = useEventCallback(ev => {\n if (isDisabled) {\n ev.preventDefault();\n ev.stopPropagation();\n } else {\n onClick?.(ev);\n }\n });\n\n const handleKeyDown: ARIAButtonProps['onKeyDown'] = useEventCallback(ev => {\n onKeyDown?.(ev);\n\n if (ev.isDefaultPrevented()) {\n return;\n }\n\n const key = ev.key;\n\n if (isDisabled && (key === Enter || key === Space)) {\n ev.preventDefault();\n ev.stopPropagation();\n return;\n }\n\n if (key === Space) {\n ev.preventDefault();\n return;\n }\n\n // If enter is pressed, activate the button\n else if (key === Enter) {\n ev.preventDefault();\n ev.currentTarget.click();\n }\n });\n\n const handleKeyUp: ARIAButtonProps['onKeyUp'] = useEventCallback(ev => {\n onKeyUp?.(ev);\n\n if (ev.isDefaultPrevented()) {\n return;\n }\n\n const key = ev.key;\n\n if (isDisabled && (key === Enter || key === Space)) {\n ev.preventDefault();\n ev.stopPropagation();\n return;\n }\n\n if (key === Space) {\n ev.preventDefault();\n ev.currentTarget.click();\n }\n });\n\n // If a <button> tag is to be rendered we just need to set disabled and aria-disabled correctly\n if (type === 'button' || type === undefined) {\n return {\n ...rest,\n tabIndex,\n disabled: disabled && !disabledFocusable,\n 'aria-disabled': disabledFocusable ? true : normalizedARIADisabled,\n // onclick should still use internal handler to ensure prevention if disabled\n // if disabledFocusable then there's no requirement for handlers as those events should not be propagated\n onClick: disabledFocusable ? undefined : handleClick,\n onKeyUp: disabledFocusable ? undefined : onKeyUp,\n onKeyDown: disabledFocusable ? undefined : onKeyDown,\n } as React.PropsWithRef<JSX.IntrinsicElements[Type]>;\n }\n\n // If an <a> or <div> tag is to be rendered we have to remove disabled and type,\n // and set aria-disabled, role and tabIndex.\n else {\n const nextProps = {\n role: 'button',\n ...rest,\n // If it's not a <button> than listeners are required even with disabledFocusable\n // Since you cannot assure the default behavior of the element\n // E.g: <a> will redirect on click\n onClick: handleClick,\n onKeyUp: handleKeyUp,\n onKeyDown: handleKeyDown,\n 'aria-disabled': disabled || disabledFocusable || normalizedARIADisabled,\n tabIndex: disabled && !disabledFocusable ? undefined : tabIndex ?? 0,\n } as React.PropsWithRef<JSX.IntrinsicElements[Type]>;\n\n if (type === 'a' && isDisabled) {\n (nextProps as JSX.IntrinsicElements['a']).href = undefined;\n }\n\n return nextProps;\n }\n}\n\n/**\n * @internal\n *\n * This function expects to receive a slot, if `as` property is not desired use `useARIAButtonProps` instead\n *\n * Button keyboard handling, role, disabled and tabIndex implementation that ensures ARIA spec\n * for multiple scenarios of shorthand properties. Ensuring 1st rule of ARIA for cases\n * where no attribute addition is required.\n */\nexport const useARIAButtonShorthand: ResolveShorthandFunction<ARIAButtonSlotProps> = (slot, options) => {\n const shorthand = resolveShorthand(slot, options);\n const shorthandARIAButton = useARIAButtonProps(shorthand?.as ?? 'button', shorthand);\n return shorthand && shorthandARIAButton;\n};\n"],"sourceRoot":"../src/"}