@ionic/core 8.5.7-dev.11748379940.12698faf → 8.5.7-dev.11748545890.14d6a067

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.
@@ -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
- this.onInput = (index) => (event) => {
78
- const { validKeyPattern } = this;
79
- const value = event.target.value;
80
- // Only allow input if it's a single character and matches the pattern
81
- if (value.length > 1 || (value.length > 0 && !validKeyPattern.test(value))) {
82
- // Reset the input value if not valid
83
- this.inputRefs[index].value = '';
84
- this.inputValues[index] = '';
85
- return;
86
- }
87
- // Find the first empty box before or at the current index
88
- let targetIndex = index;
89
- for (let i = 0; i < index; i++) {
90
- if (!this.inputValues[i] || this.inputValues[i] === '') {
91
- targetIndex = i;
92
- break;
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
- // Set the value at the target index
96
- this.inputValues[targetIndex] = value;
97
- // If the value was entered in a later box, clear the current box
98
- if (targetIndex !== index) {
99
- this.inputRefs[index].value = '';
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
- if (value.length > 0) {
102
- this.focusNext(targetIndex);
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,67 +288,27 @@ 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
- * Handles the focus behavior for the input OTP component.
235
- *
236
- * Focus behavior:
237
- * 1. Keyboard navigation: Allow normal focus movement
238
- * 2. Mouse click:
239
- * - If clicked box has value: Focus that box
240
- * - If clicked box is empty: Focus first empty box
241
- *
242
- * Emits the `ionFocus` event when the input group gains focus.
243
- */
244
- this.onFocus = (index) => (event) => {
245
- var _a;
246
- const { inputRefs } = this;
247
- // Only emit ionFocus and set the focusedValue when the
248
- // component first gains focus
249
- if (!this.hasFocus) {
250
- this.ionFocus.emit(event);
251
- this.focusedValue = this.value;
252
- }
253
- this.hasFocus = true;
254
- let finalIndex = index;
255
- if (!this.isKeyboardNavigation) {
256
- // If the clicked box has a value, focus it
257
- // Otherwise focus the first empty box
258
- const targetIndex = this.inputValues[index] ? index : this.getFirstEmptyIndex();
259
- finalIndex = targetIndex === -1 ? this.length - 1 : targetIndex;
260
- // Focus the target box
261
- (_a = this.inputRefs[finalIndex]) === null || _a === void 0 ? void 0 : _a.focus();
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
+ * 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
+ }
291
308
  }
292
309
  valueChanged() {
293
310
  this.initializeValues();
311
+ this.updateTabIndexes();
294
312
  }
295
313
  /**
296
314
  * Processes the separators prop into an array of numbers.
@@ -348,59 +366,6 @@ const InputOTP = /*@__PURE__*/ proxyCustomElement(class InputOTP extends HTMLEle
348
366
  componentDidLoad() {
349
367
  this.updateTabIndexes();
350
368
  }
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
369
  /**
405
370
  * Get the regex pattern for allowed characters.
406
371
  * If a pattern is provided, use it to create a regex pattern
@@ -437,6 +402,30 @@ const InputOTP = /*@__PURE__*/ proxyCustomElement(class InputOTP extends HTMLEle
437
402
  return 'text';
438
403
  }
439
404
  }
405
+ /**
406
+ * Initializes the input values array based on the current value prop.
407
+ * This splits the value into individual characters and validates them against
408
+ * the allowed pattern. The values are then used as the values in the native
409
+ * input boxes and the value of the input group is updated.
410
+ */
411
+ initializeValues() {
412
+ // Clear all input values
413
+ this.inputValues = Array(this.length).fill('');
414
+ // If the value is null, undefined, or an empty string, return
415
+ if (this.value == null || String(this.value).length === 0) {
416
+ return;
417
+ }
418
+ // Split the value into individual characters and validate
419
+ // them against the allowed pattern
420
+ const chars = String(this.value).split('').slice(0, this.length);
421
+ chars.forEach((char, index) => {
422
+ if (this.validKeyPattern.test(char)) {
423
+ this.inputValues[index] = char;
424
+ }
425
+ });
426
+ // Update the value without emitting events
427
+ this.value = this.inputValues.join('');
428
+ }
440
429
  /**
441
430
  * Updates the value of the input group.
442
431
  * This updates the value of the input group and emits an `ionChange` event.
@@ -450,7 +439,6 @@ const InputOTP = /*@__PURE__*/ proxyCustomElement(class InputOTP extends HTMLEle
450
439
  if (newValue.length === length) {
451
440
  this.ionComplete.emit({ value: newValue });
452
441
  }
453
- this.updateTabIndexes();
454
442
  }
455
443
  /**
456
444
  * Emits an `ionChange` event.
@@ -495,12 +483,27 @@ const InputOTP = /*@__PURE__*/ proxyCustomElement(class InputOTP extends HTMLEle
495
483
  }
496
484
  }
497
485
  /**
498
- * Determines if a separator should be shown for a given index by
499
- * checking if the index is included in the parsed separators array.
486
+ * Searches through the input values and returns the index
487
+ * of the first empty input.
488
+ * Returns -1 if all inputs are filled.
500
489
  */
501
- showSeparator(index) {
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() {
502
504
  const { length } = this;
503
- return this.parsedSeparators.includes(index + 1) && index < length - 1;
505
+ const firstEmptyIndex = this.getFirstEmptyIndex();
506
+ return firstEmptyIndex === -1 ? length - 1 : firstEmptyIndex;
504
507
  }
505
508
  /**
506
509
  * Updates the tabIndexes for the input boxes.
@@ -528,27 +531,12 @@ const InputOTP = /*@__PURE__*/ proxyCustomElement(class InputOTP extends HTMLEle
528
531
  });
529
532
  }
530
533
  /**
531
- * Searches through the input values and returns the index
532
- * of the first empty input.
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.
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.
547
536
  */
548
- getTabbableIndex() {
537
+ showSeparator(index) {
549
538
  const { length } = this;
550
- const firstEmptyIndex = this.getFirstEmptyIndex();
551
- return firstEmptyIndex === -1 ? length - 1 : firstEmptyIndex;
539
+ return this.parsedSeparators.includes(index + 1) && index < length - 1;
552
540
  }
553
541
  render() {
554
542
  var _a, _b;
@@ -558,7 +546,7 @@ const InputOTP = /*@__PURE__*/ proxyCustomElement(class InputOTP extends HTMLEle
558
546
  const tabbableIndex = this.getTabbableIndex();
559
547
  const pattern = this.getPattern();
560
548
  const hasDescription = ((_b = (_a = el.querySelector('.input-otp-description')) === null || _a === void 0 ? void 0 : _a.textContent) === null || _b === void 0 ? void 0 : _b.trim()) !== '';
561
- return (h(Host, { key: '973743fa99d77dbdaaf9b630b64180a189b5d778', class: createColorClasses(color, {
549
+ return (h(Host, { key: 'e87987e639fcff31612db32baa45ef928f1214fe', class: createColorClasses(color, {
562
550
  [mode]: true,
563
551
  'has-focus': hasFocus,
564
552
  [`input-otp-size-${size}`]: true,
@@ -566,10 +554,10 @@ const InputOTP = /*@__PURE__*/ proxyCustomElement(class InputOTP extends HTMLEle
566
554
  [`input-otp-fill-${fill}`]: true,
567
555
  'input-otp-disabled': disabled,
568
556
  'input-otp-readonly': readonly,
569
- }) }, h("div", Object.assign({ key: '3891cbdc07d4fa017ea04590bbb6225ab68deff2', role: "group", "aria-label": "One-time password input", class: "input-otp-group" }, inheritedAttributes), Array.from({ length }).map((_, index) => (h(Fragment, null, h("div", { class: "native-wrapper" }, h("input", { class: "native-input", id: `${inputId}-${index}`, "aria-label": `Input ${index + 1} of ${length}`, type: "text", autoCapitalize: autocapitalize, inputmode: inputmode, maxLength: 1, pattern: pattern, disabled: disabled, readOnly: readonly, tabIndex: index === tabbableIndex ? 0 : -1, value: inputValues[index] || '', autocomplete: index === 0 ? 'one-time-code' : 'off', ref: (el) => (inputRefs[index] = el), onInput: this.onInput(index), onBlur: this.onBlur, onFocus: this.onFocus(index), onKeyDown: this.onKeyDown(index), onPaste: this.onPaste })), this.showSeparator(index) && h("div", { class: "input-otp-separator" }))))), h("div", { key: '0d3cfa8c081552d0c52a544a1c52c0e3d5d4f532', class: {
557
+ }) }, h("div", Object.assign({ key: '10d82d5c21171e3673b337da472139e8c9e077d7', role: "group", "aria-label": "One-time password input", class: "input-otp-group" }, inheritedAttributes), Array.from({ length }).map((_, index) => (h(Fragment, null, h("div", { class: "native-wrapper" }, h("input", { class: "native-input", id: `${inputId}-${index}`, "aria-label": `Input ${index + 1} of ${length}`, type: "text", autoCapitalize: autocapitalize, inputmode: inputmode, maxLength: 1, pattern: pattern, disabled: disabled, readOnly: readonly, tabIndex: index === tabbableIndex ? 0 : -1, value: inputValues[index] || '', autocomplete: index === 0 ? 'one-time-code' : 'off', ref: (el) => (inputRefs[index] = el), onInput: this.onInput(index), onBlur: this.onBlur, onFocus: this.onFocus(index), onKeyDown: this.onKeyDown(index), onPaste: this.onPaste })), this.showSeparator(index) && h("div", { class: "input-otp-separator" }))))), h("div", { key: '3cbb5dd138c5640c71c51a5088ad1047a74d3ad6', class: {
570
558
  'input-otp-description': true,
571
559
  'input-otp-description-hidden': !hasDescription,
572
- } }, h("slot", { key: '13c3f795956749ccdf396bfb0ff882a9c9e9ce81' }))));
560
+ } }, h("slot", { key: '9fdeca4d1eebd60334a48b103229d43849bbb0ac' }))));
573
561
  }
574
562
  get el() { return this; }
575
563
  static get watchers() { return {
@@ -590,14 +578,13 @@ const InputOTP = /*@__PURE__*/ proxyCustomElement(class InputOTP extends HTMLEle
590
578
  "length": [2],
591
579
  "pattern": [1],
592
580
  "readonly": [516],
593
- "size": [1],
594
581
  "separators": [1],
595
582
  "shape": [1],
583
+ "size": [1],
596
584
  "type": [1],
597
585
  "value": [1032],
598
586
  "inputValues": [32],
599
587
  "hasFocus": [32],
600
- "reset": [64],
601
588
  "setFocus": [64]
602
589
  }, undefined, {
603
590
  "value": ["valueChanged"],