Skip to content

Commit b08f644

Browse files
committed
feat: [Request] QField Slots quasarframework#1962
1 parent 926052c commit b08f644

File tree

2 files changed

+37
-19
lines changed

2 files changed

+37
-19
lines changed

dev/components/form/field.vue

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,21 @@
539539
<q-toggle v-model="cond2" label="Render test ctrl" />
540540
</div>
541541
</div>
542+
543+
<h4>Slots test</h4>
544+
<q-field
545+
icon="cloud"
546+
:error="error"
547+
:warning="warning"
548+
:label-width="3"
549+
>
550+
Slot test
551+
552+
<span slot="label">Slot label</span>
553+
<span slot="error-label">Slot error label</span>
554+
<span slot="warning-label">Slot warning label</span>
555+
<span slot="helper">Slot helper</span>
556+
</q-field>
542557
</div>
543558
<div class="fixed-bottom-right">
544559
<label>

src/components/field/QField.js

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,6 @@ export default {
4545
hasWarning () {
4646
return !this.hasError && (this.input.warning || this.warning)
4747
},
48-
hasBottom () {
49-
return (this.hasError && this.errorLabel) ||
50-
(this.hasWarning && this.warningLabel) ||
51-
this.helper ||
52-
this.count
53-
},
54-
hasLabel () {
55-
return this.label || this.$slots.label || ['label', 'full'].includes(this.inset)
56-
},
5748
childHasLabel () {
5849
return this.input.floatLabel || this.input.stackLabel
5950
},
@@ -111,6 +102,9 @@ export default {
111102
prop.color = this.iconColor
112103
}
113104
return prop
105+
},
106+
insetHasLabel () {
107+
return ['label', 'full'].includes(this.inset)
114108
}
115109
},
116110
provide () {
@@ -128,19 +122,29 @@ export default {
128122
}
129123
},
130124
__getBottomContent (h) {
131-
if (this.hasError && this.errorLabel) {
132-
return h('div', { staticClass: 'q-field-error col' }, this.errorLabel)
125+
let label
126+
127+
if (this.hasError && (label = this.$slots['error-label'] || this.errorLabel)) {
128+
return h('div', { staticClass: 'q-field-error col' }, label)
133129
}
134-
if (this.hasWarning && this.warningLabel) {
135-
return h('div', { staticClass: 'q-field-warning col' }, this.warningLabel)
130+
if (this.hasWarning && (label = this.$slots['warning-label'] || this.warningLabel)) {
131+
return h('div', { staticClass: 'q-field-warning col' }, label)
136132
}
137-
if (this.helper) {
138-
return h('div', { staticClass: 'q-field-helper col' }, this.helper)
133+
if ((label = this.$slots.helper || this.helper)) {
134+
return h('div', { staticClass: 'q-field-helper col' }, label)
139135
}
140136
return h('div', { staticClass: 'col' })
137+
},
138+
__hasBottom () {
139+
return (this.hasError && (this.$slots['error-label'] || this.errorLabel)) ||
140+
(this.hasWarning && (this.$slots['warning-label'] || this.warningLabel)) ||
141+
(this.$slots.helper || this.helper) ||
142+
this.count
141143
}
142144
},
143145
render (h) {
146+
const label = this.$slots.label || this.label
147+
144148
return h('div', {
145149
staticClass: 'q-field row no-wrap items-start',
146150
'class': this.classes
@@ -153,14 +157,13 @@ export default {
153157
: (this.insetIcon ? h('div', { staticClass: 'q-field-icon' }) : null),
154158

155159
h('div', { staticClass: 'row col' }, [
156-
this.hasLabel
160+
label || this.insetHasLabel
157161
? h('div', {
158162
staticClass: 'q-field-label q-field-margin',
159163
'class': this.labelClasses
160164
}, [
161165
h('div', { staticClass: 'q-field-label-inner row items-center' }, [
162-
this.label,
163-
this.$slots.label
166+
this.$slots.label || this.label
164167
])
165168
])
166169
: null,
@@ -170,7 +173,7 @@ export default {
170173
'class': this.inputClasses
171174
}, [
172175
this.$slots.default,
173-
this.hasBottom
176+
this.__hasBottom()
174177
? h('div', {
175178
staticClass: 'q-field-bottom row no-wrap',
176179
'class': { 'q-field-no-input': this.hasNoInput }

0 commit comments

Comments
 (0)