@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.
@@ -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
- this.onInput = (index) => (event) => {
66
- const { validKeyPattern } = this;
67
- const value = event.target.value;
68
- // Only allow input if it's a single character and matches the pattern
69
- if (value.length > 1 || (value.length > 0 && !validKeyPattern.test(value))) {
70
- // Reset the input value if not valid
71
- this.inputRefs[index].value = '';
72
- this.inputValues[index] = '';
73
- return;
74
- }
75
- // Find the first empty box before or at the current index
76
- let targetIndex = index;
77
- for (let i = 0; i < index; i++) {
78
- if (!this.inputValues[i] || this.inputValues[i] === '') {
79
- targetIndex = i;
80
- break;
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
- // Set the value at the target index
84
- this.inputValues[targetIndex] = value;
85
- // If the value was entered in a later box, clear the current box
86
- if (targetIndex !== index) {
87
- this.inputRefs[index].value = '';
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
- if (value.length > 0) {
90
- this.focusNext(targetIndex);
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,67 +276,27 @@ export class InputOTP {
218
276
  (_c = inputRefs[length - 1]) === null || _c === void 0 ? void 0 : _c.focus();
219
277
  }
220
278
  };
221
- /**
222
- * Handles the focus behavior for the input OTP component.
223
- *
224
- * Focus behavior:
225
- * 1. Keyboard navigation: Allow normal focus movement
226
- * 2. Mouse click:
227
- * - If clicked box has value: Focus that box
228
- * - If clicked box is empty: Focus first empty box
229
- *
230
- * Emits the `ionFocus` event when the input group gains focus.
231
- */
232
- this.onFocus = (index) => (event) => {
233
- var _a;
234
- const { inputRefs } = this;
235
- // Only emit ionFocus and set the focusedValue when the
236
- // component first gains focus
237
- if (!this.hasFocus) {
238
- this.ionFocus.emit(event);
239
- this.focusedValue = this.value;
240
- }
241
- this.hasFocus = true;
242
- let finalIndex = index;
243
- if (!this.isKeyboardNavigation) {
244
- // If the clicked box has a value, focus it
245
- // Otherwise focus the first empty box
246
- const targetIndex = this.inputValues[index] ? index : this.getFirstEmptyIndex();
247
- finalIndex = targetIndex === -1 ? this.length - 1 : targetIndex;
248
- // Focus the target box
249
- (_a = this.inputRefs[finalIndex]) === null || _a === void 0 ? void 0 : _a.focus();
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
+ * Sets focus to an input box.
282
+ * @param index - The index of the input box to focus (0-based).
283
+ * If provided and the input box has a value, the input box at that index will be focused.
284
+ * Otherwise, the first empty input box or the last input if all are filled will be focused.
285
+ */
286
+ async setFocus(index) {
287
+ var _a, _b;
288
+ if (typeof index === 'number') {
289
+ const validIndex = Math.max(0, Math.min(index, this.length - 1));
290
+ (_a = this.inputRefs[validIndex]) === null || _a === void 0 ? void 0 : _a.focus();
291
+ }
292
+ else {
293
+ const tabbableIndex = this.getTabbableIndex();
294
+ (_b = this.inputRefs[tabbableIndex]) === null || _b === void 0 ? void 0 : _b.focus();
295
+ }
279
296
  }
280
297
  valueChanged() {
281
298
  this.initializeValues();
299
+ this.updateTabIndexes();
282
300
  }
283
301
  /**
284
302
  * Processes the separators prop into an array of numbers.
@@ -336,59 +354,6 @@ export class InputOTP {
336
354
  componentDidLoad() {
337
355
  this.updateTabIndexes();
338
356
  }
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
357
  /**
393
358
  * Get the regex pattern for allowed characters.
394
359
  * If a pattern is provided, use it to create a regex pattern
@@ -425,6 +390,30 @@ export class InputOTP {
425
390
  return 'text';
426
391
  }
427
392
  }
393
+ /**
394
+ * Initializes the input values array based on the current value prop.
395
+ * This splits the value into individual characters and validates them against
396
+ * the allowed pattern. The values are then used as the values in the native
397
+ * input boxes and the value of the input group is updated.
398
+ */
399
+ initializeValues() {
400
+ // Clear all input values
401
+ this.inputValues = Array(this.length).fill('');
402
+ // If the value is null, undefined, or an empty string, return
403
+ if (this.value == null || String(this.value).length === 0) {
404
+ return;
405
+ }
406
+ // Split the value into individual characters and validate
407
+ // them against the allowed pattern
408
+ const chars = String(this.value).split('').slice(0, this.length);
409
+ chars.forEach((char, index) => {
410
+ if (this.validKeyPattern.test(char)) {
411
+ this.inputValues[index] = char;
412
+ }
413
+ });
414
+ // Update the value without emitting events
415
+ this.value = this.inputValues.join('');
416
+ }
428
417
  /**
429
418
  * Updates the value of the input group.
430
419
  * This updates the value of the input group and emits an `ionChange` event.
@@ -438,7 +427,6 @@ export class InputOTP {
438
427
  if (newValue.length === length) {
439
428
  this.ionComplete.emit({ value: newValue });
440
429
  }
441
- this.updateTabIndexes();
442
430
  }
443
431
  /**
444
432
  * Emits an `ionChange` event.
@@ -483,12 +471,27 @@ export class InputOTP {
483
471
  }
484
472
  }
485
473
  /**
486
- * Determines if a separator should be shown for a given index by
487
- * checking if the index is included in the parsed separators array.
474
+ * Searches through the input values and returns the index
475
+ * of the first empty input.
476
+ * Returns -1 if all inputs are filled.
488
477
  */
489
- showSeparator(index) {
478
+ getFirstEmptyIndex() {
479
+ var _a;
480
+ const { inputValues, length } = this;
481
+ // Create an array of the same length as the input OTP
482
+ // and fill it with the input values
483
+ const values = Array.from({ length }, (_, i) => inputValues[i] || '');
484
+ return (_a = values.findIndex((value) => !value || value === '')) !== null && _a !== void 0 ? _a : -1;
485
+ }
486
+ /**
487
+ * Returns the index of the input that should be tabbed to.
488
+ * If all inputs are filled, returns the last input's index.
489
+ * Otherwise, returns the index of the first empty input.
490
+ */
491
+ getTabbableIndex() {
490
492
  const { length } = this;
491
- return this.parsedSeparators.includes(index + 1) && index < length - 1;
493
+ const firstEmptyIndex = this.getFirstEmptyIndex();
494
+ return firstEmptyIndex === -1 ? length - 1 : firstEmptyIndex;
492
495
  }
493
496
  /**
494
497
  * Updates the tabIndexes for the input boxes.
@@ -516,27 +519,12 @@ export class InputOTP {
516
519
  });
517
520
  }
518
521
  /**
519
- * Searches through the input values and returns the index
520
- * of the first empty input.
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.
522
+ * Determines if a separator should be shown for a given index by
523
+ * checking if the index is included in the parsed separators array.
535
524
  */
536
- getTabbableIndex() {
525
+ showSeparator(index) {
537
526
  const { length } = this;
538
- const firstEmptyIndex = this.getFirstEmptyIndex();
539
- return firstEmptyIndex === -1 ? length - 1 : firstEmptyIndex;
527
+ return this.parsedSeparators.includes(index + 1) && index < length - 1;
540
528
  }
541
529
  render() {
542
530
  var _a, _b;
@@ -546,7 +534,7 @@ export class InputOTP {
546
534
  const tabbableIndex = this.getTabbableIndex();
547
535
  const pattern = this.getPattern();
548
536
  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()) !== '';
549
- return (h(Host, { key: '973743fa99d77dbdaaf9b630b64180a189b5d778', class: createColorClasses(color, {
537
+ return (h(Host, { key: 'e87987e639fcff31612db32baa45ef928f1214fe', class: createColorClasses(color, {
550
538
  [mode]: true,
551
539
  'has-focus': hasFocus,
552
540
  [`input-otp-size-${size}`]: true,
@@ -554,10 +542,10 @@ export class InputOTP {
554
542
  [`input-otp-fill-${fill}`]: true,
555
543
  'input-otp-disabled': disabled,
556
544
  'input-otp-readonly': readonly,
557
- }) }, 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: {
545
+ }) }, 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: {
558
546
  'input-otp-description': true,
559
547
  'input-otp-description-hidden': !hasDescription,
560
- } }, h("slot", { key: '13c3f795956749ccdf396bfb0ff882a9c9e9ce81' }))));
548
+ } }, h("slot", { key: '9fdeca4d1eebd60334a48b103229d43849bbb0ac' }))));
561
549
  }
562
550
  static get is() { return "ion-input-otp"; }
563
551
  static get encapsulation() { return "scoped"; }
@@ -738,26 +726,6 @@ export class InputOTP {
738
726
  "reflect": true,
739
727
  "defaultValue": "false"
740
728
  },
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
729
  "separators": {
762
730
  "type": "string",
763
731
  "attribute": "separators",
@@ -797,6 +765,26 @@ export class InputOTP {
797
765
  "reflect": false,
798
766
  "defaultValue": "'round'"
799
767
  },
768
+ "size": {
769
+ "type": "string",
770
+ "attribute": "size",
771
+ "mutable": false,
772
+ "complexType": {
773
+ "original": "'small' | 'medium' | 'large'",
774
+ "resolved": "\"large\" | \"medium\" | \"small\"",
775
+ "references": {}
776
+ },
777
+ "required": false,
778
+ "optional": false,
779
+ "docs": {
780
+ "tags": [],
781
+ "text": "The size of the input boxes."
782
+ },
783
+ "getter": false,
784
+ "setter": false,
785
+ "reflect": false,
786
+ "defaultValue": "'medium'"
787
+ },
800
788
  "type": {
801
789
  "type": "string",
802
790
  "attribute": "type",
@@ -953,23 +941,6 @@ export class InputOTP {
953
941
  }
954
942
  static get methods() {
955
943
  return {
956
- "reset": {
957
- "complexType": {
958
- "signature": "() => Promise<void>",
959
- "parameters": [],
960
- "references": {
961
- "Promise": {
962
- "location": "global",
963
- "id": "global::Promise"
964
- }
965
- },
966
- "return": "Promise<void>"
967
- },
968
- "docs": {
969
- "text": "Resets the value and focus state.",
970
- "tags": []
971
- }
972
- },
973
944
  "setFocus": {
974
945
  "complexType": {
975
946
  "signature": "(index?: number) => Promise<void>",
package/dist/docs.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "timestamp": "2025-05-27T21:07:25",
2
+ "timestamp": "2025-05-29T19:13:09",
3
3
  "compiler": {
4
4
  "name": "@stencil/core",
5
5
  "version": "4.29.3",
@@ -13511,28 +13511,6 @@
13511
13511
  }
13512
13512
  ],
13513
13513
  "methods": [
13514
- {
13515
- "name": "reset",
13516
- "returns": {
13517
- "type": "Promise<void>",
13518
- "docs": ""
13519
- },
13520
- "complexType": {
13521
- "signature": "() => Promise<void>",
13522
- "parameters": [],
13523
- "references": {
13524
- "Promise": {
13525
- "location": "global",
13526
- "id": "global::Promise"
13527
- }
13528
- },
13529
- "return": "Promise<void>"
13530
- },
13531
- "signature": "reset() => Promise<void>",
13532
- "parameters": [],
13533
- "docs": "Resets the value and focus state.",
13534
- "docsTags": []
13535
- },
13536
13514
  {
13537
13515
  "name": "setFocus",
13538
13516
  "returns": {