Skip to content

Commit 7cee7d1

Browse files
committed
fix: add type property to buttons
1 parent d48bf58 commit 7cee7d1

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

packages/design-system/src/components/Button/Button.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ type ButtonProps<C extends React.ElementType = 'button'> = FlexProps<C> & {
2020
size?: ButtonSize;
2121
startIcon?: React.ReactNode;
2222
variant?: ButtonVariant;
23+
type?: 'button' | 'submit' | 'reset';
2324
};
2425

2526
const Button = forwardRef(
@@ -34,6 +35,7 @@ const Button = forwardRef(
3435
size = BUTTON_SIZES[1],
3536
loading = false,
3637
fullWidth = false,
38+
type = 'button',
3739
...props
3840
}: ButtonProps<C>,
3941
ref: PolymorphicRef<C>,
@@ -46,6 +48,10 @@ const Button = forwardRef(
4648
}
4749
};
4850

51+
// Only forward the `type` attribute when we actually render a native button
52+
const asTag = (props as { tag?: React.ElementType }).tag ?? 'button';
53+
const buttonType = asTag === 'button' || asTag === 'input' ? type : undefined;
54+
4955
return (
5056
<ButtonWrapper
5157
ref={ref}
@@ -64,6 +70,7 @@ const Button = forwardRef(
6470
paddingLeft={4}
6571
paddingRight={4}
6672
cursor="pointer"
73+
type={buttonType}
6774
{...props}
6875
>
6976
{(startIcon || loading) && (

packages/design-system/src/components/IconButton/IconButton.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { getActiveStyle, getDisabledStyle, getHoverStyle, getVariantStyle } from
1111
import { Tooltip } from '../Tooltip';
1212

1313
type IconButtonProps<C extends React.ElementType = 'button'> = FlexProps<C> &
14-
Pick<ButtonProps, 'size' | 'variant'> & {
14+
Pick<ButtonProps, 'size' | 'variant' | 'type'> & {
1515
children: React.ReactNode;
1616
disabled?: boolean;
1717
/**
@@ -36,6 +36,7 @@ const IconButton = forwardRef(
3636
size = 'S',
3737
variant = 'tertiary',
3838
withTooltip = true,
39+
type = 'button',
3940
...restProps
4041
}: IconButtonProps<C>,
4142
ref: PolymorphicRef<C>,
@@ -60,6 +61,7 @@ const IconButton = forwardRef(
6061
$size={size}
6162
onClick={handleClick}
6263
$variant={variant}
64+
type={type}
6365
>
6466
<AccessibleIcon label={label}>{children}</AccessibleIcon>
6567
</IconButtonWrapper>

packages/design-system/src/components/TextButton/TextButton.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@ type TextButtonProps<C extends React.ElementType = 'button'> = FlexProps<C> & {
1414
endIcon?: React.ReactNode;
1515
loading?: boolean;
1616
startIcon?: React.ReactNode;
17+
type?: 'button' | 'submit' | 'reset';
1718
};
1819

1920
const TextButton = forwardRef(
2021
<C extends React.ElementType = 'button'>(
21-
{ children, startIcon, endIcon, disabled = false, loading = false, ...props }: TextButtonProps<C>,
22+
{ children, startIcon, endIcon, disabled = false, loading = false, type = 'button', ...props }: TextButtonProps<C>,
2223
ref: PolymorphicRef<C>,
2324
) => {
2425
const isDisabled = disabled || loading;
@@ -29,7 +30,7 @@ const TextButton = forwardRef(
2930
disabled={isDisabled}
3031
aria-disabled={isDisabled}
3132
tag="button"
32-
type="button"
33+
type={type}
3334
gap={2}
3435
{...props}
3536
>

0 commit comments

Comments
 (0)