From a4b8992cd2c14767378962be69f0c0b9f745b0c3 Mon Sep 17 00:00:00 2001 From: ikusteu Date: Tue, 2 May 2023 13:52:56 +0200 Subject: [PATCH] Make the buttons default to 'type="button"' to prevent form submissions on button click (if not specified otherwise) --- packages/ui/src/Button/Button.tsx | 30 +++++++++++++---------- packages/ui/src/IconButton/IconButton.tsx | 1 + 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/packages/ui/src/Button/Button.tsx b/packages/ui/src/Button/Button.tsx index c190c67bb..ffc3b408b 100644 --- a/packages/ui/src/Button/Button.tsx +++ b/packages/ui/src/Button/Button.tsx @@ -46,21 +46,25 @@ const Button: React.FC = ({ children ); - return React.createElement(as, { ...props, className, disabled }, [ - startAdornment && ( -
- {startAdornment} -
- ), + return React.createElement( + as, + { type: "button", ...props, className, disabled }, + [ + startAdornment && ( +
+ {startAdornment} +
+ ), - content, + content, - endAdornment && ( -
- {endAdornment} -
- ), - ]); + endAdornment && ( +
+ {endAdornment} +
+ ), + ] + ); }; const baseClasses = [ diff --git a/packages/ui/src/IconButton/IconButton.tsx b/packages/ui/src/IconButton/IconButton.tsx index 05e5953ca..585162cdf 100644 --- a/packages/ui/src/IconButton/IconButton.tsx +++ b/packages/ui/src/IconButton/IconButton.tsx @@ -47,6 +47,7 @@ const IconButton: React.FC = ({ ...props }) => (