1
- import { defineComponent , h } from 'vue'
1
+ import { defineComponent , h , ref } from 'vue'
2
2
import { Color , Shape } from '../props'
3
3
4
4
export const CButton = defineComponent ( {
@@ -60,6 +60,20 @@ export const CButton = defineComponent({
60
60
return [ 'sm' , 'lg' ] . includes ( value )
61
61
} ,
62
62
} ,
63
+ /**
64
+ * Specifies the type of button. Always specify the type attribute for the `<button>` element.
65
+ * Different browsers may use different default types for the `<button>` element.
66
+ *
67
+ * @values 'button', 'submit', 'reset'
68
+ */
69
+ type : {
70
+ type : String ,
71
+ default : 'button' ,
72
+ required : false ,
73
+ validator : ( value : string ) => {
74
+ return [ 'button' , 'submit' , 'reset' ] . includes ( value )
75
+ } ,
76
+ } ,
63
77
/**
64
78
* Set the button variant to an outlined button or a ghost button.
65
79
*
@@ -74,7 +88,20 @@ export const CButton = defineComponent({
74
88
} ,
75
89
} ,
76
90
} ,
77
- setup ( props , { slots } ) {
91
+ emits : [
92
+ /**
93
+ * Event called when the user clicks on the button.
94
+ */
95
+ 'click' ,
96
+ ] ,
97
+ setup ( props , { emit, slots } ) {
98
+ const handleClick = ( ) => {
99
+ if ( props . disabled ) {
100
+ return
101
+ }
102
+
103
+ emit ( 'click' )
104
+ }
78
105
return ( ) =>
79
106
h (
80
107
props . component ,
@@ -92,6 +119,8 @@ export const CButton = defineComponent({
92
119
disabled : props . disabled && props . component !== 'a' ,
93
120
...( props . component === 'a' && props . disabled && { 'aria-disabled' : true , tabIndex : - 1 } ) ,
94
121
...( props . component === 'a' && props . href && { href : props . href } ) ,
122
+ ...( props . component === 'button' && { type : props . type } ) ,
123
+ onClick : handleClick ,
95
124
} ,
96
125
slots . default && slots . default ( ) ,
97
126
)
0 commit comments