Skip to content

Commit 4dad5d7

Browse files
authored
feat: deprecates useARIAButtonShorthand in favor of useARIAButtonProps (#29735)
1 parent 8012cdf commit 4dad5d7

13 files changed

+93
-68
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "patch",
3+
"comment": "chore: adopts useARIAButtonProps instead of deprecated method useARIAButtonShorthand",
4+
"packageName": "@fluentui/react-accordion",
5+
"email": "[email protected]",
6+
"dependentChangeType": "patch"
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "minor",
3+
"comment": "feat: deprecates useARIAButtonShorthand in favor of useARIAButtonProps",
4+
"packageName": "@fluentui/react-aria",
5+
"email": "[email protected]",
6+
"dependentChangeType": "patch"
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "patch",
3+
"comment": "chore: adopts useARIAButtonProps instead of deprecated method useARIAButtonShorthand",
4+
"packageName": "@fluentui/react-button",
5+
"email": "[email protected]",
6+
"dependentChangeType": "patch"
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "patch",
3+
"comment": "chore: adopts useARIAButtonProps instead of deprecated method useARIAButtonShorthand",
4+
"packageName": "@fluentui/react-table",
5+
"email": "[email protected]",
6+
"dependentChangeType": "patch"
7+
}

packages/react-components/react-accordion/src/components/AccordionHeader/useAccordionHeader.tsx

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as React from 'react';
2-
import { getIntrinsicElementProps, isResolvedShorthand, useEventCallback, slot } from '@fluentui/react-utilities';
3-
import { ARIAButtonSlotProps, useARIAButtonShorthand } from '@fluentui/react-aria';
2+
import { getIntrinsicElementProps, useEventCallback, slot, isResolvedShorthand } from '@fluentui/react-utilities';
3+
import { useARIAButtonProps } from '@fluentui/react-aria';
44
import type { AccordionHeaderProps, AccordionHeaderState } from './AccordionHeader.types';
55
import { useAccordionContext_unstable } from '../../contexts/accordion';
66
import { ChevronRightRegular } from '@fluentui/react-icons';
@@ -38,6 +38,25 @@ export const useAccordionHeader_unstable = (
3838
expandIconRotation = open ? 90 : dir !== 'rtl' ? 0 : 180;
3939
}
4040

41+
const buttonSlot = slot.always(button, {
42+
elementType: 'button',
43+
defaultProps: {
44+
disabled,
45+
disabledFocusable,
46+
'aria-expanded': open,
47+
type: 'button',
48+
},
49+
});
50+
51+
buttonSlot.onClick = useEventCallback(event => {
52+
if (isResolvedShorthand(button)) {
53+
button.onClick?.(event);
54+
}
55+
if (!event.defaultPrevented) {
56+
requestToggle({ value, event });
57+
}
58+
});
59+
4160
return {
4261
disabled,
4362
open,
@@ -69,27 +88,6 @@ export const useAccordionHeader_unstable = (
6988
},
7089
elementType: 'span',
7190
}),
72-
button: slot.always<ARIAButtonSlotProps<'a'>>(
73-
{
74-
...useARIAButtonShorthand(button, {
75-
required: true,
76-
defaultProps: {
77-
disabled,
78-
disabledFocusable,
79-
'aria-expanded': open,
80-
type: 'button',
81-
},
82-
}),
83-
onClick: useEventCallback(event => {
84-
if (isResolvedShorthand(button)) {
85-
button.onClick?.(event);
86-
}
87-
if (!event.defaultPrevented) {
88-
requestToggle({ value, event });
89-
}
90-
}),
91-
},
92-
{ elementType: 'button' },
93-
),
91+
button: useARIAButtonProps(buttonSlot.as, buttonSlot),
9492
};
9593
};

packages/react-components/react-aria/etc/react-aria.api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export function useActiveDescendant<TActiveParentElement extends HTMLElement, TL
6666
// @internal
6767
export function useARIAButtonProps<Type extends ARIAButtonType, Props extends ARIAButtonProps<Type>>(type?: Type, props?: Props): ARIAButtonResultProps<Type, Props>;
6868

69-
// @internal
69+
// @internal @deprecated (undocumented)
7070
export const useARIAButtonShorthand: ResolveShorthandFunction<ARIAButtonSlotProps>;
7171

