File tree Expand file tree Collapse file tree
src/lib/components/button Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -5,13 +5,15 @@ import { IconName } from '../icon/IconName'
55import { Icon } from '../icon/Icon'
66
77type ButtonVariant = 'primary' | 'secondary' | 'link'
8+ type ButtonType = 'button' | 'reset' | 'submit'
89
910interface 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 }
Original file line number Diff line number Diff 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} )
You can’t perform that action at this time.
0 commit comments