Skip to content

Commit

Permalink
fix: form loading
Browse files Browse the repository at this point in the history
  • Loading branch information
Zhou-Bill committed Sep 6, 2024
1 parent 58b7be5 commit f1601a1
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions packages/react/src/component/form/form_group.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,17 @@ const FormGroup: FC<FormGroupProps> = ({
export default FormGroup

type ActionProps = Omit<FormGroupProps, 'formRefs' | 'onSubmitValidated' | 'onSubmit'> & {
onSubmit?(event: BaseSyntheticEvent): void
onSubmit?(event: BaseSyntheticEvent): Promise<void> | void
}

const Action: FC<ActionProps> = ({ onCancel, onSubmit, disabled, saveText, actions }) => {
const [loading, setLoading] = useState(false)

const handleClick = (e: BaseSyntheticEvent) => {
setLoading(true)
Promise.resolve(onSubmit?.(e)).finally(() => setLoading(false))
}

return (
<>
{onCancel && (
Expand All @@ -141,7 +148,7 @@ const Action: FC<ActionProps> = ({ onCancel, onSubmit, disabled, saveText, actio
<div className='gm-gap-10' />
</>
)}
<Button type='primary' disabled={disabled} onClick={onSubmit}>
<Button type='primary' disabled={disabled} loading={loading} onClick={handleClick}>
{saveText || getLocale('确定')}
</Button>
{actions}
Expand Down

0 comments on commit f1601a1

Please sign in to comment.