Skip to content

Commit b2c31a7

Browse files
committed
feat(DesignSystem): add type attribute to Button component
1 parent 08b7442 commit b2c31a7

2 files changed

Lines changed: 9 additions & 0 deletions

File tree

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@ import { IconName } from '../icon/IconName'
55
import { Icon } from '../icon/Icon'
66

77
type ButtonVariant = 'primary' | 'secondary' | 'link'
8+
type ButtonType = 'button' | 'reset' | 'submit'
89

910
interface ButtonProps extends HTMLAttributes<HTMLButtonElement> {
1011
variant?: ButtonVariant
1112
disabled?: boolean
1213
onClick?: (event: MouseEvent<HTMLButtonElement>) => void
1314
icon?: IconName | ReactNode
1415
withSpacing?: boolean
16+
type?: ButtonType
1517
children?: ReactNode
1618
}
1719

@@ -21,6 +23,7 @@ export function Button({
2123
onClick,
2224
icon,
2325
withSpacing,
26+
type,
2427
children,
2528
...props
2629
}: ButtonProps) {
@@ -31,6 +34,7 @@ export function Button({
3134
onClick={disabled ? undefined : onClick}
3235
disabled={disabled}
3336
aria-disabled={disabled}
37+
type={type}
3438
{...props}>
3539
{typeof icon === 'string' ? <Icon name={icon} /> : icon}
3640
{children}

packages/design-system/tests/component/button/Button.spec.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,9 @@ describe('Button', () => {
5454
cy.mount(<Button icon={IconName.COLLECTION} />)
5555
cy.findByRole('img', { name: IconName.COLLECTION }).should('exist')
5656
})
57+
58+
it('renders a button with submit type', () => {
59+
cy.mount(<Button type="submit">{clickMeText}</Button>)
60+
cy.findByText(clickMeText).should('have.attr', 'type').and('eq', 'submit')
61+
})
5762
})

0 commit comments

Comments
 (0)