Skip to content

Commit c2fb9ed

Browse files
pdanpdanrstoenescu
authored andcommitted
feat: Prevent q-btn loading state from resizing the button quasarframework#2799 (quasarframework#2818)
close quasarframework#2799
1 parent a245fe0 commit c2fb9ed

File tree

4 files changed

+83
-30
lines changed

4 files changed

+83
-30
lines changed

src/components/btn/QBtn.js

Lines changed: 38 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,32 @@ export default {
153153
this.__cleanup()
154154
},
155155
render (h) {
156+
const inner = [].concat(this.$slots.default)
157+
158+
if (this.icon !== void 0) {
159+
inner.unshift(
160+
h(QIcon, {
161+
class: { 'on-left': this.label !== void 0 && this.isRectangle === true },
162+
props: { name: this.icon }
163+
})
164+
)
165+
}
166+
167+
if (this.label !== void 0 && this.isRectangle === true) {
168+
inner.unshift(
169+
h('div', [this.label])
170+
)
171+
}
172+
173+
if (this.iconRight !== void 0 && this.isRound === false) {
174+
inner.push(
175+
h(QIcon, {
176+
staticClass: 'on-right',
177+
props: { name: this.iconRight }
178+
})
179+
)
180+
}
181+
156182
return h(this.isLink ? 'a' : 'button', {
157183
staticClass: 'q-btn inline relative-position q-btn-item non-selectable',
158184
'class': this.classes,
@@ -182,29 +208,18 @@ export default {
182208
h('div', {
183209
staticClass: 'q-btn-inner row col items-center q-popup--skip',
184210
'class': this.innerClasses
185-
},
186-
this.loading
187-
? [ this.$slots.loading || h(QSpinner) ]
188-
: [
189-
this.icon
190-
? h(QIcon, {
191-
'class': { 'on-left': this.label && this.isRectangle },
192-
props: { name: this.icon }
193-
})
194-
: null,
195-
196-
this.label && this.isRectangle ? h('div', [ this.label ]) : null,
197-
198-
this.$slots.default,
199-
200-
this.iconRight && this.isRectangle
201-
? h(QIcon, {
202-
staticClass: 'on-right',
203-
props: { name: this.iconRight }
204-
})
205-
: null
206-
]
207-
)
211+
}, inner),
212+
213+
this.loading !== null
214+
? h('transition', {
215+
props: { name: 'q-transition--fade' }
216+
}, this.loading === true ? [
217+
h('div', {
218+
key: 'loading',
219+
staticClass: 'absolute-full flex flex-center'
220+
}, this.$slots.loading !== void 0 ? this.$slots.loading : [h(QSpinner)])
221+
] : void 0)
222+
: null
208223
])
209224
}
210225
}

src/components/btn/btn-default.ios.styl

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,12 @@
1717
.q-icon, .q-spinner
1818
font-size 1.4em
1919
// workaround for alignment/sizing change when showing loader
20-
.q-btn-inner:before
21-
content ''
20+
.q-btn-inner
21+
transition opacity .6s
22+
&--hidden
23+
opacity 0
24+
&:before
25+
content ''
2226

2327
&.disabled
2428
opacity .7 !important
@@ -79,3 +83,16 @@
7983
.q-btn-fab-mini
8084
height 40px
8185
width 40px
86+
87+
.q-transition
88+
89+
&--fade
90+
91+
&-leave-active
92+
position absolute
93+
94+
&--fade
95+
&-enter-active, &-leave-active
96+
transition opacity .4s ease-out
97+
&-enter, &-leave, &-leave-to
98+
opacity 0

src/components/btn/btn-default.mat.styl

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,12 @@
2020
.q-icon, .q-spinner
2121
font-size 1.4em
2222
// workaround for alignment/sizing change when showing loader
23-
.q-btn-inner:before
24-
content ''
23+
.q-btn-inner
24+
transition opacity .6s
25+
&--hidden
26+
opacity 0
27+
&:before
28+
content ''
2529

2630
&.disabled
2731
opacity .7 !important
@@ -108,3 +112,16 @@
108112
.q-btn-fab-mini
109113
height 40px
110114
width 40px
115+
116+
.q-transition
117+
118+
&--fade
119+
120+
&-leave-active
121+
position absolute
122+
123+
&--fade
124+
&-enter-active, &-leave-active
125+
transition opacity .4s ease-out
126+
&-enter, &-leave, &-leave-to
127+
opacity 0

src/components/btn/btn-mixin.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ export default {
2020
},
2121
props: {
2222
type: String,
23-
loading: Boolean,
23+
loading: {
24+
type: Boolean,
25+
default: null
26+
},
2427
disable: Boolean,
2528
label: [Number, String],
2629
noCaps: Boolean,
@@ -135,8 +138,9 @@ export default {
135138
},
136139
innerClasses () {
137140
const classes = [ this.alignClass ]
138-
this.noWrap && classes.push('no-wrap', 'text-no-wrap')
139-
this.repeating && classes.push('non-selectable')
141+
this.noWrap === true && classes.push('no-wrap', 'text-no-wrap')
142+
this.repeating === true && classes.push('non-selectable')
143+
this.loading === true && classes.push('q-btn-inner--hidden')
140144
return classes
141145
}
142146
}

0 commit comments

Comments
 (0)