123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397 |
- 'use strict';
-
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
-
- var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; // Styles
-
- // Extensions
-
- // Components
-
- // Mixins
-
- // Directives
-
- // Utilities
-
-
- require('../../../src/stylus/components/_text-fields.styl');
-
- var _VInput = require('../VInput');
-
- var _VInput2 = _interopRequireDefault(_VInput);
-
- var _VCounter = require('../VCounter');
-
- var _VCounter2 = _interopRequireDefault(_VCounter);
-
- var _VLabel = require('../VLabel');
-
- var _VLabel2 = _interopRequireDefault(_VLabel);
-
- var _maskable = require('../../mixins/maskable');
-
- var _maskable2 = _interopRequireDefault(_maskable);
-
- var _loadable = require('../../mixins/loadable');
-
- var _loadable2 = _interopRequireDefault(_loadable);
-
- var _ripple = require('../../directives/ripple');
-
- var _ripple2 = _interopRequireDefault(_ripple);
-
- var _helpers = require('../../util/helpers');
-
- var _console = require('../../util/console');
-
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
-
- var dirtyTypes = ['color', 'file', 'time', 'date', 'datetime-local', 'week', 'month'];
- /* @vue/component */
- exports.default = _VInput2.default.extend({
- name: 'v-text-field',
- directives: { Ripple: _ripple2.default },
- mixins: [_maskable2.default, _loadable2.default],
- inheritAttrs: false,
- props: {
- appendOuterIcon: String,
- /** @deprecated */
- appendOuterIconCb: Function,
- autofocus: Boolean,
- box: Boolean,
- browserAutocomplete: String,
- clearable: Boolean,
- clearIcon: {
- type: String,
- default: '$vuetify.icons.clear'
- },
- clearIconCb: Function,
- color: {
- type: String,
- default: 'primary'
- },
- counter: [Boolean, Number, String],
- flat: Boolean,
- fullWidth: Boolean,
- label: String,
- outline: Boolean,
- placeholder: String,
- prefix: String,
- prependInnerIcon: String,
- /** @deprecated */
- prependInnerIconCb: Function,
- reverse: Boolean,
- singleLine: Boolean,
- solo: Boolean,
- soloInverted: Boolean,
- suffix: String,
- type: {
- type: String,
- default: 'text'
- }
- },
- data: function data() {
- return {
- badInput: false,
- initialValue: null,
- internalChange: false,
- isClearing: false
- };
- },
- computed: {
- classes: function classes() {
- return {
- 'v-text-field': true,
- 'v-text-field--full-width': this.fullWidth,
- 'v-text-field--prefix': this.prefix,
- 'v-text-field--single-line': this.isSingle,
- 'v-text-field--solo': this.isSolo,
- 'v-text-field--solo-inverted': this.soloInverted,
- 'v-text-field--solo-flat': this.flat,
- 'v-text-field--box': this.box,
- 'v-text-field--enclosed': this.isEnclosed,
- 'v-text-field--reverse': this.reverse,
- 'v-text-field--outline': this.hasOutline,
- 'v-text-field--placeholder': this.placeholder
- };
- },
- counterValue: function counterValue() {
- return (this.internalValue || '').toString().length;
- },
- directivesInput: function directivesInput() {
- return [];
- },
-
- // TODO: Deprecate
- hasOutline: function hasOutline() {
- return this.outline || this.textarea;
- },
-
- internalValue: {
- get: function get() {
- return this.lazyValue;
- },
- set: function set(val) {
- if (this.mask && val !== this.lazyValue) {
- this.lazyValue = this.unmaskText(this.maskText(this.unmaskText(val)));
- this.setSelectionRange();
- } else {
- this.lazyValue = val;
- this.$emit('input', this.lazyValue);
- }
- }
- },
- isDirty: function isDirty() {
- return this.lazyValue != null && this.lazyValue.toString().length > 0 || this.badInput;
- },
- isEnclosed: function isEnclosed() {
- return this.box || this.isSolo || this.hasOutline || this.fullWidth;
- },
- isLabelActive: function isLabelActive() {
- return this.isDirty || dirtyTypes.includes(this.type);
- },
- isSingle: function isSingle() {
- return this.isSolo || this.singleLine;
- },
- isSolo: function isSolo() {
- return this.solo || this.soloInverted;
- },
- labelPosition: function labelPosition() {
- var offset = this.prefix && !this.labelValue ? this.prefixWidth : 0;
- return !this.$vuetify.rtl !== !this.reverse ? {
- left: 'auto',
- right: offset
- } : {
- left: offset,
- right: 'auto'
- };
- },
- showLabel: function showLabel() {
- return this.hasLabel && (!this.isSingle || !this.isLabelActive && !this.placeholder && !this.prefixLabel);
- },
- labelValue: function labelValue() {
- return !this.isSingle && Boolean(this.isFocused || this.isLabelActive || this.placeholder || this.prefixLabel);
- },
- prefixWidth: function prefixWidth() {
- if (!this.prefix && !this.$refs.prefix) return;
- return this.$refs.prefix.offsetWidth;
- },
- prefixLabel: function prefixLabel() {
- return this.prefix && !this.value;
- }
- },
- watch: {
- isFocused: function isFocused(val) {
- // Sets validationState from validatable
- this.hasColor = val;
- if (val) {
- this.initialValue = this.lazyValue;
- } else if (this.initialValue !== this.lazyValue) {
- this.$emit('change', this.lazyValue);
- }
- },
- value: function value(val) {
- var _this = this;
-
- if (this.mask && !this.internalChange) {
- var masked = this.maskText(this.unmaskText(val));
- this.lazyValue = this.unmaskText(masked);
- // Emit when the externally set value was modified internally
- String(val) !== this.lazyValue && this.$nextTick(function () {
- _this.$refs.input.value = masked;
- _this.$emit('input', _this.lazyValue);
- });
- } else this.lazyValue = val;
- }
- },
- mounted: function mounted() {
- this.autofocus && this.onFocus();
- },
-
- methods: {
- /** @public */
- focus: function focus() {
- this.onFocus();
- },
-
- /** @public */
- blur: function blur() {
- this.$refs.input ? this.$refs.input.blur() : this.onBlur();
- },
- clearableCallback: function clearableCallback() {
- var _this2 = this;
-
- this.internalValue = null;
- this.$nextTick(function () {
- return _this2.$refs.input.focus();
- });
- },
- genAppendSlot: function genAppendSlot() {
- var slot = [];
- if (this.$slots['append-outer']) {
- slot.push(this.$slots['append-outer']);
- } else if (this.appendOuterIcon) {
- slot.push(this.genIcon('appendOuter'));
- }
- return this.genSlot('append', 'outer', slot);
- },
- genPrependInnerSlot: function genPrependInnerSlot() {
- var slot = [];
- if (this.$slots['prepend-inner']) {
- slot.push(this.$slots['prepend-inner']);
- } else if (this.prependInnerIcon) {
- slot.push(this.genIcon('prependInner'));
- }
- return this.genSlot('prepend', 'inner', slot);
- },
- genIconSlot: function genIconSlot() {
- var slot = [];
- if (this.$slots['append']) {
- slot.push(this.$slots['append']);
- } else if (this.appendIcon) {
- slot.push(this.genIcon('append'));
- }
- return this.genSlot('append', 'inner', slot);
- },
- genInputSlot: function genInputSlot() {
- var input = _VInput2.default.options.methods.genInputSlot.call(this);
- var prepend = this.genPrependInnerSlot();
- prepend && input.children.unshift(prepend);
- return input;
- },
- genClearIcon: function genClearIcon() {
- if (!this.clearable) return null;
- var icon = !this.isDirty ? false : 'clear';
- if (this.clearIconCb) (0, _console.deprecate)(':clear-icon-cb', '@click:clear', this);
- return this.genSlot('append', 'inner', [this.genIcon(icon, !this.$listeners['click:clear'] && this.clearIconCb || this.clearableCallback, false)]);
- },
- genCounter: function genCounter() {
- if (this.counter === false || this.counter == null) return null;
- var max = this.counter === true ? this.$attrs.maxlength : this.counter;
- return this.$createElement(_VCounter2.default, {
- props: {
- dark: this.dark,
- light: this.light,
- max: max,
- value: this.counterValue
- }
- });
- },
- genDefaultSlot: function genDefaultSlot() {
- return [this.genTextFieldSlot(), this.genClearIcon(), this.genIconSlot(), this.genProgress()];
- },
- genLabel: function genLabel() {
- if (!this.showLabel) return null;
- var data = {
- props: {
- absolute: true,
- color: this.validationState,
- dark: this.dark,
- disabled: this.disabled,
- focused: !this.isSingle && (this.isFocused || !!this.validationState),
- left: this.labelPosition.left,
- light: this.light,
- right: this.labelPosition.right,
- value: this.labelValue
- }
- };
- if (this.$attrs.id) data.props.for = this.$attrs.id;
- return this.$createElement(_VLabel2.default, data, this.$slots.label || this.label);
- },
- genInput: function genInput() {
- var listeners = Object.assign({}, this.$listeners);
- delete listeners['change']; // Change should not be bound externally
- var data = {
- style: {},
- domProps: {
- value: this.maskText(this.lazyValue)
- },
- attrs: _extends({
- 'aria-label': (!this.$attrs || !this.$attrs.id) && this.label
- }, this.$attrs, {
- autofocus: this.autofocus,
- disabled: this.disabled,
- readonly: this.readonly,
- type: this.type
- }),
- on: Object.assign(listeners, {
- blur: this.onBlur,
- input: this.onInput,
- focus: this.onFocus,
- keydown: this.onKeyDown
- }),
- ref: 'input'
- };
- if (this.placeholder) data.attrs.placeholder = this.placeholder;
- if (this.mask) data.attrs.maxlength = this.masked.length;
- if (this.browserAutocomplete) data.attrs.autocomplete = this.browserAutocomplete;
- return this.$createElement('input', data);
- },
- genMessages: function genMessages() {
- if (this.hideDetails) return null;
- return this.$createElement('div', {
- staticClass: 'v-text-field__details'
- }, [_VInput2.default.options.methods.genMessages.call(this), this.genCounter()]);
- },
- genTextFieldSlot: function genTextFieldSlot() {
- return this.$createElement('div', {
- staticClass: 'v-text-field__slot'
- }, [this.genLabel(), this.prefix ? this.genAffix('prefix') : null, this.genInput(), this.suffix ? this.genAffix('suffix') : null]);
- },
- genAffix: function genAffix(type) {
- return this.$createElement('div', {
- 'class': 'v-text-field__' + type,
- ref: type
- }, this[type]);
- },
- onBlur: function onBlur(e) {
- this.isFocused = false;
- // Reset internalChange state
- // to allow external change
- // to persist
- this.internalChange = false;
- this.$emit('blur', e);
- },
- onClick: function onClick() {
- if (this.isFocused || this.disabled) return;
- this.$refs.input.focus();
- },
- onFocus: function onFocus(e) {
- if (!this.$refs.input) return;
- if (document.activeElement !== this.$refs.input) {
- return this.$refs.input.focus();
- }
- if (!this.isFocused) {
- this.isFocused = true;
- this.$emit('focus', e);
- }
- },
- onInput: function onInput(e) {
- this.internalChange = true;
- this.mask && this.resetSelections(e.target);
- this.internalValue = e.target.value;
- this.badInput = e.target.validity && e.target.validity.badInput;
- },
- onKeyDown: function onKeyDown(e) {
- this.internalChange = true;
- if (e.keyCode === _helpers.keyCodes.enter) this.$emit('change', this.internalValue);
- this.$emit('keydown', e);
- },
- onMouseDown: function onMouseDown(e) {
- // Prevent input from being blurred
- if (e.target !== this.$refs.input) {
- e.preventDefault();
- e.stopPropagation();
- }
- _VInput2.default.options.methods.onMouseDown.call(this, e);
- },
- onMouseUp: function onMouseUp(e) {
- if (this.hasMouseDown) this.focus();
- _VInput2.default.options.methods.onMouseUp.call(this, e);
- }
- }
- });
- //# sourceMappingURL=VTextField.js.map
|