mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-12-02 12:09:14 +08:00
refactor: review <Button/> defaultProps (#28211)
This commit is contained in:
parent
ebb6fcf6c5
commit
fa09208cda
@ -129,7 +129,7 @@ type Loading = number | boolean;
|
||||
|
||||
const InternalButton: React.ForwardRefRenderFunction<unknown, ButtonProps> = (props, ref) => {
|
||||
const {
|
||||
loading,
|
||||
loading = false,
|
||||
prefixCls: customizePrefixCls,
|
||||
type,
|
||||
danger,
|
||||
@ -138,8 +138,11 @@ const InternalButton: React.ForwardRefRenderFunction<unknown, ButtonProps> = (pr
|
||||
className,
|
||||
children,
|
||||
icon,
|
||||
ghost,
|
||||
block,
|
||||
ghost = false,
|
||||
block = false,
|
||||
/** if we extract items here, we dont need use omit.js */
|
||||
// React does not recognize the `htmlType` prop on a DOM element. Here we pick it out of `rest`.
|
||||
htmlType = 'button' as ButtonProps['htmlType'],
|
||||
...rest
|
||||
} = props;
|
||||
|
||||
@ -260,7 +263,7 @@ const InternalButton: React.ForwardRefRenderFunction<unknown, ButtonProps> = (pr
|
||||
? spaceChildren(children, isNeedInserted() && autoInsertSpace)
|
||||
: null;
|
||||
|
||||
const linkButtonRestProps = omit(rest as AnchorButtonProps, ['htmlType', 'loading', 'navigate']);
|
||||
const linkButtonRestProps = omit(rest as AnchorButtonProps, ['navigate']);
|
||||
if (linkButtonRestProps.href !== undefined) {
|
||||
return (
|
||||
<a {...linkButtonRestProps} className={classes} onClick={handleClick} ref={buttonRef}>
|
||||
@ -270,12 +273,9 @@ const InternalButton: React.ForwardRefRenderFunction<unknown, ButtonProps> = (pr
|
||||
);
|
||||
}
|
||||
|
||||
// React does not recognize the `htmlType` prop on a DOM element. Here we pick it out of `rest`.
|
||||
const { htmlType, ...otherProps } = rest as NativeButtonProps;
|
||||
|
||||
const buttonNode = (
|
||||
<button
|
||||
{...(omit(otherProps, ['loading']) as NativeButtonProps)}
|
||||
{...rest as NativeButtonProps}
|
||||
type={htmlType}
|
||||
className={classes}
|
||||
onClick={handleClick}
|
||||
@ -297,13 +297,6 @@ const Button = React.forwardRef<unknown, ButtonProps>(InternalButton) as Compoun
|
||||
|
||||
Button.displayName = 'Button';
|
||||
|
||||
Button.defaultProps = {
|
||||
loading: false,
|
||||
ghost: false,
|
||||
block: false,
|
||||
htmlType: 'button' as ButtonProps['htmlType'],
|
||||
};
|
||||
|
||||
Button.Group = Group;
|
||||
Button.__ANT_BUTTON = true;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user