@gitlab/ui
Version:
GitLab UI Components
52 lines (46 loc) • 1.4 kB
JavaScript
import { extend } from '../../vue';
import { NAME_FORM_SELECT_OPTION_GROUP } from '../../constants/components';
import { SLOT_NAME_FIRST } from '../../constants/slots';
import { htmlOrText } from '../../utils/html';
import { sortKeys } from '../../utils/object';
import { props as props$1, formOptionsMixin } from '../../mixins/form-options';
import { normalizeSlotMixin } from '../../mixins/normalize-slot';
import { BFormSelectOption } from './form-select-option';
// --- Props ---
const props = sortKeys({
...props$1,
label: {
type: String,
required: true
}
});
// --- Main component ---
// @vue/component
const BFormSelectOptionGroup = /*#__PURE__*/extend({
name: NAME_FORM_SELECT_OPTION_GROUP,
mixins: [normalizeSlotMixin, formOptionsMixin],
props,
render(h) {
const label = this.label;
const $options = this.formOptions.map((option, index) => {
const value = option.value,
text = option.text,
html = option.html,
disabled = option.disabled;
return h(BFormSelectOption, {
attrs: {
value,
disabled
},
domProps: htmlOrText(html, text),
key: `option_${index}`
});
});
return h('optgroup', {
attrs: {
label
}
}, [this.normalizeSlot(SLOT_NAME_FIRST), $options, this.normalizeSlot()]);
}
});
export { BFormSelectOptionGroup, props };