1- import { defineComponent , h } from 'vue'
1+ import { defineComponent , h , PropType } from 'vue'
2+
3+ type Option = {
4+ disabled ?: boolean
5+ label ?: string
6+ value ?: string
7+ }
28
39const CFormSelect = defineComponent ( {
410 name : 'CFormSelect' ,
@@ -26,6 +32,17 @@ const CFormSelect = defineComponent({
2632 default : undefined ,
2733 require : false ,
2834 } ,
35+ /**
36+ * Options list of the select component. Available keys: `label`, `value`, `disabled`.
37+ * Examples:
38+ * - `:options="[{ value: 'js', label: 'JavaScript' }, { value: 'html', label: 'HTML', disabled: true }]"`
39+ * - `:options="['js', 'html']"`
40+ */
41+ options : {
42+ type : Array as PropType < Option [ ] | string [ ] > ,
43+ default : undefined ,
44+ required : false ,
45+ } ,
2946 /**
3047 * Size the component small or large.
3148 *
@@ -49,7 +66,7 @@ const CFormSelect = defineComponent({
4966 } ,
5067 emits : [
5168 /**
52- * Event occurs when when a user changes the selected option of a <select> element.
69+ * Event occurs when when a user changes the selected option of a ` <select>` element.
5370 */
5471 'change' ,
5572 /**
@@ -84,7 +101,19 @@ const CFormSelect = defineComponent({
84101 onChange : ( event : InputEvent ) => handleChange ( event ) ,
85102 size : props . htmlSize ,
86103 } ,
87- slots . default && slots . default ( ) ,
104+ props . options
105+ ? props . options . map ( ( option : Option | string ) => {
106+ return h (
107+ 'option' ,
108+ {
109+ ...( typeof option === 'object' &&
110+ option . disabled && { disabled : option . disabled } ) ,
111+ ...( typeof option === 'object' && option . value && { value : option . value } ) ,
112+ } ,
113+ typeof option === 'string' ? option : option . label ,
114+ )
115+ } )
116+ : slots . default && slots . default ( ) ,
88117 )
89118 } ,
90119} )
0 commit comments