chore: prevent enter keypress from saving document (#3115)
This commit is contained in:
@@ -2,16 +2,24 @@ import React from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import FormSubmit from '../../forms/Submit';
|
||||
import RenderCustomComponent from '../../utilities/RenderCustomComponent';
|
||||
import { useForm } from '../../forms/Form/context';
|
||||
|
||||
export type CustomSaveButtonProps = React.ComponentType<DefaultSaveButtonProps & {
|
||||
DefaultButton: React.ComponentType<DefaultSaveButtonProps>;
|
||||
}>
|
||||
type DefaultSaveButtonProps = {
|
||||
label: string;
|
||||
save: () => void;
|
||||
};
|
||||
const DefaultSaveButton: React.FC<DefaultSaveButtonProps> = ({ label }) => {
|
||||
const DefaultSaveButton: React.FC<DefaultSaveButtonProps> = ({ label, save }) => {
|
||||
return (
|
||||
<FormSubmit buttonId="action-save">{label}</FormSubmit>
|
||||
<FormSubmit
|
||||
type="button"
|
||||
buttonId="action-save"
|
||||
onClick={save}
|
||||
>
|
||||
{label}
|
||||
</FormSubmit>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -20,12 +28,14 @@ type Props = {
|
||||
}
|
||||
export const Save: React.FC<Props> = ({ CustomComponent }) => {
|
||||
const { t } = useTranslation('general');
|
||||
const { submit } = useForm();
|
||||
|
||||
return (
|
||||
<RenderCustomComponent
|
||||
CustomComponent={CustomComponent}
|
||||
DefaultComponent={DefaultSaveButton}
|
||||
componentProps={{
|
||||
save: submit,
|
||||
label: t('save'),
|
||||
DefaultButton: DefaultSaveButton,
|
||||
}}
|
||||
|
||||
Reference in New Issue
Block a user