@carbon/vue 2.20.1-canary.0 → 2.20.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@carbon/vue",
3
3
  "description": "A collection of components for the Carbon Design System built using Vue.js",
4
- "version": "2.20.1-canary.0",
4
+ "version": "2.20.1",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
7
7
  "type": "git",
@@ -73,5 +73,5 @@
73
73
  "eslint-plugin-prettier": "^3.1.1",
74
74
  "vue-template-compiler": "^2.6.10"
75
75
  },
76
- "gitHead": "28d36ca08d2c0476cdb27b34d665c17bf64fd26c"
76
+ "gitHead": "fae47ab7d9c7b51e2513daa47be06e583a19b426"
77
77
  }
@@ -129,7 +129,7 @@ export default {
129
129
  },
130
130
  data() {
131
131
  return {
132
- dataValue: '',
132
+ dataValue: this.value,
133
133
  dataOptions: {},
134
134
  isInvalid: false,
135
135
  };
@@ -18,12 +18,14 @@
18
18
  <input
19
19
  :id="uid"
20
20
  type="number"
21
- v-model="internalValue"
21
+ :value="internalValue"
22
22
  v-bind="$attrs"
23
23
  v-on="inputListeners"
24
+ :disabled="disabled"
24
25
  :step="step"
25
26
  :min="min"
26
27
  :max="max"
28
+ ref="input"
27
29
  />
28
30
  <WarningFilled16 v-if="isInvalid" class="bx--number__invalid" />
29
31
  <div class="bx--number__controls">
@@ -32,6 +34,7 @@
32
34
  @click="doUp"
33
35
  type="button"
34
36
  :aria-label="ariaLabelForUpButton"
37
+ :disabled="disabled"
35
38
  >
36
39
  <CaretUpGlyph />
37
40
  </button>
@@ -40,6 +43,7 @@
40
43
  @click="doDown"
41
44
  type="button"
42
45
  :aria-label="ariaLabelForDownButton"
46
+ :disabled="disabled"
43
47
  >
44
48
  <CaretDownGlyph />
45
49
  </button>
@@ -68,6 +72,7 @@ export default {
68
72
  components: { CaretDownGlyph, CaretUpGlyph, WarningFilled16, CvWrapper },
69
73
  inheritAttrs: false,
70
74
  props: {
75
+ disabled: Boolean,
71
76
  formItem: { type: Boolean, default: true },
72
77
  helperText: { type: String, default: undefined },
73
78
  invalidMessage: { type: String, default: undefined },
@@ -105,7 +110,13 @@ export default {
105
110
  },
106
111
  watch: {
107
112
  value() {
108
- this.internalValue = this.valueAsString(this.value);
113
+ // NOTE: DELIBERATE USE OF != TO COMPARE this.interanlValue and this.value
114
+ if (typeof this.value !== 'number' || this.internalValue != this.value) {
115
+ // prevents this.value of 1 updating this.internalValue of 1.0
116
+ // which improves the typing experience
117
+ // does not matter if this.value is string or number
118
+ this.internalValue = this.value.toString();
119
+ }
109
120
  },
110
121
  },
111
122
  computed: {
@@ -114,108 +125,40 @@ export default {
114
125
  // https://vuejs.org/v2/guide/components-custom-events.html#Customizing-Component-v-model
115
126
  inputListeners() {
116
127
  return Object.assign({}, this.$listeners, {
117
- input: () => this.emitValue(),
128
+ input: ev => this.onInput(ev.target.value),
118
129
  });
119
130
  },
120
- internalNumberValue() {
121
- let numVal = parseFloat(this.internalValue, 10);
122
-
123
- if (isNaN(numVal)) {
124
- numVal = parseFloat(this.min, 10) || 0;
125
- }
126
- return this.roundToPrecision(numVal);
127
- },
128
- internalMinValue() {
129
- let numVal = parseFloat(this.min, 10);
130
-
131
- if (isNaN(numVal)) {
132
- return undefined;
133
- }
134
- return this.roundToPrecision(numVal);
135
- },
136
- internalMaxValue() {
137
- let numVal = parseFloat(this.max, 10);
138
-
139
- if (isNaN(numVal)) {
140
- return undefined;
141
- }
142
- return this.roundToPrecision((this.internalStepValue * numVal) / this.internalStepValue);
143
- },
144
- internalStepValue() {
145
- let numVal = parseFloat(this.step, 10);
146
-
147
- if (isNaN(numVal) || numVal <= 0) {
148
- numVal = 1;
149
- }
150
- return numVal;
151
- },
152
- stepDecimalPlaces() {
153
- if (Math.floor(this.internalStepValue) === this.internalStepValue) return 0;
154
- return Math.min(maxDecimalPlaces, this.internalStepValue.toString().split('.')[1].length || 0);
155
- },
156
- // stepPrecision() {
157
- // return Math.pow(10, -1 * this.stepDecimalPlaces);
158
- // },
159
131
  },
160
132
  methods: {
133
+ onInput(val) {
134
+ this.internalValue = val;
135
+ this.emitValue();
136
+ },
161
137
  checkSlots() {
162
138
  // NOTE: this.$slots is not reactive so needs to be managed on beforeUpdate
163
139
  this.isInvalid = !!(this.$slots['invalid-message'] || (this.invalidMessage && this.invalidMessage.length));
164
140
  this.isHelper = !!(this.$slots['helper-text'] || (this.helperText && this.helperText.length));
165
141
  },
166
- _doUpDown(up) {
167
- let value;
168
- let min = this.internalMinValue;
169
- let min0 = min || 0;
170
- let max = this.internalMaxValue;
171
- let step = this.internalStepValue;
172
- // be wary of floating point error
173
- // steps should be from min value to less than or equal to max
174
- let steps = Math.round((this.internalNumberValue - min0) / step);
175
-
176
- if (up) {
177
- value = this.roundToPrecision(min0 + step * (steps + 1));
178
-
179
- if (max !== undefined && value > max) {
180
- steps = Math.round((max - min0) / step);
181
- value = min0 + step * steps;
182
- if (value > max) {
183
- value = value - step;
184
- }
185
- value = this.roundToPrecision(value);
186
- }
187
-
188
- if (this.roundToPrecision(value - this.internalNumberValue - step, maxDecimalPlaces) > 0) {
189
- // this is simpler than trying to prevent rounding errors
190
- value = value - step;
191
- }
192
-
193
- this.internalValue = this.valueAsString(value);
194
- } else {
195
- value = this.roundToPrecision(min0 + step * (steps - 1));
196
-
197
- if (min !== undefined && value < min) {
198
- value = min;
199
- }
200
-
201
- if (this.roundToPrecision(value - this.internalNumberValue + step, maxDecimalPlaces) < 0) {
202
- // this is simpler than trying to prevent rounding errors
203
- value = value + step;
204
- }
205
142
 
206
- this.internalValue = this.valueAsString(value);
207
- }
208
- this.emitValue();
209
- },
210
143
  doUp() {
211
- this._doUpDown(true);
144
+ this.$refs.input.stepUp();
212
145
  },
213
146
  doDown() {
214
- this._doUpDown(false);
147
+ this.$refs.input.stepDown();
215
148
  },
216
149
  emitValue() {
217
150
  if (typeof this.value === 'number') {
218
- this.$emit('input', this.internalNumberValue);
151
+ // this.$emit('input', this.internalNumberValue);
152
+
153
+ if (this.internalValue != this.value) {
154
+ const ePos = this.internalValue.indexOf('e-');
155
+ const dotPos = this.internalValue.indexOf('.');
156
+ if (ePos > -1 || dotPos > -1) {
157
+ this.$emit('input', parseFloat(this.internalValue));
158
+ } else {
159
+ this.$emit('input', parseInt(this.internalValue));
160
+ }
161
+ }
219
162
  } else {
220
163
  this.$emit('input', this.internalValue);
221
164
  }
@@ -223,20 +166,12 @@ export default {
223
166
  valueAsString(val) {
224
167
  let strVal;
225
168
  if (typeof val === 'number') {
226
- strVal = val.toFixed(this.stepDecimalPlaces);
169
+ strVal = val.toString();
227
170
  } else {
228
171
  strVal = val;
229
172
  }
230
-
231
173
  return strVal;
232
174
  },
233
- roundToPrecision(x, optDecimalPlaces) {
234
- // let sign = x >= 0 ? 1 : -1;
235
- // let y = x + sign * (this.stepPrecision === undefined ? 0.5 : this.stepPrecision / 2);
236
- // return y - (y % (this.stepPrecision === undefined ? 1 : this.stepPrecision));
237
- let decimalPlaces = optDecimalPlaces || this.stepDecimalPlaces;
238
- return parseFloat(x.toFixed(decimalPlaces));
239
- },
240
175
  },
241
176
  };
242
177
  </script>