Skip to content

Commit 7c7f26e

Browse files
authored
fix: prevent page reload on FormDialog submission with Enter key (#2715)
1 parent 4c1cff7 commit 7c7f26e

File tree

1 file changed

+24
-19
lines changed

1 file changed

+24
-19
lines changed

src/components/Dialog/FormDialog.tsx

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,13 @@ export const FormDialog = <
107107
<div className={clsx('str-chat__dialog str-chat__dialog--form', className)}>
108108
<div className='str-chat__dialog__body'>
109109
{title && <div className='str-chat__dialog__title'>{title}</div>}
110-
<form autoComplete='off'>
110+
<form
111+
autoComplete='off'
112+
onSubmit={(e) => {
113+
e.preventDefault();
114+
handleSubmit();
115+
}}
116+
>
111117
{Object.entries(fields).map(([id, fieldConfig]) => (
112118
<div className='str-chat__dialog__field' key={`dialog-field-${id}`}>
113119
{fieldConfig.label && (
@@ -129,26 +135,25 @@ export const FormDialog = <
129135
<FieldError text={fieldErrors[id]?.message} />
130136
</div>
131137
))}
138+
<div className='str-chat__dialog__controls'>
139+
<button
140+
className='str-chat__dialog__controls-button str-chat__dialog__controls-button--cancel'
141+
onClick={close}
142+
>
143+
{t<string>('Cancel')}
144+
</button>
145+
<button
146+
className='str-chat__dialog__controls-button str-chat__dialog__controls-button--submit'
147+
disabled={
148+
Object.keys(fieldErrors).length > 0 || shouldDisableSubmitButton?.(value)
149+
}
150+
type='submit'
151+
>
152+
{t<string>('Send')}
153+
</button>
154+
</div>
132155
</form>
133156
</div>
134-
<div className='str-chat__dialog__controls'>
135-
<button
136-
className='str-chat__dialog__controls-button str-chat__dialog__controls-button--cancel'
137-
onClick={close}
138-
>
139-
{t<string>('Cancel')}
140-
</button>
141-
<button
142-
className='str-chat__dialog__controls-button str-chat__dialog__controls-button--submit'
143-
disabled={
144-
Object.keys(fieldErrors).length > 0 || shouldDisableSubmitButton?.(value)
145-
}
146-
onClick={handleSubmit}
147-
type='submit'
148-
>
149-
{t<string>('Send')}
150-
</button>
151-
</div>
152157
</div>
153158
);
154159
};

0 commit comments

Comments
 (0)