|
1 | 1 | import { Enter, Space } from '@fluentui/keyboard-keys'; |
2 | | -import { resolveShorthand, useEventCallback } from '@fluentui/react-utilities'; |
3 | | -import type { ExtractSlotProps, ResolveShorthandFunction, Slot } from '@fluentui/react-utilities'; |
4 | | -import * as React from 'react'; |
5 | | - |
6 | | -export type ARIAButtonType = 'button' | 'a' | 'div'; |
7 | | - |
8 | | -/** |
9 | | - * Props expected by `useARIAButtonProps` hooks |
10 | | - */ |
11 | | -export type ARIAButtonProps<Type extends ARIAButtonType = ARIAButtonType> = React.PropsWithRef< |
12 | | - JSX.IntrinsicElements[Type] |
13 | | -> & { |
14 | | - disabled?: boolean; |
15 | | - /** |
16 | | - * When set, allows the button to be focusable even when it has been disabled. |
17 | | - * This is used in scenarios where it is important to keep a consistent tab order |
18 | | - * for screen reader and keyboard users. The primary example of this |
19 | | - * pattern is when the disabled button is in a menu or a commandbar and is seldom used for standalone buttons. |
20 | | - * |
21 | | - * @default false |
22 | | - */ |
23 | | - disabledFocusable?: boolean; |
24 | | -}; |
25 | | - |
26 | | -export type ARIAButtonSlotProps<AlternateAs extends 'a' | 'div' = 'a' | 'div'> = ExtractSlotProps< |
27 | | - Slot<'button', AlternateAs> |
28 | | -> & |
29 | | - Pick<ARIAButtonProps<ARIAButtonType>, 'disabled' | 'disabledFocusable'>; |
30 | | - |
31 | | -/** |
32 | | - * @internal |
33 | | - * Props that will be modified internally by `useARIAButtonProps` by each case. |
34 | | - * This typing is to ensure a well specified return value for `useARIAbButtonProps` |
35 | | - */ |
36 | | -type ARIAButtonAlteredProps<Type extends ARIAButtonType> = |
37 | | - | (Type extends 'button' |
38 | | - ? Pick< |
39 | | - JSX.IntrinsicElements['button'], |
40 | | - 'onClick' | 'onKeyDown' | 'onKeyUp' | 'disabled' | 'aria-disabled' | 'tabIndex' |
41 | | - > |
42 | | - : never) |
43 | | - | (Type extends 'a' |
44 | | - ? Pick< |
45 | | - JSX.IntrinsicElements['a'], |
46 | | - 'onClick' | 'onKeyDown' | 'onKeyUp' | 'aria-disabled' | 'tabIndex' | 'role' | 'href' |
47 | | - > |
48 | | - : never) |
49 | | - | (Type extends 'div' |
50 | | - ? Pick<JSX.IntrinsicElements['div'], 'onClick' | 'onKeyDown' | 'onKeyUp' | 'aria-disabled' | 'tabIndex' | 'role'> |
51 | | - : never); |
52 | | - |
53 | | -type UnionToIntersection<U> = (U extends unknown ? (x: U) => U : never) extends (x: infer I) => U ? I : never; |
54 | | - |
55 | | -/** |
56 | | - * Merge of props provided by the user and props provided internally. |
57 | | - */ |
58 | | -export type ARIAButtonResultProps<Type extends ARIAButtonType, Props> = Props & |
59 | | - UnionToIntersection<ARIAButtonAlteredProps<Type>>; |
| 2 | +import { useEventCallback } from '@fluentui/react-utilities'; |
| 3 | +import type { ARIAButtonProps, ARIAButtonResultProps, ARIAButtonType } from './types'; |
60 | 4 |
|
61 | 5 | /** |
62 | 6 | * @internal |
@@ -199,18 +143,3 @@ export function useARIAButtonProps<Type extends ARIAButtonType, Props extends AR |
199 | 143 | return resultProps; |
200 | 144 | } |
201 | 145 | } |
202 | | - |
203 | | -/** |
204 | | - * @internal |
205 | | - * |
206 | | - * This function expects to receive a slot, if `as` property is not desired use `useARIAButtonProps` instead |
207 | | - * |
208 | | - * Button keyboard handling, role, disabled and tabIndex implementation that ensures ARIA spec |
209 | | - * for multiple scenarios of shorthand properties. Ensuring 1st rule of ARIA for cases |
210 | | - * where no attribute addition is required. |
211 | | - */ |
212 | | -export const useARIAButtonShorthand: ResolveShorthandFunction<ARIAButtonSlotProps> = (slot, options) => { |
213 | | - const shorthand = resolveShorthand(slot, options); |
214 | | - const shorthandARIAButton = useARIAButtonProps<ARIAButtonType, ARIAButtonProps>(shorthand?.as ?? 'button', shorthand); |
215 | | - return shorthand && shorthandARIAButton; |
216 | | -}; |
0 commit comments