Skip to content

Commit afae825

Browse files
committed
fix(Button): fix button prop inference when using as prop
1 parent e7c07da commit afae825

File tree

1 file changed

+14
-16
lines changed

1 file changed

+14
-16
lines changed

src/Button.tsx

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as React from 'react';
2+
import type { DynamicRefForwardingComponent } from './types.js';
23

34
export type ButtonType = 'button' | 'reset' | 'submit';
45

@@ -108,7 +109,7 @@ export function useButtonProps({
108109
];
109110
}
110111

111-
export interface BaseButtonProps {
112+
export interface ButtonProps extends React.ButtonHTMLAttributes<HTMLElement> {
112113
/**
113114
* Control the underlying rendered element directly by passing in a valid
114115
* component type
@@ -127,21 +128,18 @@ export interface BaseButtonProps {
127128
rel?: string | undefined;
128129
}
129130

130-
export interface ButtonProps
131-
extends BaseButtonProps,
132-
React.ComponentPropsWithoutRef<'button'> {}
133-
134-
const Button = React.forwardRef<HTMLElement, ButtonProps>(
135-
({ as: asProp, disabled, ...props }, ref) => {
136-
const [buttonProps, { tagName: Component }] = useButtonProps({
137-
tagName: asProp,
138-
disabled,
139-
...props,
140-
});
141-
142-
return <Component {...props} {...buttonProps} ref={ref} />;
143-
},
144-
);
131+
const Button: DynamicRefForwardingComponent<'button', ButtonProps> =
132+
React.forwardRef<HTMLElement, ButtonProps>(
133+
({ as: asProp, disabled, ...props }, ref) => {
134+
const [buttonProps, { tagName: Component }] = useButtonProps({
135+
tagName: asProp,
136+
disabled,
137+
...props,
138+
});
139+
140+
return <Component {...props} {...buttonProps} ref={ref} />;
141+
},
142+
);
145143

146144
Button.displayName = 'Button';
147145

0 commit comments

Comments
 (0)