7272
// (No @packageDocumentation comment for this package)

packages/react-components/react-aria/src/button/useARIAButtonProps.test.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@ import { renderHook } from '@testing-library/react-hooks';
44
import { fireEvent, render } from '@testing-library/react';
55
import { getSlots, Slot, ComponentProps } from '@fluentui/react-utilities';
66
import { ARIAButtonProps, ARIAButtonSlotProps } from './types';
7-
import { useARIAButtonShorthand } from './useARIAButtonShorthand';
87

98
const TestButton = (props: ComponentProps<{ root: Slot<ARIAButtonSlotProps> }>) => {
109
const { slots, slotProps } = getSlots<{ root: Slot<ARIAButtonSlotProps> }>({
1110
components: { root: 'button' },
12-
root: useARIAButtonShorthand(props, { required: true }),
11+
root: useARIAButtonProps(props.as, props),
1312
});
1413
return <slots.root {...slotProps.root} />;
1514
};

packages/react-components/react-aria/src/button/useARIAButtonShorthand.test.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,22 @@ describe('useARIAButtonShorthands', () => {
55
it('should return shorthands', () => {
66
const {
77
result: { current: buttonShorthand },
8+
// eslint-disable-next-line deprecation/deprecation
89
} = renderHook(() => useARIAButtonShorthand({ as: 'button' }, { required: true }));
910
expect(buttonShorthand.as).toBe('button');
1011
const {
1112
result: { current: buttonShorthand2 },
13+
// eslint-disable-next-line deprecation/deprecation
1214
} = renderHook(() => useARIAButtonShorthand({ as: undefined }, { required: true }));
1315
expect(buttonShorthand2.as).toBe(undefined);
1416
const {
1517
result: { current: anchorShorthand },
18+
// eslint-disable-next-line deprecation/deprecation
1619
} = renderHook(() => useARIAButtonShorthand({ as: 'a' }, { required: true }));
1720
expect(anchorShorthand.as).toBe('a');
1821
const {
1922
result: { current: divShorthand },
23+
// eslint-disable-next-line deprecation/deprecation
2024
} = renderHook(() => useARIAButtonShorthand({ as: 'div' }, { required: true }));
2125
expect(divShorthand.as).toBe('div');
2226
});

packages/react-components/react-aria/src/button/useARIAButtonShorthand.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import type { ARIAButtonProps, ARIAButtonSlotProps, ARIAButtonType } from './typ
66
/**
77
* @internal
88
*
9+
* @deprecated use useARIAButtonProps instead
10+
*
911
* This function expects to receive a slot, if `as` property is not desired use `useARIAButtonProps` instead
1012
*
1113
* Button keyboard handling, role, disabled and tabIndex implementation that ensures ARIA spec

packages/react-components/react-aria/src/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
export { useARIAButtonShorthand, useARIAButtonProps } from './button/index';
1+
export {
2+
// eslint-disable-next-line deprecation/deprecation
3+
useARIAButtonShorthand,
4+
useARIAButtonProps,
5+
} from './button/index';
26
export { useActiveDescendant } from './activedescendant';
37
export type { ActiveDescendantImperativeRef, ActiveDescendantOptions } from './activedescendant';
48
export type {

packages/react-components/react-aria/stories/useARIAButton/index.stories.tsx

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as React from 'react';
2-
import { useARIAButtonShorthand } from '../../src/button';
2+
import { useARIAButtonProps } from '../../src/button';
33
import type { ARIAButtonSlotProps } from '../../src/button';
44
import { getSlots } from '@fluentui/react-components';
55
import type { ComponentState, Slot } from '@fluentui/react-components';
@@ -20,7 +20,7 @@ export const Default = (args: DefaultArgs) => {
2020
components: { root: 'div', button: 'button' },
2121
root: {},
2222
button: {
23-
...useARIAButtonShorthand({ as: 'button', onClick: args.onClick }, { required: true }),
23+
...useARIAButtonProps('button', { as: 'button', onClick: args.onClick } as const),
2424
children: React.Fragment,
2525
},
2626
};
@@ -36,17 +36,14 @@ export const Anchor = (args: DefaultArgs) => {
3636
type AnchorSlots = {
3737
root: ARIAButtonSlotProps;
3838
};
39-
const props = useARIAButtonShorthand(
40-
{
41-
as: 'a',
42-
href: '/',
43-
onClick: ev => {
44-
ev.preventDefault();
45-
args.onClick(ev);
46-
},
39+
const props = useARIAButtonProps('a', {
40+
as: 'a',
41+
href: '/',
42+
onClick: ev => {
43+
ev.preventDefault();
44+
args.onClick(ev);
4745
},
48-
{ required: true },
49-
);
46+
} as const);
5047
const { slots, slotProps } = getSlots<AnchorSlots>({
5148
components: { root: 'a' },
5249
root: props,

packages/react-components/react-button/src/components/Button/useButton.ts

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as React from 'react';
2-
import { ARIAButtonSlotProps, useARIAButtonShorthand } from '@fluentui/react-aria';
2+
import { ARIAButtonSlotProps, useARIAButtonProps } from '@fluentui/react-aria';
33
import { getIntrinsicElementProps, slot } from '@fluentui/react-utilities';
44
import { useButtonContext } from '../../contexts/ButtonContext';
55
import type { ButtonProps, ButtonState } from './Button.types';
@@ -35,19 +35,13 @@ export const useButton_unstable = (
3535
size, // State calculated from a set of props
3636
iconOnly: Boolean(iconShorthand?.children && !props.children), // Slots definition
3737
components: { root: 'button', icon: 'span' },
38-
root: slot.always(
39-
getIntrinsicElementProps(
40-
as,
41-
useARIAButtonShorthand<ARIAButtonSlotProps<'a'>>(props, {
42-
required: true,
43-
defaultProps: {
44-
ref: ref as React.Ref<HTMLButtonElement & HTMLAnchorElement>,
45-
type: 'button',
46-
},
47-
}),
48-
),
49-
{ elementType: 'button' },
50-
),
38+
root: slot.always<ARIAButtonSlotProps<'a'>>(getIntrinsicElementProps(as, useARIAButtonProps(props.as, props)), {
39+
elementType: 'button',
40+
defaultProps: {
41+
ref: ref as React.Ref<HTMLButtonElement & HTMLAnchorElement>,
42+
type: 'button',
43+
},
44+
}),
5145
icon: iconShorthand,
5246
};
5347
};

packages/react-components/react-table/src/components/TableHeaderCell/useTableHeaderCell.tsx

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as React from 'react';
22
import { getIntrinsicElementProps, useMergedRefs, slot } from '@fluentui/react-utilities';
33
import { useFocusWithin } from '@fluentui/react-tabster';
44
import { ArrowUpRegular, ArrowDownRegular } from '@fluentui/react-icons';
5-
import { useARIAButtonShorthand } from '@fluentui/react-aria';
5+
import { ARIAButtonSlotProps, useARIAButtonProps } from '@fluentui/react-aria';
66
import type { TableHeaderCellProps, TableHeaderCellState } from './TableHeaderCell.types';
77
import { useTableContext } from '../../contexts/tableContext';
88

@@ -29,6 +29,17 @@ export const useTableHeaderCell_unstable = (
2929

3030
const rootComponent = props.as ?? noNativeElements ? 'div' : 'th';
3131

32+
const buttonSlot = slot.always<ARIAButtonSlotProps>(props.button, {
33+
elementType: 'div',
34+
defaultProps: {
35+
as: 'div',
36+
...(!sortable && {
37+
role: 'presentation',
38+
tabIndex: undefined,
39+
}),
40+
},
41+
});
42+
3243
return {
3344
components: {
3445
root: rootComponent,
@@ -54,19 +65,7 @@ export const useTableHeaderCell_unstable = (
5465
defaultProps: { children: props.sortDirection ? sortIcons[props.sortDirection] : undefined },
5566
elementType: 'span',
5667
}),
57-
button: slot.always(
58-
useARIAButtonShorthand(props.button, {
59-
required: true,
60-
defaultProps: {
61-
as: 'div',
62-
...(!sortable && {
63-
role: 'presentation',
64-
tabIndex: undefined,
65-
}),
66-
},
67-
}),
68-
{ elementType: 'div' },
69-
),
68+
button: useARIAButtonProps(buttonSlot.as, buttonSlot),
7069
sortable,
7170
noNativeElements,
7271
};

0 commit comments

Comments
 (0)