Skip to content

Commit 154f227

Browse files
committed
Fix type definiton for onClick
1 parent 22a8020 commit 154f227

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

packages/for-ui/src/button/Button.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Children, ElementType, FC, forwardRef, MouseEvent, ReactNode, useMemo } from 'react';
1+
import { Children, ElementType, FC, forwardRef, MouseEvent, MouseEventHandler, ReactNode, useMemo } from 'react';
22
import MuiButton, { ButtonUnstyledProps as MuiButtonProps } from '@mui/base/ButtonUnstyled';
33
import { LoadingButtonProps } from '@mui/lab/LoadingButton';
44
import { Loader } from '../loader';
@@ -10,7 +10,7 @@ import { walkChildren } from '../system/walkChildren';
1010
type Child = Exclude<ReactNode, Iterable<ReactNode>> | string;
1111

1212
export type ButtonProps<As extends ElementType = 'button'> = ComponentProps<
13-
Omit<MuiButtonProps<As>, 'href' | 'children'> & {
13+
Omit<MuiButtonProps<As>, 'href' | 'children' | 'onClick'> & {
1414
/**
1515
* 種類を指定
1616
*
@@ -97,6 +97,8 @@ export type ButtonProps<As extends ElementType = 'button'> = ComponentProps<
9797
*/
9898
color?: 'primary' | 'secondary' | 'default';
9999

100+
onClick?: MouseEventHandler<HTMLElementTagNameMap[As extends keyof HTMLElementTagNameMap ? As : 'button']>;
101+
100102
className?: string;
101103
},
102104
As
@@ -250,7 +252,7 @@ export const Button: ButtonComponent = forwardRef(
250252
])}
251253
// FIXME: Avoid unintended type error, maybe MUI's problem?
252254
{...(rest as MuiButtonProps<As>)}
253-
onClick={(e: MouseEvent<As>) => {
255+
onClick={(e: MouseEvent<HTMLElementTagNameMap[As extends keyof HTMLElementTagNameMap ? As : 'button']>) => {
254256
if (loading) {
255257
return;
256258
}

0 commit comments

Comments
 (0)