@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
|
@@ -55,10 +55,6 @@ const InputOTP = /*@__PURE__*/ proxyCustomElement(class InputOTP extends HTMLEle
|
|
|
55
55
|
* If `true`, the user cannot modify the value.
|
|
56
56
|
*/
|
|
57
57
|
this.readonly = false;
|
|
58
|
-
/**
|
|
59
|
-
* The size of the input boxes.
|
|
60
|
-
*/
|
|
61
|
-
this.size = 'medium';
|
|
62
58
|
/**
|
|
63
59
|
* The shape of the input boxes.
|
|
64
60
|
* If "round" they will have an increased border radius.
|
|
@@ -66,6 +62,10 @@ const InputOTP = /*@__PURE__*/ proxyCustomElement(class InputOTP extends HTMLEle
|
|
|
66
62
|
* If "soft" they will have a soft border radius.
|
|
67
63
|
*/
|
|
68
64
|
this.shape = 'round';
|
|
65
|
+
/**
|
|
66
|
+
* The size of the input boxes.
|
|
67
|
+
*/
|
|
68
|
+
this.size = 'medium';
|
|
69
69
|
/**
|
|
70
70
|
* The type of input allowed in the input boxes.
|
|
71
71
|
*/
|
|
@@ -74,34 +74,63 @@ const InputOTP = /*@__PURE__*/ proxyCustomElement(class InputOTP extends HTMLEle
|
|
|
74
74
|
* The value of the input group.
|
|
75
75
|
*/
|
|
76
76
|
this.value = '';
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
77
|
+
/**
|
|
78
|
+
* Handles the focus behavior for the input OTP component.
|
|
79
|
+
*
|
|
80
|
+
* Focus behavior:
|
|
81
|
+
* 1. Keyboard navigation: Allow normal focus movement
|
|
82
|
+
* 2. Mouse click:
|
|
83
|
+
* - If clicked box has value: Focus that box
|
|
84
|
+
* - If clicked box is empty: Focus first empty box
|
|
85
|
+
*
|
|
86
|
+
* Emits the `ionFocus` event when the input group gains focus.
|
|
87
|
+
*/
|
|
88
|
+
this.onFocus = (index) => (event) => {
|
|
89
|
+
var _a;
|
|
90
|
+
const { inputRefs } = this;
|
|
91
|
+
// Only emit ionFocus and set the focusedValue when the
|
|
92
|
+
// component first gains focus
|
|
93
|
+
if (!this.hasFocus) {
|
|
94
|
+
this.ionFocus.emit(event);
|
|
95
|
+
this.focusedValue = this.value;
|
|
94
96
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
97
|
+
this.hasFocus = true;
|
|
98
|
+
let finalIndex = index;
|
|
99
|
+
if (!this.isKeyboardNavigation) {
|
|
100
|
+
// If the clicked box has a value, focus it
|
|
101
|
+
// Otherwise focus the first empty box
|
|
102
|
+
const targetIndex = this.inputValues[index] ? index : this.getFirstEmptyIndex();
|
|
103
|
+
finalIndex = targetIndex === -1 ? this.length - 1 : targetIndex;
|
|
104
|
+
// Focus the target box
|
|
105
|
+
(_a = this.inputRefs[finalIndex]) === null || _a === void 0 ? void 0 : _a.focus();
|
|
100
106
|
}
|
|
101
|
-
|
|
102
|
-
|
|
107
|
+
// Update tabIndexes to match the focused box
|
|
108
|
+
inputRefs.forEach((input, i) => {
|
|
109
|
+
input.tabIndex = i === finalIndex ? 0 : -1;
|
|
110
|
+
});
|
|
111
|
+
// Reset the keyboard navigation flag
|
|
112
|
+
this.isKeyboardNavigation = false;
|
|
113
|
+
};
|
|
114
|
+
/**
|
|
115
|
+
* Handles the blur behavior for the input OTP component.
|
|
116
|
+
* Emits the `ionBlur` event when the input group loses focus.
|
|
117
|
+
*/
|
|
118
|
+
this.onBlur = (event) => {
|
|
119
|
+
const { inputRefs } = this;
|
|
120
|
+
const relatedTarget = event.relatedTarget;
|
|
121
|
+
// Do not emit blur if we're moving to another input box in the same component
|
|
122
|
+
const isInternalFocus = relatedTarget != null && inputRefs.includes(relatedTarget);
|
|
123
|
+
if (!isInternalFocus) {
|
|
124
|
+
this.hasFocus = false;
|
|
125
|
+
// Reset tabIndexes when focus leaves the component
|
|
126
|
+
this.updateTabIndexes();
|
|
127
|
+
// Always emit ionBlur when focus leaves the component
|
|
128
|
+
this.ionBlur.emit(event);
|
|
129
|
+
// Only emit ionChange if the value has actually changed
|
|
130
|
+
if (this.focusedValue !== this.value) {
|
|
131
|
+
this.emitIonChange(event);
|
|
132
|
+
}
|
|
103
133
|
}
|
|
104
|
-
this.updateValue(event);
|
|
105
134
|
};
|
|
106
135
|
/**
|
|
107
136
|
* Handles keyboard navigation and input for the OTP component.
|
|
@@ -187,6 +216,35 @@ const InputOTP = /*@__PURE__*/ proxyCustomElement(class InputOTP extends HTMLEle
|
|
|
187
216
|
event.preventDefault();
|
|
188
217
|
}
|
|
189
218
|
};
|
|
219
|
+
this.onInput = (index) => (event) => {
|
|
220
|
+
const { validKeyPattern } = this;
|
|
221
|
+
const value = event.target.value;
|
|
222
|
+
// Only allow input if it's a single character and matches the pattern
|
|
223
|
+
if (value.length > 1 || (value.length > 0 && !validKeyPattern.test(value))) {
|
|
224
|
+
// Reset the input value if not valid
|
|
225
|
+
this.inputRefs[index].value = '';
|
|
226
|
+
this.inputValues[index] = '';
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
// Find the first empty box before or at the current index
|
|
230
|
+
let targetIndex = index;
|
|
231
|
+
for (let i = 0; i < index; i++) {
|
|
232
|
+
if (!this.inputValues[i] || this.inputValues[i] === '') {
|
|
233
|
+
targetIndex = i;
|
|
234
|
+
break;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
// Set the value at the target index
|
|
238
|
+
this.inputValues[targetIndex] = value;
|
|
239
|
+
// If the value was entered in a later box, clear the current box
|
|
240
|
+
if (targetIndex !== index) {
|
|
241
|
+
this.inputRefs[index].value = '';
|
|
242
|
+
}
|
|
243
|
+
if (value.length > 0) {
|
|
244
|
+
this.focusNext(targetIndex);
|
|
245
|
+
}
|
|
246
|
+
this.updateValue(event);
|
|
247
|
+
};
|
|
190
248
|
/**
|
|
191
249
|
* Handles pasting text into the input OTP component.
|
|
192
250
|
* This function prevents the default paste behavior and
|
|
@@ -230,64 +288,35 @@ const InputOTP = /*@__PURE__*/ proxyCustomElement(class InputOTP extends HTMLEle
|
|
|
230
288
|
(_c = inputRefs[length - 1]) === null || _c === void 0 ? void 0 : _c.focus();
|
|
231
289
|
}
|
|
232
290
|
};
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
this.
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
}
|
|
263
|
-
// Update tabIndexes to match the focused box
|
|
264
|
-
inputRefs.forEach((input, i) => {
|
|
265
|
-
input.tabIndex = i === finalIndex ? 0 : -1;
|
|
266
|
-
});
|
|
267
|
-
// Reset the keyboard navigation flag
|
|
268
|
-
this.isKeyboardNavigation = false;
|
|
269
|
-
};
|
|
270
|
-
/**
|
|
271
|
-
* Handles the blur behavior for the input OTP component.
|
|
272
|
-
* Emits the `ionBlur` event when the input group loses focus.
|
|
273
|
-
*/
|
|
274
|
-
this.onBlur = (event) => {
|
|
275
|
-
const { inputRefs } = this;
|
|
276
|
-
const relatedTarget = event.relatedTarget;
|
|
277
|
-
// Do not emit blur if we're moving to another input box in the same component
|
|
278
|
-
const isInternalFocus = relatedTarget != null && inputRefs.includes(relatedTarget);
|
|
279
|
-
if (!isInternalFocus) {
|
|
280
|
-
this.hasFocus = false;
|
|
281
|
-
// Reset tabIndexes when focus leaves the component
|
|
282
|
-
this.updateTabIndexes();
|
|
283
|
-
// Always emit ionBlur when focus leaves the component
|
|
284
|
-
this.ionBlur.emit(event);
|
|
285
|
-
// Only emit ionChange if the value has actually changed
|
|
286
|
-
if (this.focusedValue !== this.value) {
|
|
287
|
-
this.emitIonChange(event);
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
};
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* Resets the value and focus state.
|
|
294
|
+
*/
|
|
295
|
+
async reset() {
|
|
296
|
+
this.value = '';
|
|
297
|
+
this.focusedValue = null;
|
|
298
|
+
this.hasFocus = false;
|
|
299
|
+
this.inputRefs.forEach((input) => {
|
|
300
|
+
input.blur();
|
|
301
|
+
});
|
|
302
|
+
this.updateTabIndexes();
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* Sets focus to an input box.
|
|
306
|
+
* @param index - The index of the input box to focus (0-based).
|
|
307
|
+
* If provided and the input box has a value, the input box at that index will be focused.
|
|
308
|
+
* Otherwise, the first empty input box or the last input if all are filled will be focused.
|
|
309
|
+
*/
|
|
310
|
+
async setFocus(index) {
|
|
311
|
+
var _a, _b;
|
|
312
|
+
if (typeof index === 'number') {
|
|
313
|
+
const validIndex = Math.max(0, Math.min(index, this.length - 1));
|
|
314
|
+
(_a = this.inputRefs[validIndex]) === null || _a === void 0 ? void 0 : _a.focus();
|
|
315
|
+
}
|
|
316
|
+
else {
|
|
317
|
+
const tabbableIndex = this.getTabbableIndex();
|
|
318
|
+
(_b = this.inputRefs[tabbableIndex]) === null || _b === void 0 ? void 0 : _b.focus();
|
|
319
|
+
}
|
|
291
320
|
}
|
|
292
321
|
valueChanged() {
|
|
293
322
|
this.initializeValues();
|
|
@@ -348,59 +377,6 @@ const InputOTP = /*@__PURE__*/ proxyCustomElement(class InputOTP extends HTMLEle
|
|
|
348
377
|
componentDidLoad() {
|
|
349
378
|
this.updateTabIndexes();
|
|
350
379
|
}
|
|
351
|
-
/**
|
|
352
|
-
* Initializes the input values array based on the current value prop.
|
|
353
|
-
* This splits the value into individual characters and validates them against
|
|
354
|
-
* the allowed pattern. The values are then used as the values in the native
|
|
355
|
-
* input boxes and the value of the input group is updated.
|
|
356
|
-
*/
|
|
357
|
-
initializeValues() {
|
|
358
|
-
// Clear all input values
|
|
359
|
-
this.inputValues = Array(this.length).fill('');
|
|
360
|
-
// If the value is null, undefined, or an empty string, return
|
|
361
|
-
if (this.value == null || String(this.value).length === 0) {
|
|
362
|
-
return;
|
|
363
|
-
}
|
|
364
|
-
// Split the value into individual characters and validate
|
|
365
|
-
// them against the allowed pattern
|
|
366
|
-
const chars = String(this.value).split('').slice(0, this.length);
|
|
367
|
-
chars.forEach((char, index) => {
|
|
368
|
-
if (this.validKeyPattern.test(char)) {
|
|
369
|
-
this.inputValues[index] = char;
|
|
370
|
-
}
|
|
371
|
-
});
|
|
372
|
-
// Update the value without emitting events
|
|
373
|
-
this.value = this.inputValues.join('');
|
|
374
|
-
}
|
|
375
|
-
/**
|
|
376
|
-
* Resets the value and focus state.
|
|
377
|
-
*/
|
|
378
|
-
async reset() {
|
|
379
|
-
this.value = '';
|
|
380
|
-
this.focusedValue = null;
|
|
381
|
-
this.hasFocus = false;
|
|
382
|
-
this.inputRefs.forEach((input) => {
|
|
383
|
-
input.blur();
|
|
384
|
-
});
|
|
385
|
-
this.updateTabIndexes();
|
|
386
|
-
}
|
|
387
|
-
/**
|
|
388
|
-
* Sets focus to an input box.
|
|
389
|
-
* @param index - The index of the input box to focus (0-based).
|
|
390
|
-
* If provided and the input box has a value, the input box at that index will be focused.
|
|
391
|
-
* Otherwise, the first empty input box or the last input if all are filled will be focused.
|
|
392
|
-
*/
|
|
393
|
-
async setFocus(index) {
|
|
394
|
-
var _a, _b;
|
|
395
|
-
if (typeof index === 'number') {
|
|
396
|
-
const validIndex = Math.max(0, Math.min(index, this.length - 1));
|
|
397
|
-
(_a = this.inputRefs[validIndex]) === null || _a === void 0 ? void 0 : _a.focus();
|
|
398
|
-
}
|
|
399
|
-
else {
|
|
400
|
-
const tabbableIndex = this.getTabbableIndex();
|
|
401
|
-
(_b = this.inputRefs[tabbableIndex]) === null || _b === void 0 ? void 0 : _b.focus();
|
|
402
|
-
}
|
|
403
|
-
}
|
|
404
380
|
/**
|
|
405
381
|
* Get the regex pattern for allowed characters.
|
|
406
382
|
* If a pattern is provided, use it to create a regex pattern
|
|
@@ -437,6 +413,30 @@ const InputOTP = /*@__PURE__*/ proxyCustomElement(class InputOTP extends HTMLEle
|
|
|
437
413
|
return 'text';
|
|
438
414
|
}
|
|
439
415
|
}
|
|
416
|
+
/**
|
|
417
|
+
* Initializes the input values array based on the current value prop.
|
|
418
|
+
* This splits the value into individual characters and validates them against
|
|
419
|
+
* the allowed pattern. The values are then used as the values in the native
|
|
420
|
+
* input boxes and the value of the input group is updated.
|
|
421
|
+
*/
|
|
422
|
+
initializeValues() {
|
|
423
|
+
// Clear all input values
|
|
424
|
+
this.inputValues = Array(this.length).fill('');
|
|
425
|
+
// If the value is null, undefined, or an empty string, return
|
|
426
|
+
if (this.value == null || String(this.value).length === 0) {
|
|
427
|
+
return;
|
|
428
|
+
}
|
|
429
|
+
// Split the value into individual characters and validate
|
|
430
|
+
// them against the allowed pattern
|
|
431
|
+
const chars = String(this.value).split('').slice(0, this.length);
|
|
432
|
+
chars.forEach((char, index) => {
|
|
433
|
+
if (this.validKeyPattern.test(char)) {
|
|
434
|
+
this.inputValues[index] = char;
|
|
435
|
+
}
|
|
436
|
+
});
|
|
437
|
+
// Update the value without emitting events
|
|
438
|
+
this.value = this.inputValues.join('');
|
|
439
|
+
}
|
|
440
440
|
/**
|
|
441
441
|
* Updates the value of the input group.
|
|
442
442
|
* This updates the value of the input group and emits an `ionChange` event.
|
|
@@ -495,12 +495,27 @@ const InputOTP = /*@__PURE__*/ proxyCustomElement(class InputOTP extends HTMLEle
|
|
|
495
495
|
}
|
|
496
496
|
}
|
|
497
497
|
/**
|
|
498
|
-
*
|
|
499
|
-
*
|
|
498
|
+
* Searches through the input values and returns the index
|
|
499
|
+
* of the first empty input.
|
|
500
|
+
* Returns -1 if all inputs are filled.
|
|
500
501
|
*/
|
|
501
|
-
|
|
502
|
+
getFirstEmptyIndex() {
|
|
503
|
+
var _a;
|
|
504
|
+
const { inputValues, length } = this;
|
|
505
|
+
// Create an array of the same length as the input OTP
|
|
506
|
+
// and fill it with the input values
|
|
507
|
+
const values = Array.from({ length }, (_, i) => inputValues[i] || '');
|
|
508
|
+
return (_a = values.findIndex((value) => !value || value === '')) !== null && _a !== void 0 ? _a : -1;
|
|
509
|
+
}
|
|
510
|
+
/**
|
|
511
|
+
* Returns the index of the input that should be tabbed to.
|
|
512
|
+
* If all inputs are filled, returns the last input's index.
|
|
513
|
+
* Otherwise, returns the index of the first empty input.
|
|
514
|
+
*/
|
|
515
|
+
getTabbableIndex() {
|
|
502
516
|
const { length } = this;
|
|
503
|
-
|
|
517
|
+
const firstEmptyIndex = this.getFirstEmptyIndex();
|
|
518
|
+
return firstEmptyIndex === -1 ? length - 1 : firstEmptyIndex;
|
|
504
519
|
}
|
|
505
520
|
/**
|
|
506
521
|
* Updates the tabIndexes for the input boxes.
|
|
@@ -528,27 +543,12 @@ const InputOTP = /*@__PURE__*/ proxyCustomElement(class InputOTP extends HTMLEle
|
|
|
528
543
|
});
|
|
529
544
|
}
|
|
530
545
|
/**
|
|
531
|
-
*
|
|
532
|
-
*
|
|
533
|
-
* Returns -1 if all inputs are filled.
|
|
534
|
-
*/
|
|
535
|
-
getFirstEmptyIndex() {
|
|
536
|
-
var _a;
|
|
537
|
-
const { inputValues, length } = this;
|
|
538
|
-
// Create an array of the same length as the input OTP
|
|
539
|
-
// and fill it with the input values
|
|
540
|
-
const values = Array.from({ length }, (_, i) => inputValues[i] || '');
|
|
541
|
-
return (_a = values.findIndex((value) => !value || value === '')) !== null && _a !== void 0 ? _a : -1;
|
|
542
|
-
}
|
|
543
|
-
/**
|
|
544
|
-
* Returns the index of the input that should be tabbed to.
|
|
545
|
-
* If all inputs are filled, returns the last input's index.
|
|
546
|
-
* Otherwise, returns the index of the first empty input.
|
|
546
|
+
* Determines if a separator should be shown for a given index by
|
|
547
|
+
* checking if the index is included in the parsed separators array.
|
|
547
548
|
*/
|
|
548
|
-
|
|
549
|
+
showSeparator(index) {
|
|
549
550
|
const { length } = this;
|
|
550
|
-
|
|
551
|
-
return firstEmptyIndex === -1 ? length - 1 : firstEmptyIndex;
|
|
551
|
+
return this.parsedSeparators.includes(index + 1) && index < length - 1;
|
|
552
552
|
}
|
|
553
553
|
render() {
|
|
554
554
|
var _a, _b;
|
|
@@ -590,9 +590,9 @@ const InputOTP = /*@__PURE__*/ proxyCustomElement(class InputOTP extends HTMLEle
|
|
|
590
590
|
"length": [2],
|
|
591
591
|
"pattern": [1],
|
|
592
592
|
"readonly": [516],
|
|
593
|
-
"size": [1],
|
|
594
593
|
"separators": [1],
|
|
595
594
|
"shape": [1],
|
|
595
|
+
"size": [1],
|
|
596
596
|
"type": [1],
|
|
597
597
|
"value": [1032],
|
|
598
598
|
"inputValues": [32],
|