Skip to content

Commit

Permalink
Use normal click on Save button
Browse files Browse the repository at this point in the history
  • Loading branch information
JulienMattiussi committed Feb 11, 2020
1 parent e86f998 commit 7533a48
Showing 1 changed file with 1 addition and 15 deletions.
16 changes: 1 addition & 15 deletions packages/ra-ui-materialui/src/button/SaveButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,7 @@ const SaveButton: FC<SaveButtonProps> = ({
const notify = useNotify();
const translate = useTranslate();

// We handle the click event through mousedown because of an issue when
// the button is not as the same place when mouseup occurs, preventing the click
// event to fire.
// It can happen when some errors appear under inputs, pushing the button
// towards the window bottom.
const handleMouseDown = event => {
const handleClick = event => {
if (saving) {
// prevent double submission
event.preventDefault();
Expand All @@ -56,22 +51,13 @@ const SaveButton: FC<SaveButtonProps> = ({
}
};

// As we handle the "click" through the mousedown event, we have to make sure we cancel
// the default click in case the issue mentionned above does not occur.
// Otherwise, this would trigger a standard HTML submit, not the final-form one.
const handleClick = event => {
event.preventDefault();
event.stopPropagation();
};

const type = submitOnEnter ? 'submit' : 'button';
const displayedLabel = label && translate(label, { _: label });
return (
<Button
className={classnames(classes.button, className)}
variant={variant}
type={type}
onMouseDown={handleMouseDown}
onClick={handleClick}
color={saving ? 'default' : 'primary'}
aria-label={displayedLabel}
Expand Down

1 comment on commit 7533a48

@christiaanwesterbeek
Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you. We were noticing form submits on Dekstop/Chrome on mouse down.

Please sign in to comment.