bootstrap-vue
Version:
With more than 85 components, over 45 available plugins, several directives, and 1000+ icons, BootstrapVue provides one of the most comprehensive implementations of the Bootstrap v4 component and grid system available for Vue.js v2.6, complete with extens
39 lines (34 loc) • 1.12 kB
JavaScript
import Vue from '../../vue'
import { NAME_FORM_SELECT_OPTION_GROUP } from '../../constants/components'
import { SLOT_NAME_FIRST } from '../../constants/slot-names'
import { htmlOrText } from '../../utils/html'
import formOptionsMixin from '../../mixins/form-options'
import normalizeSlotMixin from '../../mixins/normalize-slot'
import { BFormSelectOption } from './form-select-option'
// @vue/component
const BFormSelectOptionGroup = /*#__PURE__*/ Vue.extend({
name: NAME_FORM_SELECT_OPTION_GROUP,
mixins: [normalizeSlotMixin, formOptionsMixin],
props: {
label: {
type: String,
required: true
}
},
render(h) {
const $options = this.formOptions.map((option, index) => {
const { value, text, html, disabled } = option
return h(BFormSelectOption, {
attrs: { value, disabled },
domProps: htmlOrText(html, text),
key: `option_${index}`
})
})
return h('optgroup', { attrs: { label: this.label } }, [
this.normalizeSlot(SLOT_NAME_FIRST),
$options,
this.normalizeSlot()
])
}
})
export { BFormSelectOptionGroup }