fleetcor-lwc 3.15.0 → 3.16.0

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/README.md CHANGED
@@ -952,6 +952,11 @@ You can override them as you wish by global css variables as priority.
952
952
  <details>
953
953
  <summary>Click to expand/collapse</summary>
954
954
 
955
+ v.3.16.0
956
+
957
+ - Update `flt-input-text` - it's become more powerfull with type number
958
+
959
+ ---
955
960
  v.3.15.0
956
961
 
957
962
  - Added to `flt-input-with-picklist` api attribute `inputmode` and `input-type`
@@ -225,4 +225,45 @@ describe('flt-input-text', () => {
225
225
  })
226
226
  })
227
227
  })
228
+
229
+ it('flt-input-text number', async () => {
230
+ const inputTextElement = createElement('flt-input-text', { is: InputText })
231
+ inputTextElement.name = 'Currency'
232
+ inputTextElement.label = 'Currency'
233
+ inputTextElement.type = 'number'
234
+ inputTextElement.inputmode = 'number'
235
+ inputTextElement.placeholder = 'Currency'
236
+ document.body.appendChild(inputTextElement)
237
+
238
+ await expect(inputTextElement.firstChild.classList).toContain('flt-input-text')
239
+ inputTextElement.validate()
240
+ return Promise.resolve().then(async () => {
241
+ await expect(inputTextElement.firstChild.classList).not.toContain(
242
+ 'flt-input-text_success'
243
+ )
244
+ await expect(inputTextElement.isValid()).toBeTruthy()
245
+ let data = inputTextElement.getData()
246
+ await expect(data.placeholder).toBe('Currency')
247
+
248
+ inputTextElement.value = '100'
249
+ inputTextElement.dispatchEvent(new CustomEvent('change'))
250
+ inputTextElement.validate()
251
+
252
+ return Promise.resolve().then(async () => {
253
+ await expect(inputTextElement.firstChild.classList).toContain(
254
+ 'flt-input-text_success'
255
+ )
256
+ await expect(inputTextElement.isValid()).toBeTruthy()
257
+ await expect(inputTextElement.getData().value).toBe('100')
258
+
259
+ const inputEl = inputTextElement.querySelector('input')
260
+ inputEl.focus()
261
+ inputEl.value = '3435234523'
262
+ inputEl.dispatchEvent(new CustomEvent('input'))
263
+ return Promise.resolve().then(async () => {
264
+ await expect(inputTextElement.getData().isValid).toBeTruthy()
265
+ })
266
+ })
267
+ })
268
+ })
228
269
  })
@@ -6,11 +6,12 @@
6
6
  <span lwc:if={prefix} class="flt-input-text__prefix" lwc:inner-html={prefix}></span>
7
7
  <input
8
8
  id={name}
9
+ lwc:ref="input"
9
10
  onfocus={handleFocused}
10
11
  onblur={handleBlur}
11
12
  class="flt-input-text__input"
12
13
  maxlength={maxLength}
13
- type={type}
14
+ type={htmlInputType}
14
15
  inputmode={inputmode}
15
16
  disabled={disabled}
16
17
  value={displayValue}
@@ -1,16 +1,26 @@
1
1
  import { api } from 'lwc'
2
2
  import { InputElement } from 'fleetcor-lwc'
3
+ import IMask from 'imask'
3
4
  import './inputText.scss'
4
5
 
6
+ const TYPE_NUMBER = 'number'
7
+ const TYPE_TEXT = 'text'
8
+
5
9
  export default class InputText extends InputElement {
6
10
  focused
7
11
  touched
12
+ mask
13
+
8
14
  @api prefix
9
- @api type = 'text'
10
- @api inputmode = 'text'
15
+ @api type = TYPE_TEXT
16
+ @api inputmode = TYPE_TEXT
11
17
  @api placeholderVisible
12
18
  @api errorMessage
13
19
 
20
+ get htmlInputType() {
21
+ return this.type == TYPE_NUMBER ? TYPE_TEXT : this.type
22
+ }
23
+
14
24
  get displayValue() {
15
25
  return this.value || ''
16
26
  }
@@ -78,7 +88,7 @@ export default class InputText extends InputElement {
78
88
  if (this.disabled) {
79
89
  event.target.value = ''
80
90
  event.preventDefault()
81
- } else {
91
+ } else if (this.type != TYPE_NUMBER) {
82
92
  this.value = event.target.value
83
93
  this.dispatchEvent(
84
94
  new CustomEvent('change', {
@@ -91,7 +101,7 @@ export default class InputText extends InputElement {
91
101
  handleChange(event) {
92
102
  if (this.disabled) {
93
103
  event.target.value = ''
94
- } else {
104
+ } else if (this.type != TYPE_NUMBER) {
95
105
  this.value = (event.target.value || '').trim()
96
106
  event.target.value = this.value
97
107
 
@@ -105,4 +115,36 @@ export default class InputText extends InputElement {
105
115
  event.stopPropagation()
106
116
  event.preventDefault()
107
117
  }
118
+
119
+ renderedCallback() {
120
+ super.renderedCallback()
121
+ if (this.type == TYPE_NUMBER && !this.mask) {
122
+ this.mask = IMask(this.refs.input, {
123
+ mask: Number, // Enable built-in number mask
124
+ scale: 0, // Number of digits after decimal (0 for integers only)
125
+ signed: false, // Disallow negative numbers
126
+ thousandsSeparator: '',
127
+ padFractionalZeros: false,
128
+ normalizeZeros: true,
129
+ min: 0,
130
+ commit: (value, masked) => {
131
+ this.value = masked._value
132
+ this.dispatchEvent(
133
+ new CustomEvent('change', {
134
+ detail: { ...this.getData(), _onchage: true }
135
+ })
136
+ )
137
+ }
138
+ })
139
+
140
+ this.mask.on('accept', () => {
141
+ this.value = this.mask.value
142
+ this.dispatchEvent(
143
+ new CustomEvent('change', {
144
+ detail: { ...this.getData(), _oninput: true }
145
+ })
146
+ )
147
+ })
148
+ }
149
+ }
108
150
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fleetcor-lwc",
3
- "version": "3.15.0",
3
+ "version": "3.16.0",
4
4
  "description": "LWC framework by Fleetcor",
5
5
  "repository": {
6
6
  "type": "git",