@ionic/core 8.5.7-dev.11748379940.12698faf → 8.5.7-dev.11748466845.12de1519
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/components/ion-input-otp.js +164 -164
- package/dist/cjs/ion-input-otp.cjs.entry.js +163 -163
- package/dist/cjs/ionic.cjs.js +1 -1
- package/dist/cjs/loader.cjs.js +1 -1
- package/dist/collection/components/input-otp/input-otp.js +183 -183
- package/dist/docs.json +1 -1
- package/dist/esm/ion-input-otp.entry.js +163 -163
- package/dist/esm/ionic.js +1 -1
- package/dist/esm/loader.js +1 -1
- package/dist/ionic/ionic.esm.js +1 -1
- package/dist/ionic/{p-702c7264.entry.js → p-cc51b53c.entry.js} +1 -1
- package/dist/types/components/input-otp/input-otp.d.ts +64 -64
- package/hydrate/index.js +164 -164
- package/hydrate/index.mjs +164 -164
- package/package.json +1 -1
|
@@ -43,10 +43,6 @@ export class InputOTP {
|
|
|
43
43
|
* If `true`, the user cannot modify the value.
|
|
44
44
|
*/
|
|
45
45
|
this.readonly = false;
|
|
46
|
-
/**
|
|
47
|
-
* The size of the input boxes.
|
|
48
|
-
*/
|
|
49
|
-
this.size = 'medium';
|
|
50
46
|
/**
|
|
51
47
|
* The shape of the input boxes.
|
|
52
48
|
* If "round" they will have an increased border radius.
|
|
@@ -54,6 +50,10 @@ export class InputOTP {
|
|
|
54
50
|
* If "soft" they will have a soft border radius.
|
|
55
51
|
*/
|
|
56
52
|
this.shape = 'round';
|
|
53
|
+
/**
|
|
54
|
+
* The size of the input boxes.
|
|
55
|
+
*/
|
|
56
|
+
this.size = 'medium';
|
|
57
57
|
/**
|
|
58
58
|
* The type of input allowed in the input boxes.
|
|
59
59
|
*/
|
|
@@ -62,34 +62,63 @@ export class InputOTP {
|
|
|
62
62
|
* The value of the input group.
|
|
63
63
|
*/
|
|
64
64
|
this.value = '';
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
65
|
+
/**
|
|
66
|
+
* Handles the focus behavior for the input OTP component.
|
|
67
|
+
*
|
|
68
|
+
* Focus behavior:
|
|
69
|
+
* 1. Keyboard navigation: Allow normal focus movement
|
|
70
|
+
* 2. Mouse click:
|
|
71
|
+
* - If clicked box has value: Focus that box
|
|
72
|
+
* - If clicked box is empty: Focus first empty box
|
|
73
|
+
*
|
|
74
|
+
* Emits the `ionFocus` event when the input group gains focus.
|
|
75
|
+
*/
|
|
76
|
+
this.onFocus = (index) => (event) => {
|
|
77
|
+
var _a;
|
|
78
|
+
const { inputRefs } = this;
|
|
79
|
+
// Only emit ionFocus and set the focusedValue when the
|
|
80
|
+
// component first gains focus
|
|
81
|
+
if (!this.hasFocus) {
|
|
82
|
+
this.ionFocus.emit(event);
|
|
83
|
+
this.focusedValue = this.value;
|
|
82
84
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
85
|
+
this.hasFocus = true;
|
|
86
|
+
let finalIndex = index;
|
|
87
|
+
if (!this.isKeyboardNavigation) {
|
|
88
|
+
// If the clicked box has a value, focus it
|
|
89
|
+
// Otherwise focus the first empty box
|
|
90
|
+
const targetIndex = this.inputValues[index] ? index : this.getFirstEmptyIndex();
|
|
91
|
+
finalIndex = targetIndex === -1 ? this.length - 1 : targetIndex;
|
|
92
|
+
// Focus the target box
|
|
93
|
+
(_a = this.inputRefs[finalIndex]) === null || _a === void 0 ? void 0 : _a.focus();
|
|
88
94
|
}
|
|
89
|
-
|
|
90
|
-
|
|
95
|
+
// Update tabIndexes to match the focused box
|
|
96
|
+
inputRefs.forEach((input, i) => {
|
|
97
|
+
input.tabIndex = i === finalIndex ? 0 : -1;
|
|
98
|
+
});
|
|
99
|
+
// Reset the keyboard navigation flag
|
|
100
|
+
this.isKeyboardNavigation = false;
|
|
101
|
+
};
|
|
102
|
+
/**
|
|
103
|
+
* Handles the blur behavior for the input OTP component.
|
|
104
|
+
* Emits the `ionBlur` event when the input group loses focus.
|
|
105
|
+
*/
|
|
106
|
+
this.onBlur = (event) => {
|
|
107
|
+
const { inputRefs } = this;
|
|
108
|
+
const relatedTarget = event.relatedTarget;
|
|
109
|
+
// Do not emit blur if we're moving to another input box in the same component
|
|
110
|
+
const isInternalFocus = relatedTarget != null && inputRefs.includes(relatedTarget);
|
|
111
|
+
if (!isInternalFocus) {
|
|
112
|
+
this.hasFocus = false;
|
|
113
|
+
// Reset tabIndexes when focus leaves the component
|
|
114
|
+
this.updateTabIndexes();
|
|
115
|
+
// Always emit ionBlur when focus leaves the component
|
|
116
|
+
this.ionBlur.emit(event);
|
|
117
|
+
// Only emit ionChange if the value has actually changed
|
|
118
|
+
if (this.focusedValue !== this.value) {
|
|
119
|
+
this.emitIonChange(event);
|
|
120
|
+
}
|
|
91
121
|
}
|
|
92
|
-
this.updateValue(event);
|
|
93
122
|
};
|
|
94
123
|
/**
|
|
95
124
|
* Handles keyboard navigation and input for the OTP component.
|
|
@@ -175,6 +204,35 @@ export class InputOTP {
|
|
|
175
204
|
event.preventDefault();
|
|
176
205
|
}
|
|
177
206
|
};
|
|
207
|
+
this.onInput = (index) => (event) => {
|
|
208
|
+
const { validKeyPattern } = this;
|
|
209
|
+
const value = event.target.value;
|
|
210
|
+
// Only allow input if it's a single character and matches the pattern
|
|
211
|
+
if (value.length > 1 || (value.length > 0 && !validKeyPattern.test(value))) {
|
|
212
|
+
// Reset the input value if not valid
|
|
213
|
+
this.inputRefs[index].value = '';
|
|
214
|
+
this.inputValues[index] = '';
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
// Find the first empty box before or at the current index
|
|
218
|
+
let targetIndex = index;
|
|
219
|
+
for (let i = 0; i < index; i++) {
|
|
220
|
+
if (!this.inputValues[i] || this.inputValues[i] === '') {
|
|
221
|
+
targetIndex = i;
|
|
222
|
+
break;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
// Set the value at the target index
|
|
226
|
+
this.inputValues[targetIndex] = value;
|
|
227
|
+
// If the value was entered in a later box, clear the current box
|
|
228
|
+
if (targetIndex !== index) {
|
|
229
|
+
this.inputRefs[index].value = '';
|
|
230
|
+
}
|
|
231
|
+
if (value.length > 0) {
|
|
232
|
+
this.focusNext(targetIndex);
|
|
233
|
+
}
|
|
234
|
+
this.updateValue(event);
|
|
235
|
+
};
|
|
178
236
|
/**
|
|
179
237
|
* Handles pasting text into the input OTP component.
|
|
180
238
|
* This function prevents the default paste behavior and
|
|
@@ -218,64 +276,35 @@ export class InputOTP {
|
|
|
218
276
|
(_c = inputRefs[length - 1]) === null || _c === void 0 ? void 0 : _c.focus();
|
|
219
277
|
}
|
|
220
278
|
};
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
this.
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
}
|
|
251
|
-
// Update tabIndexes to match the focused box
|
|
252
|
-
inputRefs.forEach((input, i) => {
|
|
253
|
-
input.tabIndex = i === finalIndex ? 0 : -1;
|
|
254
|
-
});
|
|
255
|
-
// Reset the keyboard navigation flag
|
|
256
|
-
this.isKeyboardNavigation = false;
|
|
257
|
-
};
|
|
258
|
-
/**
|
|
259
|
-
* Handles the blur behavior for the input OTP component.
|
|
260
|
-
* Emits the `ionBlur` event when the input group loses focus.
|
|
261
|
-
*/
|
|
262
|
-
this.onBlur = (event) => {
|
|
263
|
-
const { inputRefs } = this;
|
|
264
|
-
const relatedTarget = event.relatedTarget;
|
|
265
|
-
// Do not emit blur if we're moving to another input box in the same component
|
|
266
|
-
const isInternalFocus = relatedTarget != null && inputRefs.includes(relatedTarget);
|
|
267
|
-
if (!isInternalFocus) {
|
|
268
|
-
this.hasFocus = false;
|
|
269
|
-
// Reset tabIndexes when focus leaves the component
|
|
270
|
-
this.updateTabIndexes();
|
|
271
|
-
// Always emit ionBlur when focus leaves the component
|
|
272
|
-
this.ionBlur.emit(event);
|
|
273
|
-
// Only emit ionChange if the value has actually changed
|
|
274
|
-
if (this.focusedValue !== this.value) {
|
|
275
|
-
this.emitIonChange(event);
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
};
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* Resets the value and focus state.
|
|
282
|
+
*/
|
|
283
|
+
async reset() {
|
|
284
|
+
this.value = '';
|
|
285
|
+
this.focusedValue = null;
|
|
286
|
+
this.hasFocus = false;
|
|
287
|
+
this.inputRefs.forEach((input) => {
|
|
288
|
+
input.blur();
|
|
289
|
+
});
|
|
290
|
+
this.updateTabIndexes();
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* Sets focus to an input box.
|
|
294
|
+
* @param index - The index of the input box to focus (0-based).
|
|
295
|
+
* If provided and the input box has a value, the input box at that index will be focused.
|
|
296
|
+
* Otherwise, the first empty input box or the last input if all are filled will be focused.
|
|
297
|
+
*/
|
|
298
|
+
async setFocus(index) {
|
|
299
|
+
var _a, _b;
|
|
300
|
+
if (typeof index === 'number') {
|
|
301
|
+
const validIndex = Math.max(0, Math.min(index, this.length - 1));
|
|
302
|
+
(_a = this.inputRefs[validIndex]) === null || _a === void 0 ? void 0 : _a.focus();
|
|
303
|
+
}
|
|
304
|
+
else {
|
|
305
|
+
const tabbableIndex = this.getTabbableIndex();
|
|
306
|
+
(_b = this.inputRefs[tabbableIndex]) === null || _b === void 0 ? void 0 : _b.focus();
|
|
307
|
+
}
|
|
279
308
|
}
|
|
280
309
|
valueChanged() {
|
|
281
310
|
this.initializeValues();
|
|
@@ -336,59 +365,6 @@ export class InputOTP {
|
|
|
336
365
|
componentDidLoad() {
|
|
337
366
|
this.updateTabIndexes();
|
|
338
367
|
}
|
|
339
|
-
/**
|
|
340
|
-
* Initializes the input values array based on the current value prop.
|
|
341
|
-
* This splits the value into individual characters and validates them against
|
|
342
|
-
* the allowed pattern. The values are then used as the values in the native
|
|
343
|
-
* input boxes and the value of the input group is updated.
|
|
344
|
-
*/
|
|
345
|
-
initializeValues() {
|
|
346
|
-
// Clear all input values
|
|
347
|
-
this.inputValues = Array(this.length).fill('');
|
|
348
|
-
// If the value is null, undefined, or an empty string, return
|
|
349
|
-
if (this.value == null || String(this.value).length === 0) {
|
|
350
|
-
return;
|
|
351
|
-
}
|
|
352
|
-
// Split the value into individual characters and validate
|
|
353
|
-
// them against the allowed pattern
|
|
354
|
-
const chars = String(this.value).split('').slice(0, this.length);
|
|
355
|
-
chars.forEach((char, index) => {
|
|
356
|
-
if (this.validKeyPattern.test(char)) {
|
|
357
|
-
this.inputValues[index] = char;
|
|
358
|
-
}
|
|
359
|
-
});
|
|
360
|
-
// Update the value without emitting events
|
|
361
|
-
this.value = this.inputValues.join('');
|
|
362
|
-
}
|
|
363
|
-
/**
|
|
364
|
-
* Resets the value and focus state.
|
|
365
|
-
*/
|
|
366
|
-
async reset() {
|
|
367
|
-
this.value = '';
|
|
368
|
-
this.focusedValue = null;
|
|
369
|
-
this.hasFocus = false;
|
|
370
|
-
this.inputRefs.forEach((input) => {
|
|
371
|
-
input.blur();
|
|
372
|
-
});
|
|
373
|
-
this.updateTabIndexes();
|
|
374
|
-
}
|
|
375
|
-
/**
|
|
376
|
-
* Sets focus to an input box.
|
|
377
|
-
* @param index - The index of the input box to focus (0-based).
|
|
378
|
-
* If provided and the input box has a value, the input box at that index will be focused.
|
|
379
|
-
* Otherwise, the first empty input box or the last input if all are filled will be focused.
|
|
380
|
-
*/
|
|
381
|
-
async setFocus(index) {
|
|
382
|
-
var _a, _b;
|
|
383
|
-
if (typeof index === 'number') {
|
|
384
|
-
const validIndex = Math.max(0, Math.min(index, this.length - 1));
|
|
385
|
-
(_a = this.inputRefs[validIndex]) === null || _a === void 0 ? void 0 : _a.focus();
|
|
386
|
-
}
|
|
387
|
-
else {
|
|
388
|
-
const tabbableIndex = this.getTabbableIndex();
|
|
389
|
-
(_b = this.inputRefs[tabbableIndex]) === null || _b === void 0 ? void 0 : _b.focus();
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
368
|
/**
|
|
393
369
|
* Get the regex pattern for allowed characters.
|
|
394
370
|
* If a pattern is provided, use it to create a regex pattern
|
|
@@ -425,6 +401,30 @@ export class InputOTP {
|
|
|
425
401
|
return 'text';
|
|
426
402
|
}
|
|
427
403
|
}
|
|
404
|
+
/**
|
|
405
|
+
* Initializes the input values array based on the current value prop.
|
|
406
|
+
* This splits the value into individual characters and validates them against
|
|
407
|
+
* the allowed pattern. The values are then used as the values in the native
|
|
408
|
+
* input boxes and the value of the input group is updated.
|
|
409
|
+
*/
|
|
410
|
+
initializeValues() {
|
|
411
|
+
// Clear all input values
|
|
412
|
+
this.inputValues = Array(this.length).fill('');
|
|
413
|
+
// If the value is null, undefined, or an empty string, return
|
|
414
|
+
if (this.value == null || String(this.value).length === 0) {
|
|
415
|
+
return;
|
|
416
|
+
}
|
|
417
|
+
// Split the value into individual characters and validate
|
|
418
|
+
// them against the allowed pattern
|
|
419
|
+
const chars = String(this.value).split('').slice(0, this.length);
|
|
420
|
+
chars.forEach((char, index) => {
|
|
421
|
+
if (this.validKeyPattern.test(char)) {
|
|
422
|
+
this.inputValues[index] = char;
|
|
423
|
+
}
|
|
424
|
+
});
|
|
425
|
+
// Update the value without emitting events
|
|
426
|
+
this.value = this.inputValues.join('');
|
|
427
|
+
}
|
|
428
428
|
/**
|
|
429
429
|
* Updates the value of the input group.
|
|
430
430
|
* This updates the value of the input group and emits an `ionChange` event.
|
|
@@ -483,12 +483,27 @@ export class InputOTP {
|
|
|
483
483
|
}
|
|
484
484
|
}
|
|
485
485
|
/**
|
|
486
|
-
*
|
|
487
|
-
*
|
|
486
|
+
* Searches through the input values and returns the index
|
|
487
|
+
* of the first empty input.
|
|
488
|
+
* Returns -1 if all inputs are filled.
|
|
488
489
|
*/
|
|
489
|
-
|
|
490
|
+
getFirstEmptyIndex() {
|
|
491
|
+
var _a;
|
|
492
|
+
const { inputValues, length } = this;
|
|
493
|
+
// Create an array of the same length as the input OTP
|
|
494
|
+
// and fill it with the input values
|
|
495
|
+
const values = Array.from({ length }, (_, i) => inputValues[i] || '');
|
|
496
|
+
return (_a = values.findIndex((value) => !value || value === '')) !== null && _a !== void 0 ? _a : -1;
|
|
497
|
+
}
|
|
498
|
+
/**
|
|
499
|
+
* Returns the index of the input that should be tabbed to.
|
|
500
|
+
* If all inputs are filled, returns the last input's index.
|
|
501
|
+
* Otherwise, returns the index of the first empty input.
|
|
502
|
+
*/
|
|
503
|
+
getTabbableIndex() {
|
|
490
504
|
const { length } = this;
|
|
491
|
-
|
|
505
|
+
const firstEmptyIndex = this.getFirstEmptyIndex();
|
|
506
|
+
return firstEmptyIndex === -1 ? length - 1 : firstEmptyIndex;
|
|
492
507
|
}
|
|
493
508
|
/**
|
|
494
509
|
* Updates the tabIndexes for the input boxes.
|
|
@@ -516,27 +531,12 @@ export class InputOTP {
|
|
|
516
531
|
});
|
|
517
532
|
}
|
|
518
533
|
/**
|
|
519
|
-
*
|
|
520
|
-
*
|
|
521
|
-
* Returns -1 if all inputs are filled.
|
|
522
|
-
*/
|
|
523
|
-
getFirstEmptyIndex() {
|
|
524
|
-
var _a;
|
|
525
|
-
const { inputValues, length } = this;
|
|
526
|
-
// Create an array of the same length as the input OTP
|
|
527
|
-
// and fill it with the input values
|
|
528
|
-
const values = Array.from({ length }, (_, i) => inputValues[i] || '');
|
|
529
|
-
return (_a = values.findIndex((value) => !value || value === '')) !== null && _a !== void 0 ? _a : -1;
|
|
530
|
-
}
|
|
531
|
-
/**
|
|
532
|
-
* Returns the index of the input that should be tabbed to.
|
|
533
|
-
* If all inputs are filled, returns the last input's index.
|
|
534
|
-
* Otherwise, returns the index of the first empty input.
|
|
534
|
+
* Determines if a separator should be shown for a given index by
|
|
535
|
+
* checking if the index is included in the parsed separators array.
|
|
535
536
|
*/
|
|
536
|
-
|
|
537
|
+
showSeparator(index) {
|
|
537
538
|
const { length } = this;
|
|
538
|
-
|
|
539
|
-
return firstEmptyIndex === -1 ? length - 1 : firstEmptyIndex;
|
|
539
|
+
return this.parsedSeparators.includes(index + 1) && index < length - 1;
|
|
540
540
|
}
|
|
541
541
|
render() {
|
|
542
542
|
var _a, _b;
|
|
@@ -738,26 +738,6 @@ export class InputOTP {
|
|
|
738
738
|
"reflect": true,
|
|
739
739
|
"defaultValue": "false"
|
|
740
740
|
},
|
|
741
|
-
"size": {
|
|
742
|
-
"type": "string",
|
|
743
|
-
"attribute": "size",
|
|
744
|
-
"mutable": false,
|
|
745
|
-
"complexType": {
|
|
746
|
-
"original": "'small' | 'medium' | 'large'",
|
|
747
|
-
"resolved": "\"large\" | \"medium\" | \"small\"",
|
|
748
|
-
"references": {}
|
|
749
|
-
},
|
|
750
|
-
"required": false,
|
|
751
|
-
"optional": false,
|
|
752
|
-
"docs": {
|
|
753
|
-
"tags": [],
|
|
754
|
-
"text": "The size of the input boxes."
|
|
755
|
-
},
|
|
756
|
-
"getter": false,
|
|
757
|
-
"setter": false,
|
|
758
|
-
"reflect": false,
|
|
759
|
-
"defaultValue": "'medium'"
|
|
760
|
-
},
|
|
761
741
|
"separators": {
|
|
762
742
|
"type": "string",
|
|
763
743
|
"attribute": "separators",
|
|
@@ -797,6 +777,26 @@ export class InputOTP {
|
|
|
797
777
|
"reflect": false,
|
|
798
778
|
"defaultValue": "'round'"
|
|
799
779
|
},
|
|
780
|
+
"size": {
|
|
781
|
+
"type": "string",
|
|
782
|
+
"attribute": "size",
|
|
783
|
+
"mutable": false,
|
|
784
|
+
"complexType": {
|
|
785
|
+
"original": "'small' | 'medium' | 'large'",
|
|
786
|
+
"resolved": "\"large\" | \"medium\" | \"small\"",
|
|
787
|
+
"references": {}
|
|
788
|
+
},
|
|
789
|
+
"required": false,
|
|
790
|
+
"optional": false,
|
|
791
|
+
"docs": {
|
|
792
|
+
"tags": [],
|
|
793
|
+
"text": "The size of the input boxes."
|
|
794
|
+
},
|
|
795
|
+
"getter": false,
|
|
796
|
+
"setter": false,
|
|
797
|
+
"reflect": false,
|
|
798
|
+
"defaultValue": "'medium'"
|
|
799
|
+
},
|
|
800
800
|
"type": {
|
|
801
801
|
"type": "string",
|
|
802
802
|
"attribute": "type",
|
package/dist/docs.json
CHANGED