Skip to content

Commit

Permalink
fix(VTextField): use resize directive to recalculate elements width (#…
Browse files Browse the repository at this point in the history
…11816)

* fix(VTextField): use resize directive to recalculate elements width

* refactor(VTextField): restructure to avoid multiple onResize calls

was called twice when mounting. normalized watchers and reduced
their overall footprint.

Co-authored-by: John Leider <john.j.leider@gmail.com>
  • Loading branch information
Djaler and johnleider committed Sep 29, 2020
1 parent d723457 commit 4efd18d
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions packages/vuetify/src/components/VTextField/VTextField.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import Loadable from '../../mixins/loadable'
import Validatable from '../../mixins/validatable'

// Directives
import resize from '../../directives/resize'
import ripple from '../../directives/ripple'

// Utilities
Expand All @@ -28,9 +29,7 @@ const baseMixins = mixins(
VInput,
Intersectable({
onVisible: [
'setLabelWidth',
'setPrefixWidth',
'setPrependWidth',
'onResize',
'tryAutofocus',
],
}),
Expand All @@ -52,7 +51,10 @@ const dirtyTypes = ['color', 'file', 'time', 'date', 'datetime-local', 'week', '
export default baseMixins.extend<options>().extend({
name: 'v-text-field',

directives: { ripple },
directives: {
resize,
ripple,
},

inheritAttrs: false,

Expand Down Expand Up @@ -227,9 +229,7 @@ export default baseMixins.extend<options>().extend({

mounted () {
this.autofocus && this.tryAutofocus()
this.setLabelWidth()
this.setPrefixWidth()
this.setPrependWidth()

requestAnimationFrame(() => (this.isBooted = true))
},

Expand Down Expand Up @@ -396,6 +396,11 @@ export default baseMixins.extend<options>().extend({
keydown: this.onKeyDown,
}),
ref: 'input',
directives: [{
name: 'resize',
modifiers: { quiet: true },
value: this.onResize,
}],
})
},
genMessages () {
Expand Down Expand Up @@ -511,5 +516,10 @@ export default baseMixins.extend<options>().extend({
this.$emit('change', this.lazyValue)
}
},
onResize () {
this.setLabelWidth()
this.setPrefixWidth()
this.setPrependWidth()
},
},
})

0 comments on commit 4efd18d

Please sign in to comment.