Skip to content

Commit 07befbd

Browse files
committed
fix: align button ref types with underlying elements to fix TS errors
1 parent afd1d2b commit 07befbd

23 files changed

Lines changed: 39 additions & 29 deletions

packages/ra-ui-materialui/src/button/BulkDeleteButton.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import {
3636
*/
3737
export const BulkDeleteButton = React.forwardRef(function BulkDeleteButton(
3838
inProps: BulkDeleteButtonProps,
39-
ref: React.ForwardedRef<HTMLElement>
39+
ref: React.ForwardedRef<HTMLButtonElement>
4040
) {
4141
const { mutationMode = 'undoable', ...props } = useThemeProps({
4242
name: PREFIX,

packages/ra-ui-materialui/src/button/BulkDeleteWithConfirmButton.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import { humanize, inflect } from 'inflection';
2323
export const BulkDeleteWithConfirmButton = React.forwardRef(
2424
function BulkDeleteWithConfirmButton(
2525
inProps: BulkDeleteWithConfirmButtonProps,
26-
ref: React.ForwardedRef<HTMLElement>
26+
ref: React.ForwardedRef<HTMLButtonElement>
2727
) {
2828
const props = useThemeProps({
2929
props: inProps,

packages/ra-ui-materialui/src/button/BulkDeleteWithUndoButton.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { Button, type ButtonProps } from './Button';
1616
export const BulkDeleteWithUndoButton = React.forwardRef(
1717
function BulkDeleteWithUndoButton(
1818
inProps: BulkDeleteWithUndoButtonProps,
19-
ref: React.ForwardedRef<HTMLElement>
19+
ref: React.ForwardedRef<HTMLButtonElement>
2020
) {
2121
const props = useThemeProps({
2222
props: inProps,

packages/ra-ui-materialui/src/button/BulkExportButton.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ import { Button, ButtonProps } from './Button';
3939
*/
4040
export const BulkExportButton = React.forwardRef(function BulkExportButton(
4141
inProps: BulkExportButtonProps,
42-
ref: React.ForwardedRef<HTMLElement>
42+
ref: React.ForwardedRef<HTMLButtonElement>
4343
) {
4444
const props = useThemeProps({
4545
props: inProps,

packages/ra-ui-materialui/src/button/BulkUpdateButton.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import {
3636
*/
3737
export const BulkUpdateButton = React.forwardRef(function BulkUpdateButton(
3838
props: BulkUpdateButtonProps,
39-
ref: React.ForwardedRef<HTMLElement>
39+
ref: React.ForwardedRef<HTMLButtonElement>
4040
) {
4141
const {
4242
mutationMode = 'undoable',

packages/ra-ui-materialui/src/button/BulkUpdateWithConfirmButton.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import { humanize, inflect } from 'inflection';
2222
export const BulkUpdateWithConfirmButton = React.forwardRef(
2323
function BulkUpdateWithConfirmButton(
2424
inProps: BulkUpdateWithConfirmButtonProps,
25-
ref: React.ForwardedRef<HTMLElement>
25+
ref: React.ForwardedRef<HTMLButtonElement>
2626
) {
2727
const props = useThemeProps({
2828
props: inProps,

packages/ra-ui-materialui/src/button/BulkUpdateWithUndoButton.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { Button, type ButtonProps } from './Button';
1616
export const BulkUpdateWithUndoButton = React.forwardRef(
1717
function BulkUpdateWithUndoButton(
1818
inProps: BulkUpdateWithUndoButtonProps,
19-
ref: React.ForwardedRef<HTMLElement>
19+
ref: React.ForwardedRef<HTMLButtonElement>
2020
) {
2121
const props = useThemeProps({
2222
props: inProps,

packages/ra-ui-materialui/src/button/Button.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,16 @@ import { Path, To } from 'react-router';
2929
*
3030
*/
3131
type ButtonComponent = <RootComponent extends React.ElementType = 'button'>(
32-
props: ButtonProps<RootComponent> & React.RefAttributes<HTMLElement>
32+
props: ButtonProps<RootComponent> &
33+
React.RefAttributes<HTMLButtonElement | HTMLAnchorElement>
3334
) => React.ReactElement | null;
3435

3536
export const Button = React.forwardRef(function Button<
3637
RootComponent extends React.ElementType = 'button',
37-
>(inProps: ButtonProps<RootComponent>, ref: React.ForwardedRef<HTMLElement>) {
38+
>(
39+
inProps: ButtonProps<RootComponent>,
40+
ref: React.ForwardedRef<HTMLButtonElement | HTMLAnchorElement>
41+
) {
3842
const props = useThemeProps({ props: inProps, name: PREFIX });
3943
const {
4044
alignIcon = 'left',
@@ -65,7 +69,7 @@ export const Button = React.forwardRef(function Button<
6569
label && !disabled ? (
6670
<Tooltip title={translatedLabel}>
6771
<IconButton
68-
ref={ref}
72+
ref={ref as React.Ref<HTMLButtonElement>}
6973
// If users provide a ReactNode as label, its their responsibility to also provide an aria-label should they need it
7074
aria-label={
7175
typeof translatedLabel === 'string'
@@ -83,7 +87,7 @@ export const Button = React.forwardRef(function Button<
8387
</Tooltip>
8488
) : (
8589
<IconButton
86-
ref={ref}
90+
ref={ref as React.Ref<HTMLButtonElement>}
8791
className={className}
8892
color={color}
8993
disabled={disabled}
@@ -96,7 +100,7 @@ export const Button = React.forwardRef(function Button<
96100
)
97101
) : (
98102
<StyledButton
99-
ref={ref}
103+
ref={ref as React.Ref<HTMLButtonElement>}
100104
className={className}
101105
color={color}
102106
size={size}

packages/ra-ui-materialui/src/button/CloneButton.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { Button, ButtonProps } from './Button';
1414

1515
export const CloneButton = React.forwardRef(function CloneButton(
1616
inProps: CloneButtonProps,
17-
ref: React.ForwardedRef<HTMLElement>
17+
ref: React.ForwardedRef<HTMLAnchorElement>
1818
) {
1919
const props = useThemeProps({
2020
props: inProps,

packages/ra-ui-materialui/src/button/CreateButton.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import { Button, type ButtonProps, type LocationDescriptor } from './Button';
3535
*/
3636
const CreateButton = React.forwardRef(function CreateButton(
3737
inProps: CreateButtonProps,
38-
ref: React.ForwardedRef<HTMLElement>
38+
ref: React.ForwardedRef<HTMLAnchorElement>
3939
) {
4040
const props = useThemeProps({
4141
props: inProps,

0 commit comments

Comments
 (0)