@fluentui/react-aria 9.1.0 → 9.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.json CHANGED
@@ -2,7 +2,92 @@
2
2
  "name": "@fluentui/react-aria",
3
3
  "entries": [
4
4
  {
5
- "date": "Wed, 03 Aug 2022 16:00:04 GMT",
5
+ "date": "Mon, 03 Oct 2022 22:22:44 GMT",
6
+ "tag": "@fluentui/react-aria_v9.2.1",
7
+ "version": "9.2.1",
8
+ "comments": {
9
+ "patch": [
10
+ {
11
+ "author": "bernardo.sunderhus@gmail.com",
12
+ "package": "@fluentui/react-aria",
13
+ "commit": "3b48ff5d92433635997aa69a59b138ec273172ea",
14
+ "comment": "chore: user defined tabIndex should prevail aria-button defined"
15
+ }
16
+ ]
17
+ }
18
+ },
19
+ {
20
+ "date": "Fri, 23 Sep 2022 10:32:29 GMT",
21
+ "tag": "@fluentui/react-aria_v9.2.0",
22
+ "version": "9.2.0",
23
+ "comments": {
24
+ "none": [
25
+ {
26
+ "author": "bernardo.sunderhus@gmail.com",
27
+ "package": "@fluentui/react-aria",
28
+ "commit": "ce5f1ec6a0c0f766679ea708c40538fc2d56c6d9",
29
+ "comment": "chore: restructure folder organization"
30
+ }
31
+ ]
32
+ }
33
+ },
34
+ {
35
+ "date": "Thu, 15 Sep 2022 09:49:48 GMT",
36
+ "tag": "@fluentui/react-aria_v9.2.0",
37
+ "version": "9.2.0",
38
+ "comments": {
39
+ "none": [
40
+ {
41
+ "author": "bernardo.sunderhus@gmail.com",
42
+ "package": "@fluentui/react-aria",
43
+ "commit": "bf151e71e0ffa5de5c44cc722e629cdeb7abdbb2",
44
+ "comment": "chore: re-organize useARIAButton into its own folder"
45
+ },
46
+ {
47
+ "author": "martinhochel@microsoft.com",
48
+ "package": "@fluentui/react-aria",
49
+ "commit": "e6cf183695d6d67a24e038c49a876224e5ed35e5",
50
+ "comment": "chore: update package scaffold"
51
+ }
52
+ ],
53
+ "patch": [
54
+ {
55
+ "author": "martinhochel@microsoft.com",
56
+ "package": "@fluentui/react-aria",
57
+ "commit": "16aa65dcae8f75c6a221225fd0eb43800650ac66",
58
+ "comment": "docs(react-aria): re-generate api.md"
59
+ },
60
+ {
61
+ "author": "bernardo.sunderhus@gmail.com",
62
+ "package": "@fluentui/react-aria",
63
+ "commit": "de08c96226ec5d425f705c22c5d94dbac5811eb6",
64
+ "comment": "chore(react-aria): improve internal typings"
65
+ },
66
+ {
67
+ "author": "bernardo.sunderhus@gmail.com",
68
+ "package": "@fluentui/react-aria",
69
+ "commit": "0547583ebcebe746110e5ef8d0599b0972b1f4c6",
70
+ "comment": "feat: upgrade typings on useARIAButtonProps to be more specific"
71
+ }
72
+ ],
73
+ "minor": [
74
+ {
75
+ "author": "bernardo.sunderhus@gmail.com",
76
+ "package": "@fluentui/react-aria",
77
+ "commit": "81191d9a45e629126a416e7202af3e241cd5e0fc",
78
+ "comment": "feat: add helper types to assist DOM element handling"
79
+ },
80
+ {
81
+ "author": "beachball",
82
+ "package": "@fluentui/react-aria",
83
+ "comment": "Bump @fluentui/react-utilities to v9.1.0",
84
+ "commit": "a33448fe4a0f4117686c378f80b893d1406d95a8"
85
+ }
86
+ ]
87
+ }
88
+ },
89
+ {
90
+ "date": "Wed, 03 Aug 2022 16:03:37 GMT",
6
91
  "tag": "@fluentui/react-aria_v9.1.0",
7
92
  "version": "9.1.0",
8
93
  "comments": {
package/CHANGELOG.md CHANGED
@@ -1,12 +1,37 @@
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 Mon, 03 Oct 2022 22:22:44 GMT and should not be manually modified.
4
4
 
5
5
  <!-- Start content -->
6
6
 
7
+ ## [9.2.1](https://github.com/microsoft/fluentui/tree/@fluentui/react-aria_v9.2.1)
8
+
9
+ Mon, 03 Oct 2022 22:22:44 GMT
10
+ [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-aria_v9.2.0..@fluentui/react-aria_v9.2.1)
11
+
12
+ ### Patches
13
+
14
+ - chore: user defined tabIndex should prevail aria-button defined ([PR #24962](https://github.com/microsoft/fluentui/pull/24962) by bernardo.sunderhus@gmail.com)
15
+
16
+ ## [9.2.0](https://github.com/microsoft/fluentui/tree/@fluentui/react-aria_v9.2.0)
17
+
18
+ Thu, 15 Sep 2022 09:49:48 GMT
19
+ [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-aria_v9.1.0..@fluentui/react-aria_v9.2.0)
20
+
21
+ ### Minor changes
22
+
23
+ - feat: add helper types to assist DOM element handling ([PR #24722](https://github.com/microsoft/fluentui/pull/24722) by bernardo.sunderhus@gmail.com)
24
+ - Bump @fluentui/react-utilities to v9.1.0 ([PR #24808](https://github.com/microsoft/fluentui/pull/24808) by beachball)
25
+
26
+ ### Patches
27
+
28
+ - docs(react-aria): re-generate api.md ([PR #23369](https://github.com/microsoft/fluentui/pull/23369) by martinhochel@microsoft.com)
29
+ - chore(react-aria): improve internal typings ([PR #24742](https://github.com/microsoft/fluentui/pull/24742) by bernardo.sunderhus@gmail.com)
30
+ - feat: upgrade typings on useARIAButtonProps to be more specific ([PR #24177](https://github.com/microsoft/fluentui/pull/24177) by bernardo.sunderhus@gmail.com)
31
+
7
32
  ## [9.1.0](https://github.com/microsoft/fluentui/tree/@fluentui/react-aria_v9.1.0)
8
33
 
9
- Wed, 03 Aug 2022 16:00:04 GMT
34
+ Wed, 03 Aug 2022 16:03:37 GMT
10
35
  [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-aria_v9.0.2..@fluentui/react-aria_v9.1.0)
11
36
 
12
37
  ### 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":["button/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":["button/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,22 +1,41 @@
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) {
12
32
  const {
13
33
  disabled,
14
- tabIndex,
15
34
  disabledFocusable = false,
35
+ ['aria-disabled']: ariaDisabled,
16
36
  onClick,
17
37
  onKeyDown,
18
38
  onKeyUp,
19
- ['aria-disabled']: ariaDisabled,
20
39
  ...rest
21
40
  } = props !== null && props !== void 0 ? props : {};
22
41
  const normalizedARIADisabled = typeof ariaDisabled === 'string' ? ariaDisabled === 'true' : ariaDisabled;
@@ -76,7 +95,6 @@ export function useARIAButtonProps(type, props) {
76
95
 
77
96
  if (type === 'button' || type === undefined) {
78
97
  return { ...rest,
79
- tabIndex,
80
98
  disabled: disabled && !disabledFocusable,
81
99
  'aria-disabled': disabledFocusable ? true : normalizedARIADisabled,
82
100
  // onclick should still use internal handler to ensure prevention if disabled
@@ -88,8 +106,9 @@ export function useARIAButtonProps(type, props) {
88
106
  } // If an <a> or <div> tag is to be rendered we have to remove disabled and type,
89
107
  // and set aria-disabled, role and tabIndex.
90
108
  else {
91
- const nextProps = {
109
+ const resultProps = {
92
110
  role: 'button',
111
+ tabIndex: disabled && !disabledFocusable ? undefined : 0,
93
112
  ...rest,
94
113
  // If it's not a <button> than listeners are required even with disabledFocusable
95
114
  // Since you cannot assure the default behavior of the element
@@ -97,32 +116,14 @@ export function useARIAButtonProps(type, props) {
97
116
  onClick: handleClick,
98
117
  onKeyUp: handleKeyUp,
99
118
  onKeyDown: handleKeyDown,
100
- 'aria-disabled': disabled || disabledFocusable || normalizedARIADisabled,
101
- tabIndex: disabled && !disabledFocusable ? undefined : tabIndex !== null && tabIndex !== void 0 ? tabIndex : 0
119
+ 'aria-disabled': disabled || disabledFocusable || normalizedARIADisabled
102
120
  };
103
121
 
104
122
  if (type === 'a' && isDisabled) {
105
- nextProps.href = undefined;
123
+ resultProps.href = undefined;
106
124
  }
107
125
 
108
- return nextProps;
126
+ return resultProps;
109
127
  }
110
128
  }
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
129
+ //# sourceMappingURL=useARIAButtonProps.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["button/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;IAAE,QAAF;IAAY,iBAAiB,GAAG,KAAhC;IAAuC,CAAC,eAAD,GAAmB,YAA1D;IAAwE,OAAxE;IAAiF,SAAjF;IAA4F,OAA5F;IAAqG,GAAG;EAAxG,IACJ,KAAK,KAAA,IAAL,IAAA,KAAK,KAAA,KAAA,CAAL,GAAA,KA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AJ,EAA6B;MAC3B;IACD;;IAED,MAAM,GAAG,GAAG,EAAE,CAAC,GAAf;;IAEA,IAAI,UAAU,KAAK,GAAG,KAAK,KAAR,IAAiB,GAAG,KAAK,KAA9B,CAAd,EAAoD;MAClD,EAAE,CAAC,cAAH;MACA,EAAE,CAAC,eAAH;MACA;IACD;;IAED,IAAI,GAAG,KAAK,KAAZ,EAAmB;MACjB,EAAE,CAAC,cAAH;MACA,EAAE,CAAC,aAAH,CAAiB,KAAjB;IACD;EACF,CAnBmC,CAApC,CA7Ca,CAkEb;;EACA,IAAI,IAAI,KAAK,QAAT,IAAqB,IAAI,KAAK,SAAlC,EAA6C;IAC3C,OAAO,EACL,GAAG,IADE;MAEL,QAAQ,EAAE,QAAQ,IAAI,CAAC,iBAFlB;MAGL,iBAAiB,iBAAiB,GAAG,IAAH,GAAU,sBAHvC;MAIL;MACA;MACA,OAAO,EAAE,iBAAiB,GAAG,SAAH,GAAe,WANpC;MAOL,OAAO,EAAE,iBAAiB,GAAG,SAAH,GAAe,OAPpC;MAQL,SAAS,EAAE,iBAAiB,GAAG,SAAH,GAAe;IARtC,CAAP;EAUD,CAXD,CAaA;EACA;EAdA,KAeK;IACH,MAAM,WAAW,GAAG;MAClB,IAAI,EAAE,QADY;MAElB,QAAQ,EAAE,QAAQ,IAAI,CAAC,iBAAb,GAAiC,SAAjC,GAA6C,CAFrC;MAGlB,GAAG,IAHe;MAIlB;MACA;MACA;MACA,OAAO,EAAE,WAPS;MAQlB,OAAO,EAAE,WARS;MASlB,SAAS,EAAE,aATO;MAUlB,iBAAiB,QAAQ,IAAI,iBAAZ,IAAiC;IAVhC,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 { disabled, disabledFocusable = false, ['aria-disabled']: ariaDisabled, onClick, onKeyDown, onKeyUp, ...rest } =\n props ?? {};\n\n const normalizedARIADisabled = typeof ariaDisabled === 'string' ? ariaDisabled === 'true' : ariaDisabled;\n\n const isDisabled = disabled || disabledFocusable || normalizedARIADisabled;\n\n const handleClick = useEventCallback((ev: React.MouseEvent<ARIAButtonElementIntersection>) => {\n if (isDisabled) {\n ev.preventDefault();\n ev.stopPropagation();\n } else {\n onClick?.(ev);\n }\n });\n\n const handleKeyDown = useEventCallback((ev: React.KeyboardEvent<ARIAButtonElementIntersection>) => {\n onKeyDown?.(ev);\n\n if (ev.isDefaultPrevented()) {\n return;\n }\n\n const key = ev.key;\n\n if (isDisabled && (key === Enter || key === Space)) {\n ev.preventDefault();\n ev.stopPropagation();\n return;\n }\n\n if (key === Space) {\n ev.preventDefault();\n return;\n }\n\n // If enter is pressed, activate the button\n else if (key === Enter) {\n ev.preventDefault();\n ev.currentTarget.click();\n }\n });\n\n const handleKeyUp = useEventCallback((ev: React.KeyboardEvent<ARIAButtonElementIntersection>) => {\n onKeyUp?.(ev);\n\n if (ev.isDefaultPrevented()) {\n return;\n }\n\n const key = ev.key;\n\n if (isDisabled && (key === Enter || key === Space)) {\n ev.preventDefault();\n ev.stopPropagation();\n return;\n }\n\n if (key === Space) {\n ev.preventDefault();\n ev.currentTarget.click();\n }\n });\n\n // If a <button> tag is to be rendered we just need to set disabled and aria-disabled correctly\n if (type === 'button' || type === undefined) {\n return {\n ...rest,\n disabled: disabled && !disabledFocusable,\n 'aria-disabled': disabledFocusable ? true : normalizedARIADisabled,\n // onclick should still use internal handler to ensure prevention if disabled\n // if disabledFocusable then there's no requirement for handlers as those events should not be propagated\n onClick: disabledFocusable ? undefined : handleClick,\n onKeyUp: disabledFocusable ? undefined : onKeyUp,\n onKeyDown: disabledFocusable ? undefined : onKeyDown,\n } as ARIAButtonResultProps<Type, Props>;\n }\n\n // If an <a> or <div> tag is to be rendered we have to remove disabled and type,\n // and set aria-disabled, role and tabIndex.\n else {\n const resultProps = {\n role: 'button',\n tabIndex: disabled && !disabledFocusable ? undefined : 0,\n ...rest,\n // If it's not a <button> than listeners are required even with disabledFocusable\n // Since you cannot assure the default behavior of the element\n // E.g: <a> will redirect on click\n onClick: handleClick,\n onKeyUp: handleKeyUp,\n onKeyDown: handleKeyDown,\n 'aria-disabled': disabled || disabledFocusable || normalizedARIADisabled,\n } as ARIAButtonResultProps<Type, Props>;\n\n if (type === 'a' && isDisabled) {\n (resultProps as ARIAButtonResultProps<'a', Props>).href = undefined;\n }\n\n return resultProps;\n }\n}\n"],"sourceRoot":"../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":["button/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 './button/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,gBAAgB,CAAC","sourcesContent":["export { useARIAButtonShorthand, useARIAButtonProps } from './button/index';\nexport type {\n ARIAButtonSlotProps,\n ARIAButtonProps,\n ARIAButtonResultProps,\n ARIAButtonType,\n ARIAButtonElement,\n ARIAButtonElementIntersection,\n} from './button/index';\n"]}
@@ -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":["button/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,20 +12,39 @@ 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
 
20
40
  function useARIAButtonProps(type, props) {
21
41
  const {
22
42
  disabled,
23
- tabIndex,
24
43
  disabledFocusable = false,
44
+ ['aria-disabled']: ariaDisabled,
25
45
  onClick,
26
46
  onKeyDown,
27
47
  onKeyUp,
28
- ['aria-disabled']: ariaDisabled,
29
48
  ...rest
30
49
  } = props !== null && props !== void 0 ? props : {};
31
50
  const normalizedARIADisabled = typeof ariaDisabled === 'string' ? ariaDisabled === 'true' : ariaDisabled;
@@ -85,7 +104,6 @@ function useARIAButtonProps(type, props) {
85
104
 
86
105
  if (type === 'button' || type === undefined) {
87
106
  return { ...rest,
88
- tabIndex,
89
107
  disabled: disabled && !disabledFocusable,
90
108
  'aria-disabled': disabledFocusable ? true : normalizedARIADisabled,
91
109
  // onclick should still use internal handler to ensure prevention if disabled
@@ -97,8 +115,9 @@ function useARIAButtonProps(type, props) {
97
115
  } // If an <a> or <div> tag is to be rendered we have to remove disabled and type,
98
116
  // and set aria-disabled, role and tabIndex.
99
117
  else {
100
- const nextProps = {
118
+ const resultProps = {
101
119
  role: 'button',
120
+ tabIndex: disabled && !disabledFocusable ? undefined : 0,
102
121
  ...rest,
103
122
  // If it's not a <button> than listeners are required even with disabledFocusable
104
123
  // Since you cannot assure the default behavior of the element
@@ -106,36 +125,16 @@ function useARIAButtonProps(type, props) {
106
125
  onClick: handleClick,
107
126
  onKeyUp: handleKeyUp,
108
127
  onKeyDown: handleKeyDown,
109
- 'aria-disabled': disabled || disabledFocusable || normalizedARIADisabled,
110
- tabIndex: disabled && !disabledFocusable ? undefined : tabIndex !== null && tabIndex !== void 0 ? tabIndex : 0
128
+ 'aria-disabled': disabled || disabledFocusable || normalizedARIADisabled
111
129
  };
112
130
 
113
131
  if (type === 'a' && isDisabled) {
114
- nextProps.href = undefined;
132
+ resultProps.href = undefined;
115
133
  }
116
134
 
117
- return nextProps;
135
+ return resultProps;
118
136
  }
119
137
  }
120
138
 
121
139
  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
140
+ //# sourceMappingURL=useARIAButtonProps.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["button/useARIAButtonProps.ts"],"names":[],"mappings":";;;;;;;AAAA,MAAA,eAAA,gBAAA,OAAA,CAAA,yBAAA,CAAA;;AACA,MAAA,iBAAA,gBAAA,OAAA,CAAA,2BAAA,CAAA;AAIA;;;;;;;;;;;;;;;;;;;;;;;;;;AA0BG;;;AACH,SAAgB,kBAAhB,CACE,IADF,EAEE,KAFF,EAEe;EAEb,MAAM;IAAE,QAAF;IAAY,iBAAiB,GAAG,KAAhC;IAAuC,CAAC,eAAD,GAAmB,YAA1D;IAAwE,OAAxE;IAAiF,SAAjF;IAA4F,OAA5F;IAAqG,GAAG;EAAxG,IACJ,KAAK,KAAA,IAAL,IAAA,KAAK,KAAA,KAAA,CAAL,GAAA,KAAA,GAAS,EADX;EAGA,MAAM,sBAAsB,GAAG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;AAxGD,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 { disabled, disabledFocusable = false, ['aria-disabled']: ariaDisabled, onClick, onKeyDown, onKeyUp, ...rest } =\n props ?? {};\n\n const normalizedARIADisabled = typeof ariaDisabled === 'string' ? ariaDisabled === 'true' : ariaDisabled;\n\n const isDisabled = disabled || disabledFocusable || normalizedARIADisabled;\n\n const handleClick = useEventCallback((ev: React.MouseEvent<ARIAButtonElementIntersection>) => {\n if (isDisabled) {\n ev.preventDefault();\n ev.stopPropagation();\n } else {\n onClick?.(ev);\n }\n });\n\n const handleKeyDown = useEventCallback((ev: React.KeyboardEvent<ARIAButtonElementIntersection>) => {\n onKeyDown?.(ev);\n\n if (ev.isDefaultPrevented()) {\n return;\n }\n\n const key = ev.key;\n\n if (isDisabled && (key === Enter || key === Space)) {\n ev.preventDefault();\n ev.stopPropagation();\n return;\n }\n\n if (key === Space) {\n ev.preventDefault();\n return;\n }\n\n // If enter is pressed, activate the button\n else if (key === Enter) {\n ev.preventDefault();\n ev.currentTarget.click();\n }\n });\n\n const handleKeyUp = useEventCallback((ev: React.KeyboardEvent<ARIAButtonElementIntersection>) => {\n onKeyUp?.(ev);\n\n if (ev.isDefaultPrevented()) {\n return;\n }\n\n const key = ev.key;\n\n if (isDisabled && (key === Enter || key === Space)) {\n ev.preventDefault();\n ev.stopPropagation();\n return;\n }\n\n if (key === Space) {\n ev.preventDefault();\n ev.currentTarget.click();\n }\n });\n\n // If a <button> tag is to be rendered we just need to set disabled and aria-disabled correctly\n if (type === 'button' || type === undefined) {\n return {\n ...rest,\n disabled: disabled && !disabledFocusable,\n 'aria-disabled': disabledFocusable ? true : normalizedARIADisabled,\n // onclick should still use internal handler to ensure prevention if disabled\n // if disabledFocusable then there's no requirement for handlers as those events should not be propagated\n onClick: disabledFocusable ? undefined : handleClick,\n onKeyUp: disabledFocusable ? undefined : onKeyUp,\n onKeyDown: disabledFocusable ? undefined : onKeyDown,\n } as ARIAButtonResultProps<Type, Props>;\n }\n\n // If an <a> or <div> tag is to be rendered we have to remove disabled and type,\n // and set aria-disabled, role and tabIndex.\n else {\n const resultProps = {\n role: 'button',\n tabIndex: disabled && !disabledFocusable ? undefined : 0,\n ...rest,\n // If it's not a <button> than listeners are required even with disabledFocusable\n // Since you cannot assure the default behavior of the element\n // E.g: <a> will redirect on click\n onClick: handleClick,\n onKeyUp: handleKeyUp,\n onKeyDown: handleKeyDown,\n 'aria-disabled': disabled || disabledFocusable || normalizedARIADisabled,\n } as ARIAButtonResultProps<Type, Props>;\n\n if (type === 'a' && isDisabled) {\n (resultProps as ARIAButtonResultProps<'a', Props>).href = undefined;\n }\n\n return resultProps;\n }\n}\n"],"sourceRoot":"../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":["button/useARIAButtonShorthand.ts"],"names":[],"mappings":";;;;;;;AAAA,MAAA,iBAAA,gBAAA,OAAA,CAAA,2BAAA,CAAA;;AACA,MAAA,oBAAA,gBAAA,OAAA,CAAA,sBAAA,CAAA;AAIA;;;;;;;;AAQG;;;AACI,MAAM,sBAAsB,GAAkD,CAAC,IAAD,EAAO,OAAP,KAAkB;;;EACrG,MAAM,SAAS,GAAG,iBAAA,CAAA,gBAAA,CAAiB,IAAjB,EAAuB,OAAvB,CAAlB;EACA,MAAM,mBAAmB,GAAG,oBAAA,CAAA,kBAAA,CAAoD,CAAA,EAAA,GAAA,SAAS,KAAA,IAAT,IAAA,SAAS,KAAA,KAAA,CAAT,GAAS,KAAA,CAAT,GAAA,SAAS,CAAE,EAAX,MAAa,IAAb,IAAa,EAAA,KAAA,KAAA,CAAb,GAAa,EAAb,GAAiB,QAArE,EAA+E,SAA/E,CAA5B;EACA,OAAO,SAAS,IAAI,mBAApB;AACD,CAJM;;AAAM,OAAA,CAAA,sBAAA,GAAsB,sBAAtB","sourcesContent":["import { resolveShorthand } from '@fluentui/react-utilities';\nimport { useARIAButtonProps } from './useARIAButtonProps';\nimport type { ResolveShorthandFunction } from '@fluentui/react-utilities';\nimport type { ARIAButtonProps, ARIAButtonSlotProps, ARIAButtonType } from './types';\n\n/**\n * @internal\n *\n * This function expects to receive a slot, if `as` property is not desired use `useARIAButtonProps` instead\n *\n * Button keyboard handling, role, disabled and tabIndex implementation that ensures ARIA spec\n * for multiple scenarios of shorthand properties. Ensuring 1st rule of ARIA for cases\n * where no attribute addition is required.\n */\nexport const useARIAButtonShorthand: ResolveShorthandFunction<ARIAButtonSlotProps> = (slot, options) => {\n const shorthand = resolveShorthand(slot, options);\n const shorthandARIAButton = useARIAButtonProps<ARIAButtonType, ARIAButtonProps>(shorthand?.as ?? 'button', shorthand);\n return shorthand && shorthandARIAButton;\n};\n"],"sourceRoot":"../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("./button/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,gBAAA,CAAA;;AAAS,MAAA,CAAA,cAAA,CAAA,OAAA,EAAA,wBAAA,EAAA;EAAA,UAAA,EAAA,IAAA;EAAA,GAAA,EAAA,YAAA;IAAA,OAAA,OAAA,CAAA,sBAAA;EAAsB;AAAtB,CAAA;AAAwB,MAAA,CAAA,cAAA,CAAA,OAAA,EAAA,oBAAA,EAAA;EAAA,UAAA,EAAA,IAAA;EAAA,GAAA,EAAA,YAAA;IAAA,OAAA,OAAA,CAAA,kBAAA;EAAkB;AAAlB,CAAA","sourcesContent":["export { useARIAButtonShorthand, useARIAButtonProps } from './button/index';\nexport type {\n ARIAButtonSlotProps,\n ARIAButtonProps,\n ARIAButtonResultProps,\n ARIAButtonType,\n ARIAButtonElement,\n ARIAButtonElementIntersection,\n} from './button/index';\n"],"sourceRoot":"../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.1",
4
4
  "description": "React helper to ensure ARIA",
5
5
  "main": "lib-commonjs/index.js",
6
6
  "module": "lib/index.js",
@@ -20,8 +20,8 @@
20
20
  "start": "yarn storybook",
21
21
  "test": "jest --passWithNoTests",
22
22
  "docs": "api-extractor run --config=config/api-extractor.local.json --local",
23
- "build:local": "tsc -p ./tsconfig.lib.json --module esnext --emitDeclarationOnly && node ../../../scripts/typescript/normalize-import --output ./dist/packages/react-components/react-aria/src && yarn docs",
24
- "storybook": "node ../../../scripts/storybook/runner",
23
+ "build:local": "tsc -p ./tsconfig.lib.json --module esnext --emitDeclarationOnly && node ../../../scripts/typescript/normalize-import --output ./dist/types/types/packages/react-components/react-aria/src && yarn docs",
24
+ "storybook": "start-storybook",
25
25
  "type-check": "tsc -b tsconfig.json"
26
26
  },
27
27
  "devDependencies": {
@@ -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,QAA6B,yBAA7B;AACA,SAAS,gBAAT,EAA2B,gBAA3B,QAAmD,2BAAnD;AAwBA;;;;;;AAMG;;AACH,OAAM,SAAU,kBAAV,CACJ,IADI,EAEJ,KAFI,EAEmB;EAEvB,MAAM;IACJ,QADI;IAEJ,QAFI;IAGJ,iBAAiB,GAAG,KAHhB;IAIJ,OAJI;IAKJ,SALI;IAMJ,OANI;IAOJ,CAAC,eAAD,GAAmB,YAPf;IAQJ,GAAG;EARC,IASF,KAAK,KAAA,IAAL,IAAA,KAAK,KAAA,KAAA,CAA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ACD;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,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AcA;EACA;EAfA,KAgBK;IACH,MAAM,SAAS,GAAG;MAChB,IAAI,EAAE,QADU;MAEhB,GAAG,IAFa;MAGhB;MACA;MACA;MACA,OAAO,EAAE,WANO;MAOhB,OAAO,EAAE,WAPO;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;;AAjHD,OAAA,CAAA,kBAAA,GAAA,kBAAA;AAmHA;;;;;;;;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,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;;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/"}