1- import { defineComponent , h } from 'vue'
1+ import { defineComponent , h , ref } from 'vue'
22import { Color , Shape } from '../props'
33
44export const CButton = defineComponent ( {
@@ -60,6 +60,20 @@ export const CButton = defineComponent({
6060 return [ 'sm' , 'lg' ] . includes ( value )
6161 } ,
6262 } ,
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+ } ,
6377 /**
6478 * Set the button variant to an outlined button or a ghost button.
6579 *
@@ -74,7 +88,20 @@ export const CButton = defineComponent({
7488 } ,
7589 } ,
7690 } ,
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+ }
78105 return ( ) =>
79106 h (
80107 props . component ,
@@ -92,6 +119,8 @@ export const CButton = defineComponent({
92119 disabled : props . disabled && props . component !== 'a' ,
93120 ...( props . component === 'a' && props . disabled && { 'aria-disabled' : true , tabIndex : - 1 } ) ,
94121 ...( props . component === 'a' && props . href && { href : props . href } ) ,
122+ ...( props . component === 'button' && { type : props . type } ) ,
123+ onClick : handleClick ,
95124 } ,
96125 slots . default && slots . default ( ) ,
97126 )
0 commit comments