🌐 AI搜索 & 代理 主页
Skip to content

Commit b47a94d

Browse files
committed
Improve option property handling
1 parent 6f41367 commit b47a94d

File tree

4 files changed

+26
-19
lines changed

4 files changed

+26
-19
lines changed

src/components/form-select/form-select-option-group.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,15 @@ const BFormSelectOptionGroup = /*#__PURE__*/ Vue.extend({
1818
return h('optgroup', { attrs: { label: this.label } }, [
1919
this.normalizeSlot('first'),
2020
this.formOptions.map((option, index) => {
21-
const tag = isArray(option.options) ? BFormSelectOptionGroup : BFormSelectOption
22-
return h(tag, { props: option, key: `option_${index}_opt` })
21+
const key = `option_${index}_opt`
22+
const options = option.options
23+
return isArray(options)
24+
? h(BFormSelectOptionGroup, { props: { label: option.label, options }, key })
25+
: h(
26+
BFormSelectOption,
27+
{ props: { value: option.value, disabled: option.disabled }, key },
28+
option.html || option.text
29+
)
2330
}),
2431
this.normalizeSlot('default')
2532
])
Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import Vue from '../../utils/vue'
22
import { mergeData } from 'vue-functional-data-merge'
3-
import { htmlOrText } from '../../utils/html'
43

54
const NAME = 'BFormSelectOption'
65

@@ -9,14 +8,6 @@ export const props = {
98
// type: [String, Number, Boolean, Object],
109
required: true
1110
},
12-
text: {
13-
type: String,
14-
default: null
15-
},
16-
html: {
17-
type: String,
18-
default: null
19-
},
2011
disabled: {
2112
type: Boolean,
2213
default: false
@@ -28,14 +19,15 @@ export const BFormSelectOption = /*#__PURE__*/ Vue.extend({
2819
name: NAME,
2920
functional: true,
3021
props,
31-
render(h, { props, data }) {
32-
const { value, text, html, disabled } = props
22+
render(h, { props, data, children }) {
23+
const { value, disabled } = props
3324
return h(
3425
'option',
3526
mergeData(data, {
3627
attrs: { disabled },
37-
domProps: { ...htmlOrText(html, text), value }
38-
})
28+
domProps: { value }
29+
}),
30+
children
3931
)
4032
}
4133
})

src/components/form-select/form-select.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,15 @@ export const BFormSelect = /*#__PURE__*/ Vue.extend({
129129
[
130130
this.normalizeSlot('first'),
131131
this.formOptions.map((option, index) => {
132-
const tag = isArray(option.options) ? BFormSelectOptionGroup : BFormSelectOption
133-
return h(tag, { props: option, key: `option_${index}_opt` })
132+
const key = `option_${index}_opt`
133+
const options = option.options
134+
return isArray(options)
135+
? h(BFormSelectOptionGroup, { props: { label: option.label, options }, key })
136+
: h(
137+
BFormSelectOption,
138+
{ props: { value: option.value, disabled: option.disabled }, key },
139+
option.html || option.text
140+
)
134141
}),
135142
this.normalizeSlot('default')
136143
]

src/mixins/form-options.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import warn from '../utils/warn'
22
import { isArray, isPlainObject, isUndefined } from '../utils/inspect'
3+
import { stripTags } from '../utils/html'
34
import { keys } from '../utils/object'
45

56
const DEPRECATED_MSG =
@@ -50,15 +51,15 @@ export default {
5051
const text = option[this.textField]
5152
return {
5253
value: isUndefined(value) ? key || text : value,
53-
text: String(isUndefined(text) ? key : text),
54+
text: stripTags(String(isUndefined(text) ? key : text)),
5455
html: option[this.htmlField],
5556
disabled: Boolean(option[this.disabledField])
5657
}
5758
}
5859
// Otherwise create an `<option>` object from the given value
5960
return {
6061
value: key || option,
61-
text: String(option),
62+
text: stripTags(String(option)),
6263
disabled: false
6364
}
6465
}

0 commit comments

Comments
 (0)