@fluentui/react-aria 0.0.0-nightly-20230427-0418.1 → 0.0.0-nightly-20230428-0419.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 +7 -7
- package/CHANGELOG.md +6 -6
- package/package.json +3 -3
- package/dist/index.d.ts +0 -86
- package/lib/button/index.js +0 -4
- package/lib/button/index.js.map +0 -1
- package/lib/button/types.js +0 -2
- package/lib/button/types.js.map +0 -1
- package/lib/button/useARIAButtonProps.js +0 -117
- package/lib/button/useARIAButtonProps.js.map +0 -1
- package/lib/button/useARIAButtonShorthand.js +0 -18
- package/lib/button/useARIAButtonShorthand.js.map +0 -1
- package/lib/index.js +0 -2
- package/lib/index.js.map +0 -1
package/CHANGELOG.json
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
"name": "@fluentui/react-aria",
|
|
3
3
|
"entries": [
|
|
4
4
|
{
|
|
5
|
-
"date": "
|
|
6
|
-
"tag": "@fluentui/react-aria_v0.0.0-nightly-
|
|
7
|
-
"version": "0.0.0-nightly-
|
|
5
|
+
"date": "Fri, 28 Apr 2023 04:25:12 GMT",
|
|
6
|
+
"tag": "@fluentui/react-aria_v0.0.0-nightly-20230428-0419.1",
|
|
7
|
+
"version": "0.0.0-nightly-20230428-0419.1",
|
|
8
8
|
"comments": {
|
|
9
9
|
"prerelease": [
|
|
10
10
|
{
|
|
@@ -16,14 +16,14 @@
|
|
|
16
16
|
{
|
|
17
17
|
"author": "beachball",
|
|
18
18
|
"package": "@fluentui/react-aria",
|
|
19
|
-
"comment": "Bump @fluentui/keyboard-keys to v0.0.0-nightly-
|
|
20
|
-
"commit": "
|
|
19
|
+
"comment": "Bump @fluentui/keyboard-keys to v0.0.0-nightly-20230428-0419.1",
|
|
20
|
+
"commit": "6d0e3c2fb45fde4cf5056d3d18d4c5bc5899a839"
|
|
21
21
|
},
|
|
22
22
|
{
|
|
23
23
|
"author": "beachball",
|
|
24
24
|
"package": "@fluentui/react-aria",
|
|
25
|
-
"comment": "Bump @fluentui/react-utilities to v0.0.0-nightly-
|
|
26
|
-
"commit": "
|
|
25
|
+
"comment": "Bump @fluentui/react-utilities to v0.0.0-nightly-20230428-0419.1",
|
|
26
|
+
"commit": "6d0e3c2fb45fde4cf5056d3d18d4c5bc5899a839"
|
|
27
27
|
}
|
|
28
28
|
]
|
|
29
29
|
}
|
package/CHANGELOG.md
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
# Change Log - @fluentui/react-aria
|
|
2
2
|
|
|
3
|
-
This log was last generated on
|
|
3
|
+
This log was last generated on Fri, 28 Apr 2023 04:25:12 GMT and should not be manually modified.
|
|
4
4
|
|
|
5
5
|
<!-- Start content -->
|
|
6
6
|
|
|
7
|
-
## [0.0.0-nightly-
|
|
7
|
+
## [0.0.0-nightly-20230428-0419.1](https://github.com/microsoft/fluentui/tree/@fluentui/react-aria_v0.0.0-nightly-20230428-0419.1)
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-aria_v9.3.18..@fluentui/react-aria_v0.0.0-nightly-
|
|
9
|
+
Fri, 28 Apr 2023 04:25:12 GMT
|
|
10
|
+
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-aria_v9.3.18..@fluentui/react-aria_v0.0.0-nightly-20230428-0419.1)
|
|
11
11
|
|
|
12
12
|
### Changes
|
|
13
13
|
|
|
14
14
|
- Release nightly v9 ([commit](https://github.com/microsoft/fluentui/commit/not available) by fluentui-internal@service.microsoft.com)
|
|
15
|
-
- Bump @fluentui/keyboard-keys to v0.0.0-nightly-
|
|
16
|
-
- Bump @fluentui/react-utilities to v0.0.0-nightly-
|
|
15
|
+
- Bump @fluentui/keyboard-keys to v0.0.0-nightly-20230428-0419.1 ([commit](https://github.com/microsoft/fluentui/commit/6d0e3c2fb45fde4cf5056d3d18d4c5bc5899a839) by beachball)
|
|
16
|
+
- Bump @fluentui/react-utilities to v0.0.0-nightly-20230428-0419.1 ([commit](https://github.com/microsoft/fluentui/commit/6d0e3c2fb45fde4cf5056d3d18d4c5bc5899a839) by beachball)
|
|
17
17
|
|
|
18
18
|
## [9.3.18](https://github.com/microsoft/fluentui/tree/@fluentui/react-aria_v9.3.18)
|
|
19
19
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluentui/react-aria",
|
|
3
|
-
"version": "0.0.0-nightly-
|
|
3
|
+
"version": "0.0.0-nightly-20230428-0419.1",
|
|
4
4
|
"description": "React helper to ensure ARIA",
|
|
5
5
|
"main": "lib-commonjs/index.js",
|
|
6
6
|
"module": "lib/index.js",
|
|
@@ -30,8 +30,8 @@
|
|
|
30
30
|
"@fluentui/scripts-tasks": "*"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@fluentui/keyboard-keys": "0.0.0-nightly-
|
|
34
|
-
"@fluentui/react-utilities": "0.0.0-nightly-
|
|
33
|
+
"@fluentui/keyboard-keys": "0.0.0-nightly-20230428-0419.1",
|
|
34
|
+
"@fluentui/react-utilities": "0.0.0-nightly-20230428-0419.1",
|
|
35
35
|
"@swc/helpers": "^0.4.14"
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {
|
package/dist/index.d.ts
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import type { ExtractSlotProps } from '@fluentui/react-utilities';
|
|
2
|
-
import * as React_2 from 'react';
|
|
3
|
-
import type { ResolveShorthandFunction } from '@fluentui/react-utilities';
|
|
4
|
-
import type { Slot } from '@fluentui/react-utilities';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Props that will be modified internally by `useARIAButtonProps` by each case.
|
|
8
|
-
* This typing is to ensure a well specified return value for `useARIAbButtonProps`
|
|
9
|
-
*/
|
|
10
|
-
export 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);
|
|
11
|
-
|
|
12
|
-
export declare type ARIAButtonElement<AlternateAs extends 'a' | 'div' = 'a' | 'div'> = HTMLButtonElement | (AlternateAs extends 'a' ? HTMLAnchorElement : never) | (AlternateAs extends 'div' ? HTMLDivElement : never);
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* @internal
|
|
16
|
-
*/
|
|
17
|
-
export declare type ARIAButtonElementIntersection<AlternateAs extends 'a' | 'div' = 'a' | 'div'> = UnionToIntersection<ARIAButtonElement<AlternateAs>>;
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Props expected by `useARIAButtonProps` hooks
|
|
21
|
-
*/
|
|
22
|
-
export declare type ARIAButtonProps<Type extends ARIAButtonType = ARIAButtonType> = React_2.PropsWithRef<JSX.IntrinsicElements[Type]> & {
|
|
23
|
-
disabled?: boolean;
|
|
24
|
-
/**
|
|
25
|
-
* When set, allows the button to be focusable even when it has been disabled.
|
|
26
|
-
* This is used in scenarios where it is important to keep a consistent tab order
|
|
27
|
-
* for screen reader and keyboard users. The primary example of this
|
|
28
|
-
* pattern is when the disabled button is in a menu or a commandbar and is seldom used for standalone buttons.
|
|
29
|
-
*
|
|
30
|
-
* @default false
|
|
31
|
-
*/
|
|
32
|
-
disabledFocusable?: boolean;
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Merge of props provided by the user and props provided internally.
|
|
37
|
-
*/
|
|
38
|
-
export declare type ARIAButtonResultProps<Type extends ARIAButtonType, Props> = Props & UnionToIntersection<ARIAButtonAlteredProps<Type>>;
|
|
39
|
-
|
|
40
|
-
export declare type ARIAButtonSlotProps<AlternateAs extends 'a' | 'div' = 'a' | 'div'> = ExtractSlotProps<Slot<'button', AlternateAs>> & Pick<ARIAButtonProps<ARIAButtonType>, 'disabled' | 'disabledFocusable'>;
|
|
41
|
-
|
|
42
|
-
export declare type ARIAButtonType = 'button' | 'a' | 'div';
|
|
43
|
-
|
|
44
|
-
declare type UnionToIntersection<U> = (U extends unknown ? (x: U) => U : never) extends (x: infer I) => U ? I : never;
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* @internal
|
|
48
|
-
*
|
|
49
|
-
* Button keyboard handling, role, disabled and tabIndex implementation that ensures ARIA spec
|
|
50
|
-
* for multiple scenarios of non native button elements. Ensuring 1st rule of ARIA for cases
|
|
51
|
-
* where no attribute addition is required.
|
|
52
|
-
*
|
|
53
|
-
* @param type - the proper scenario to be interpreted by the hook.
|
|
54
|
-
* 1. `button` - Minimal interference from the hook, as semantic button already supports most of the states
|
|
55
|
-
* 2. `a` or `div` - Proper keyboard/mouse handling plus other support to ensure ARIA behavior
|
|
56
|
-
* @param props - the props to be passed down the line to the desired element.
|
|
57
|
-
* This hook will encapsulate proper properties, such as `onClick`, `onKeyDown`, `onKeyUp`, etc,.
|
|
58
|
-
*
|
|
59
|
-
* @example
|
|
60
|
-
* ```tsx
|
|
61
|
-
* const buttonProps = useARIAButtonProps('a', {
|
|
62
|
-
* href: './some-route'
|
|
63
|
-
* onClick: () => console.log('this should run both on click and Space and Enter')
|
|
64
|
-
* })
|
|
65
|
-
*
|
|
66
|
-
* // ...
|
|
67
|
-
*
|
|
68
|
-
* return (
|
|
69
|
-
* <a {...buttonProps}>This anchor will behave as a proper button</a>
|
|
70
|
-
* )
|
|
71
|
-
* ```
|
|
72
|
-
*/
|
|
73
|
-
export declare function useARIAButtonProps<Type extends ARIAButtonType, Props extends ARIAButtonProps<Type>>(type?: Type, props?: Props): ARIAButtonResultProps<Type, Props>;
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* @internal
|
|
77
|
-
*
|
|
78
|
-
* This function expects to receive a slot, if `as` property is not desired use `useARIAButtonProps` instead
|
|
79
|
-
*
|
|
80
|
-
* Button keyboard handling, role, disabled and tabIndex implementation that ensures ARIA spec
|
|
81
|
-
* for multiple scenarios of shorthand properties. Ensuring 1st rule of ARIA for cases
|
|
82
|
-
* where no attribute addition is required.
|
|
83
|
-
*/
|
|
84
|
-
export declare const useARIAButtonShorthand: ResolveShorthandFunction<ARIAButtonSlotProps>;
|
|
85
|
-
|
|
86
|
-
export { }
|
package/lib/button/index.js
DELETED
package/lib/button/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["../../src/button/index.ts"],"sourcesContent":["export * from './useARIAButtonProps';\nexport * from './useARIAButtonShorthand';\nexport * from './types';\n"],"mappings":"AAAA,cAAc;AACd,cAAc;AACd,cAAc"}
|
package/lib/button/types.js
DELETED
package/lib/button/types.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["React"],"sources":["../../src/button/types.ts"],"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\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 * 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"],"mappings":"AACA,YAAYA,KAAA,MAAW"}
|
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
import { Enter, Space } from '@fluentui/keyboard-keys';
|
|
2
|
-
import { useEventCallback } from '@fluentui/react-utilities';
|
|
3
|
-
import * as React from 'react';
|
|
4
|
-
/**
|
|
5
|
-
* @internal
|
|
6
|
-
*
|
|
7
|
-
* Button keyboard handling, role, disabled and tabIndex implementation that ensures ARIA spec
|
|
8
|
-
* for multiple scenarios of non native button elements. Ensuring 1st rule of ARIA for cases
|
|
9
|
-
* where no attribute addition is required.
|
|
10
|
-
*
|
|
11
|
-
* @param type - the proper scenario to be interpreted by the hook.
|
|
12
|
-
* 1. `button` - Minimal interference from the hook, as semantic button already supports most of the states
|
|
13
|
-
* 2. `a` or `div` - Proper keyboard/mouse handling plus other support to ensure ARIA behavior
|
|
14
|
-
* @param props - the props to be passed down the line to the desired element.
|
|
15
|
-
* This hook will encapsulate proper properties, such as `onClick`, `onKeyDown`, `onKeyUp`, etc,.
|
|
16
|
-
*
|
|
17
|
-
* @example
|
|
18
|
-
* ```tsx
|
|
19
|
-
* const buttonProps = useARIAButtonProps('a', {
|
|
20
|
-
* href: './some-route'
|
|
21
|
-
* onClick: () => console.log('this should run both on click and Space and Enter')
|
|
22
|
-
* })
|
|
23
|
-
*
|
|
24
|
-
* // ...
|
|
25
|
-
*
|
|
26
|
-
* return (
|
|
27
|
-
* <a {...buttonProps}>This anchor will behave as a proper button</a>
|
|
28
|
-
* )
|
|
29
|
-
* ```
|
|
30
|
-
*/
|
|
31
|
-
export function useARIAButtonProps(type, props) {
|
|
32
|
-
const {
|
|
33
|
-
disabled,
|
|
34
|
-
disabledFocusable = false,
|
|
35
|
-
['aria-disabled']: ariaDisabled,
|
|
36
|
-
onClick,
|
|
37
|
-
onKeyDown,
|
|
38
|
-
onKeyUp,
|
|
39
|
-
...rest
|
|
40
|
-
} = props !== null && props !== void 0 ? props : {};
|
|
41
|
-
const normalizedARIADisabled = typeof ariaDisabled === 'string' ? ariaDisabled === 'true' : ariaDisabled;
|
|
42
|
-
const isDisabled = disabled || disabledFocusable || normalizedARIADisabled;
|
|
43
|
-
const handleClick = useEventCallback(ev => {
|
|
44
|
-
if (isDisabled) {
|
|
45
|
-
ev.preventDefault();
|
|
46
|
-
ev.stopPropagation();
|
|
47
|
-
} else {
|
|
48
|
-
onClick === null || onClick === void 0 ? void 0 : onClick(ev);
|
|
49
|
-
}
|
|
50
|
-
});
|
|
51
|
-
const handleKeyDown = useEventCallback(ev => {
|
|
52
|
-
onKeyDown === null || onKeyDown === void 0 ? void 0 : onKeyDown(ev);
|
|
53
|
-
if (ev.isDefaultPrevented()) {
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
const key = ev.key;
|
|
57
|
-
if (isDisabled && (key === Enter || key === Space)) {
|
|
58
|
-
ev.preventDefault();
|
|
59
|
-
ev.stopPropagation();
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
if (key === Space) {
|
|
63
|
-
ev.preventDefault();
|
|
64
|
-
return;
|
|
65
|
-
} else if (key === Enter) {
|
|
66
|
-
ev.preventDefault();
|
|
67
|
-
ev.currentTarget.click();
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
const handleKeyUp = useEventCallback(ev => {
|
|
71
|
-
onKeyUp === null || onKeyUp === void 0 ? void 0 : onKeyUp(ev);
|
|
72
|
-
if (ev.isDefaultPrevented()) {
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
const key = ev.key;
|
|
76
|
-
if (isDisabled && (key === Enter || key === Space)) {
|
|
77
|
-
ev.preventDefault();
|
|
78
|
-
ev.stopPropagation();
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
81
|
-
if (key === Space) {
|
|
82
|
-
ev.preventDefault();
|
|
83
|
-
ev.currentTarget.click();
|
|
84
|
-
}
|
|
85
|
-
});
|
|
86
|
-
// If a <button> tag is to be rendered we just need to set disabled and aria-disabled correctly
|
|
87
|
-
if (type === 'button' || type === undefined) {
|
|
88
|
-
return {
|
|
89
|
-
...rest,
|
|
90
|
-
disabled: disabled && !disabledFocusable,
|
|
91
|
-
'aria-disabled': disabledFocusable ? true : normalizedARIADisabled,
|
|
92
|
-
// onclick should still use internal handler to ensure prevention if disabled
|
|
93
|
-
// if disabledFocusable then there's no requirement for handlers as those events should not be propagated
|
|
94
|
-
onClick: disabledFocusable ? undefined : handleClick,
|
|
95
|
-
onKeyUp: disabledFocusable ? undefined : onKeyUp,
|
|
96
|
-
onKeyDown: disabledFocusable ? undefined : onKeyDown
|
|
97
|
-
};
|
|
98
|
-
} else {
|
|
99
|
-
const resultProps = {
|
|
100
|
-
role: 'button',
|
|
101
|
-
tabIndex: disabled && !disabledFocusable ? undefined : 0,
|
|
102
|
-
...rest,
|
|
103
|
-
// If it's not a <button> than listeners are required even with disabledFocusable
|
|
104
|
-
// Since you cannot assure the default behavior of the element
|
|
105
|
-
// E.g: <a> will redirect on click
|
|
106
|
-
onClick: handleClick,
|
|
107
|
-
onKeyUp: handleKeyUp,
|
|
108
|
-
onKeyDown: handleKeyDown,
|
|
109
|
-
'aria-disabled': disabled || disabledFocusable || normalizedARIADisabled
|
|
110
|
-
};
|
|
111
|
-
if (type === 'a' && isDisabled) {
|
|
112
|
-
resultProps.href = undefined;
|
|
113
|
-
}
|
|
114
|
-
return resultProps;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
//# sourceMappingURL=useARIAButtonProps.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["Enter","Space","useEventCallback","React","useARIAButtonProps","type","props","disabled","disabledFocusable","ariaDisabled","onClick","onKeyDown","onKeyUp","rest","normalizedARIADisabled","isDisabled","handleClick","ev","preventDefault","stopPropagation","handleKeyDown","isDefaultPrevented","key","currentTarget","click","handleKeyUp","undefined","resultProps","role","tabIndex","href"],"sources":["../../src/button/useARIAButtonProps.ts"],"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 disabledFocusable = false,\n ['aria-disabled']: ariaDisabled,\n onClick,\n onKeyDown,\n onKeyUp,\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 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"],"mappings":"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"}
|
|
@@ -1,18 +0,0 @@
|
|
|
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
|
-
export const useARIAButtonShorthand = (slot, options) => {
|
|
13
|
-
const shorthand = resolveShorthand(slot, options);
|
|
14
|
-
var _shorthand_as;
|
|
15
|
-
const shorthandARIAButton = useARIAButtonProps((_shorthand_as = shorthand === null || shorthand === void 0 ? void 0 : shorthand.as) !== null && _shorthand_as !== void 0 ? _shorthand_as : 'button', shorthand);
|
|
16
|
-
return shorthand && shorthandARIAButton;
|
|
17
|
-
};
|
|
18
|
-
//# sourceMappingURL=useARIAButtonShorthand.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["resolveShorthand","useARIAButtonProps","useARIAButtonShorthand","slot","options","shorthand","_shorthand_as","shorthandARIAButton","as"],"sources":["../../src/button/useARIAButtonShorthand.ts"],"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"],"mappings":"AAAA,SAASA,gBAAgB,QAAQ;AACjC,SAASC,kBAAkB,QAAQ;AAInC;;;;;;;;;AASA,OAAO,MAAMC,sBAAA,GAAwEA,CAACC,IAAA,EAAMC,OAAA,KAAY;EACtG,MAAMC,SAAA,GAAYL,gBAAA,CAAiBG,IAAA,EAAMC,OAAA;MACuCE,aAAA;EAAhF,MAAMC,mBAAA,GAAsBN,kBAAA,CAAoD,CAAAK,aAAA,GAAAD,SAAA,aAAAA,SAAA,uBAAAA,SAAA,CAAWG,EAAE,cAAbF,aAAA,cAAAA,aAAA,GAAiB,QAAQ,EAAED,SAAA;EAC3G,OAAOA,SAAA,IAAaE,mBAAA;AACtB"}
|
package/lib/index.js
DELETED
package/lib/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["useARIAButtonShorthand","useARIAButtonProps"],"sources":["../src/index.ts"],"sourcesContent":["export { useARIAButtonShorthand, useARIAButtonProps } from './button/index';\nexport type {\n ARIAButtonSlotProps,\n ARIAButtonProps,\n ARIAButtonResultProps,\n ARIAButtonType,\n ARIAButtonElement,\n ARIAButtonElementIntersection,\n ARIAButtonAlteredProps,\n} from './button/index';\n"],"mappings":"AAAA,SAASA,sBAAsB,EAAEC,kBAAkB,QAAQ"}
|