Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/packages/button/button.taro.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export const Button = React.forwardRef<HTMLButtonElement, Partial<ButtonProps>>(
children,
className,
style,
formType,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

需要在类型定义中添加 formType 属性

当前代码在解构参数时添加了 formType,但在 ButtonProps 接口中并未定义该属性。为了保持类型安全和代码一致性,应当更新接口定义。

建议在 ButtonProps 接口中添加 formType 定义,如下所示:

export interface ButtonProps
  extends BasicComponent,
    OmitMiniProgramButtonProps {
  color: string
  shape: ButtonShape
  type: ButtonType
  size: ButtonSize
  fill: ButtonFill
  block: boolean
  loading: boolean
  disabled: boolean
  icon: React.ReactNode
  rightIcon: React.ReactNode
  nativeType: 'submit' | 'reset' // | 'button'
+ formType?: 'submit' | 'reset' | 'button'
  onClick: (e: MouseEvent<HTMLButtonElement>) => void
}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
formType,
export interface ButtonProps
extends BasicComponent,
OmitMiniProgramButtonProps {
color: string
shape: ButtonShape
type: ButtonType
size: ButtonSize
fill: ButtonFill
block: boolean
loading: boolean
disabled: boolean
icon: React.ReactNode
rightIcon: React.ReactNode
nativeType: 'submit' | 'reset' // | 'button'
formType?: 'submit' | 'reset' | 'button'
onClick: (e: MouseEvent<HTMLButtonElement>) => void
}

nativeType,
onClick,
...rest
Expand Down Expand Up @@ -145,7 +146,7 @@ export const Button = React.forwardRef<HTMLButtonElement, Partial<ButtonProps>>(
)

if (getEnv() === 'WEB') {
;(rest as any).type = rest.formType
;(rest as any).type = formType
}
return (
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
Expand All @@ -154,7 +155,7 @@ export const Button = React.forwardRef<HTMLButtonElement, Partial<ButtonProps>>(
<TaroButton
{...rest}
ref={ref}
formType={nativeType}
formType={formType || nativeType}
className={buttonClassNames}
style={{ ...getStyle, ...style }}
onClick={(e) => handleClick(e as any)}
Expand Down