@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.
@@ -65,10 +65,6 @@ export declare class InputOTP implements ComponentInterface {
65
65
  * If `true`, the user cannot modify the value.
66
66
  */
67
67
  readonly: boolean;
68
- /**
69
- * The size of the input boxes.
70
- */
71
- size: 'small' | 'medium' | 'large';
72
68
  /**
73
69
  * Where separators should be shown between input boxes.
74
70
  * Can be a comma-separated string or an array of numbers.
@@ -86,6 +82,10 @@ export declare class InputOTP implements ComponentInterface {
86
82
  * If "soft" they will have a soft border radius.
87
83
  */
88
84
  shape: 'round' | 'rectangular' | 'soft';
85
+ /**
86
+ * The size of the input boxes.
87
+ */
88
+ size: 'small' | 'medium' | 'large';
89
89
  /**
90
90
  * The type of input allowed in the input boxes.
91
91
  */
@@ -128,6 +128,17 @@ export declare class InputOTP implements ComponentInterface {
128
128
  * Emitted when the input group has focus.
129
129
  */
130
130
  ionFocus: EventEmitter<FocusEvent>;
131
+ /**
132
+ * Resets the value and focus state.
133
+ */
134
+ reset(): Promise<void>;
135
+ /**
136
+ * Sets focus to an input box.
137
+ * @param index - The index of the input box to focus (0-based).
138
+ * If provided and the input box has a value, the input box at that index will be focused.
139
+ * Otherwise, the first empty input box or the last input if all are filled will be focused.
140
+ */
141
+ setFocus(index?: number): Promise<void>;
131
142
  valueChanged(): void;
132
143
  /**
133
144
  * Processes the separators prop into an array of numbers.
@@ -142,24 +153,6 @@ export declare class InputOTP implements ComponentInterface {
142
153
  private processSeparators;
143
154
  componentWillLoad(): void;
144
155
  componentDidLoad(): void;
145
- /**
146
- * Initializes the input values array based on the current value prop.
147
- * This splits the value into individual characters and validates them against
148
- * the allowed pattern. The values are then used as the values in the native
149
- * input boxes and the value of the input group is updated.
150
- */
151
- private initializeValues;
152
- /**
153
- * Resets the value and focus state.
154
- */
155
- reset(): Promise<void>;
156
- /**
157
- * Sets focus to an input box.
158
- * @param index - The index of the input box to focus (0-based).
159
- * If provided and the input box has a value, the input box at that index will be focused.
160
- * Otherwise, the first empty input box or the last input if all are filled will be focused.
161
- */
162
- setFocus(index?: number): Promise<void>;
163
156
  /**
164
157
  * Get the regex pattern for allowed characters.
165
158
  * If a pattern is provided, use it to create a regex pattern
@@ -177,6 +170,13 @@ export declare class InputOTP implements ComponentInterface {
177
170
  * Otherwise, use the default inputmode based on type
178
171
  */
179
172
  private getInputmode;
173
+ /**
174
+ * Initializes the input values array based on the current value prop.
175
+ * This splits the value into individual characters and validates them against
176
+ * the allowed pattern. The values are then used as the values in the native
177
+ * input boxes and the value of the input group is updated.
178
+ */
179
+ private initializeValues;
180
180
  /**
181
181
  * Updates the value of the input group.
182
182
  * This updates the value of the input group and emits an `ionChange` event.
@@ -195,44 +195,6 @@ export declare class InputOTP implements ComponentInterface {
195
195
  * backspaces, or pastes.
196
196
  */
197
197
  private emitIonInput;
198
- private onInput;
199
- /**
200
- * Handles keyboard navigation and input for the OTP component.
201
- *
202
- * Navigation:
203
- * - Backspace: Clears current input and moves to previous box if empty
204
- * - Arrow Left/Right: Moves focus between input boxes
205
- * - Tab: Allows normal tab navigation between components
206
- *
207
- * Input Behavior:
208
- * - Validates input against the allowed pattern
209
- * - When entering a key in a filled box:
210
- * - Shifts existing values right if there is room
211
- * - Updates the value of the input group
212
- * - Prevents default behavior to avoid automatic focus shift
213
- */
214
- private onKeyDown;
215
- /**
216
- * Handles pasting text into the input OTP component.
217
- * This function prevents the default paste behavior and
218
- * validates the pasted text against the allowed pattern.
219
- * It then updates the value of the input group and focuses
220
- * the next empty input after pasting.
221
- */
222
- private onPaste;
223
- /**
224
- * Focuses the next input box.
225
- */
226
- private focusNext;
227
- /**
228
- * Focuses the previous input box.
229
- */
230
- private focusPrevious;
231
- /**
232
- * Determines if a separator should be shown for a given index by
233
- * checking if the index is included in the parsed separators array.
234
- */
235
- private showSeparator;
236
198
  /**
237
199
  * Handles the focus behavior for the input OTP component.
238
200
  *
@@ -251,11 +213,13 @@ export declare class InputOTP implements ComponentInterface {
251
213
  */
252
214
  private onBlur;
253
215
  /**
254
- * Updates the tabIndexes for the input boxes.
255
- * This is used to ensure that the correct input is
256
- * focused when the user navigates using the tab key.
216
+ * Focuses the next input box.
257
217
  */
258
- private updateTabIndexes;
218
+ private focusNext;
219
+ /**
220
+ * Focuses the previous input box.
221
+ */
222
+ private focusPrevious;
259
223
  /**
260
224
  * Searches through the input values and returns the index
261
225
  * of the first empty input.
@@ -268,5 +232,41 @@ export declare class InputOTP implements ComponentInterface {
268
232
  * Otherwise, returns the index of the first empty input.
269
233
  */
270
234
  private getTabbableIndex;
235
+ /**
236
+ * Updates the tabIndexes for the input boxes.
237
+ * This is used to ensure that the correct input is
238
+ * focused when the user navigates using the tab key.
239
+ */
240
+ private updateTabIndexes;
241
+ /**
242
+ * Handles keyboard navigation and input for the OTP component.
243
+ *
244
+ * Navigation:
245
+ * - Backspace: Clears current input and moves to previous box if empty
246
+ * - Arrow Left/Right: Moves focus between input boxes
247
+ * - Tab: Allows normal tab navigation between components
248
+ *
249
+ * Input Behavior:
250
+ * - Validates input against the allowed pattern
251
+ * - When entering a key in a filled box:
252
+ * - Shifts existing values right if there is room
253
+ * - Updates the value of the input group
254
+ * - Prevents default behavior to avoid automatic focus shift
255
+ */
256
+ private onKeyDown;
257
+ private onInput;
258
+ /**
259
+ * Handles pasting text into the input OTP component.
260
+ * This function prevents the default paste behavior and
261
+ * validates the pasted text against the allowed pattern.
262
+ * It then updates the value of the input group and focuses
263
+ * the next empty input after pasting.
264
+ */
265
+ private onPaste;
266
+ /**
267
+ * Determines if a separator should be shown for a given index by
268
+ * checking if the index is included in the parsed separators array.
269
+ */
270
+ private showSeparator;
271
271
  render(): any;
272
272
  }
package/hydrate/index.js CHANGED
@@ -16985,10 +16985,6 @@ class InputOTP {
16985
16985
  * If `true`, the user cannot modify the value.
16986
16986
  */
16987
16987
  this.readonly = false;
16988
- /**
16989
- * The size of the input boxes.
16990
- */
16991
- this.size = 'medium';
16992
16988
  /**
16993
16989
  * The shape of the input boxes.
16994
16990
  * If "round" they will have an increased border radius.
@@ -16996,6 +16992,10 @@ class InputOTP {
16996
16992
  * If "soft" they will have a soft border radius.
16997
16993
  */
16998
16994
  this.shape = 'round';
16995
+ /**
16996
+ * The size of the input boxes.
16997
+ */
16998
+ this.size = 'medium';
16999
16999
  /**
17000
17000
  * The type of input allowed in the input boxes.
17001
17001
  */
@@ -17004,34 +17004,63 @@ class InputOTP {
17004
17004
  * The value of the input group.
17005
17005
  */
17006
17006
  this.value = '';
17007
- this.onInput = (index) => (event) => {
17008
- const { validKeyPattern } = this;
17009
- const value = event.target.value;
17010
- // Only allow input if it's a single character and matches the pattern
17011
- if (value.length > 1 || (value.length > 0 && !validKeyPattern.test(value))) {
17012
- // Reset the input value if not valid
17013
- this.inputRefs[index].value = '';
17014
- this.inputValues[index] = '';
17015
- return;
17016
- }
17017
- // Find the first empty box before or at the current index
17018
- let targetIndex = index;
17019
- for (let i = 0; i < index; i++) {
17020
- if (!this.inputValues[i] || this.inputValues[i] === '') {
17021
- targetIndex = i;
17022
- break;
17023
- }
17007
+ /**
17008
+ * Handles the focus behavior for the input OTP component.
17009
+ *
17010
+ * Focus behavior:
17011
+ * 1. Keyboard navigation: Allow normal focus movement
17012
+ * 2. Mouse click:
17013
+ * - If clicked box has value: Focus that box
17014
+ * - If clicked box is empty: Focus first empty box
17015
+ *
17016
+ * Emits the `ionFocus` event when the input group gains focus.
17017
+ */
17018
+ this.onFocus = (index) => (event) => {
17019
+ var _a;
17020
+ const { inputRefs } = this;
17021
+ // Only emit ionFocus and set the focusedValue when the
17022
+ // component first gains focus
17023
+ if (!this.hasFocus) {
17024
+ this.ionFocus.emit(event);
17025
+ this.focusedValue = this.value;
17024
17026
  }
17025
- // Set the value at the target index
17026
- this.inputValues[targetIndex] = value;
17027
- // If the value was entered in a later box, clear the current box
17028
- if (targetIndex !== index) {
17029
- this.inputRefs[index].value = '';
17027
+ this.hasFocus = true;
17028
+ let finalIndex = index;
17029
+ if (!this.isKeyboardNavigation) {
17030
+ // If the clicked box has a value, focus it
17031
+ // Otherwise focus the first empty box
17032
+ const targetIndex = this.inputValues[index] ? index : this.getFirstEmptyIndex();
17033
+ finalIndex = targetIndex === -1 ? this.length - 1 : targetIndex;
17034
+ // Focus the target box
17035
+ (_a = this.inputRefs[finalIndex]) === null || _a === void 0 ? void 0 : _a.focus();
17030
17036
  }
17031
- if (value.length > 0) {
17032
- this.focusNext(targetIndex);
17037
+ // Update tabIndexes to match the focused box
17038
+ inputRefs.forEach((input, i) => {
17039
+ input.tabIndex = i === finalIndex ? 0 : -1;
17040
+ });
17041
+ // Reset the keyboard navigation flag
17042
+ this.isKeyboardNavigation = false;
17043
+ };
17044
+ /**
17045
+ * Handles the blur behavior for the input OTP component.
17046
+ * Emits the `ionBlur` event when the input group loses focus.
17047
+ */
17048
+ this.onBlur = (event) => {
17049
+ const { inputRefs } = this;
17050
+ const relatedTarget = event.relatedTarget;
17051
+ // Do not emit blur if we're moving to another input box in the same component
17052
+ const isInternalFocus = relatedTarget != null && inputRefs.includes(relatedTarget);
17053
+ if (!isInternalFocus) {
17054
+ this.hasFocus = false;
17055
+ // Reset tabIndexes when focus leaves the component
17056
+ this.updateTabIndexes();
17057
+ // Always emit ionBlur when focus leaves the component
17058
+ this.ionBlur.emit(event);
17059
+ // Only emit ionChange if the value has actually changed
17060
+ if (this.focusedValue !== this.value) {
17061
+ this.emitIonChange(event);
17062
+ }
17033
17063
  }
17034
- this.updateValue(event);
17035
17064
  };
17036
17065
  /**
17037
17066
  * Handles keyboard navigation and input for the OTP component.
@@ -17117,6 +17146,35 @@ class InputOTP {
17117
17146
  event.preventDefault();
17118
17147
  }
17119
17148
  };
17149
+ this.onInput = (index) => (event) => {
17150
+ const { validKeyPattern } = this;
17151
+ const value = event.target.value;
17152
+ // Only allow input if it's a single character and matches the pattern
17153
+ if (value.length > 1 || (value.length > 0 && !validKeyPattern.test(value))) {
17154
+ // Reset the input value if not valid
17155
+ this.inputRefs[index].value = '';
17156
+ this.inputValues[index] = '';
17157
+ return;
17158
+ }
17159
+ // Find the first empty box before or at the current index
17160
+ let targetIndex = index;
17161
+ for (let i = 0; i < index; i++) {
17162
+ if (!this.inputValues[i] || this.inputValues[i] === '') {
17163
+ targetIndex = i;
17164
+ break;
17165
+ }
17166
+ }
17167
+ // Set the value at the target index
17168
+ this.inputValues[targetIndex] = value;
17169
+ // If the value was entered in a later box, clear the current box
17170
+ if (targetIndex !== index) {
17171
+ this.inputRefs[index].value = '';
17172
+ }
17173
+ if (value.length > 0) {
17174
+ this.focusNext(targetIndex);
17175
+ }
17176
+ this.updateValue(event);
17177
+ };
17120
17178
  /**
17121
17179
  * Handles pasting text into the input OTP component.
17122
17180
  * This function prevents the default paste behavior and
@@ -17160,64 +17218,35 @@ class InputOTP {
17160
17218
  (_c = inputRefs[length - 1]) === null || _c === void 0 ? void 0 : _c.focus();
17161
17219
  }
17162
17220
  };
17163
- /**
17164
- * Handles the focus behavior for the input OTP component.
17165
- *
17166
- * Focus behavior:
17167
- * 1. Keyboard navigation: Allow normal focus movement
17168
- * 2. Mouse click:
17169
- * - If clicked box has value: Focus that box
17170
- * - If clicked box is empty: Focus first empty box
17171
- *
17172
- * Emits the `ionFocus` event when the input group gains focus.
17173
- */
17174
- this.onFocus = (index) => (event) => {
17175
- var _a;
17176
- const { inputRefs } = this;
17177
- // Only emit ionFocus and set the focusedValue when the
17178
- // component first gains focus
17179
- if (!this.hasFocus) {
17180
- this.ionFocus.emit(event);
17181
- this.focusedValue = this.value;
17182
- }
17183
- this.hasFocus = true;
17184
- let finalIndex = index;
17185
- if (!this.isKeyboardNavigation) {
17186
- // If the clicked box has a value, focus it
17187
- // Otherwise focus the first empty box
17188
- const targetIndex = this.inputValues[index] ? index : this.getFirstEmptyIndex();
17189
- finalIndex = targetIndex === -1 ? this.length - 1 : targetIndex;
17190
- // Focus the target box
17191
- (_a = this.inputRefs[finalIndex]) === null || _a === void 0 ? void 0 : _a.focus();
17192
- }
17193
- // Update tabIndexes to match the focused box
17194
- inputRefs.forEach((input, i) => {
17195
- input.tabIndex = i === finalIndex ? 0 : -1;
17196
- });
17197
- // Reset the keyboard navigation flag
17198
- this.isKeyboardNavigation = false;
17199
- };
17200
- /**
17201
- * Handles the blur behavior for the input OTP component.
17202
- * Emits the `ionBlur` event when the input group loses focus.
17203
- */
17204
- this.onBlur = (event) => {
17205
- const { inputRefs } = this;
17206
- const relatedTarget = event.relatedTarget;
17207
- // Do not emit blur if we're moving to another input box in the same component
17208
- const isInternalFocus = relatedTarget != null && inputRefs.includes(relatedTarget);
17209
- if (!isInternalFocus) {
17210
- this.hasFocus = false;
17211
- // Reset tabIndexes when focus leaves the component
17212
- this.updateTabIndexes();
17213
- // Always emit ionBlur when focus leaves the component
17214
- this.ionBlur.emit(event);
17215
- // Only emit ionChange if the value has actually changed
17216
- if (this.focusedValue !== this.value) {
17217
- this.emitIonChange(event);
17218
- }
17219
- }
17220
- };
17221
+ }
17222
+ /**
17223
+ * Resets the value and focus state.
17224
+ */
17225
+ async reset() {
17226
+ this.value = '';
17227
+ this.focusedValue = null;
17228
+ this.hasFocus = false;
17229
+ this.inputRefs.forEach((input) => {
17230
+ input.blur();
17231
+ });
17232
+ this.updateTabIndexes();
17233
+ }
17234
+ /**
17235
+ * Sets focus to an input box.
17236
+ * @param index - The index of the input box to focus (0-based).
17237
+ * If provided and the input box has a value, the input box at that index will be focused.
17238
+ * Otherwise, the first empty input box or the last input if all are filled will be focused.
17239
+ */
17240
+ async setFocus(index) {
17241
+ var _a, _b;
17242
+ if (typeof index === 'number') {
17243
+ const validIndex = Math.max(0, Math.min(index, this.length - 1));
17244
+ (_a = this.inputRefs[validIndex]) === null || _a === void 0 ? void 0 : _a.focus();
17245
+ }
17246
+ else {
17247
+ const tabbableIndex = this.getTabbableIndex();
17248
+ (_b = this.inputRefs[tabbableIndex]) === null || _b === void 0 ? void 0 : _b.focus();
17249
+ }
17221
17250
  }
17222
17251
  valueChanged() {
17223
17252
  this.initializeValues();
@@ -17278,59 +17307,6 @@ class InputOTP {
17278
17307
  componentDidLoad() {
17279
17308
  this.updateTabIndexes();
17280
17309
  }
17281
- /**
17282
- * Initializes the input values array based on the current value prop.
17283
- * This splits the value into individual characters and validates them against
17284
- * the allowed pattern. The values are then used as the values in the native
17285
- * input boxes and the value of the input group is updated.
17286
- */
17287
- initializeValues() {
17288
- // Clear all input values
17289
- this.inputValues = Array(this.length).fill('');
17290
- // If the value is null, undefined, or an empty string, return
17291
- if (this.value == null || String(this.value).length === 0) {
17292
- return;
17293
- }
17294
- // Split the value into individual characters and validate
17295
- // them against the allowed pattern
17296
- const chars = String(this.value).split('').slice(0, this.length);
17297
- chars.forEach((char, index) => {
17298
- if (this.validKeyPattern.test(char)) {
17299
- this.inputValues[index] = char;
17300
- }
17301
- });
17302
- // Update the value without emitting events
17303
- this.value = this.inputValues.join('');
17304
- }
17305
- /**
17306
- * Resets the value and focus state.
17307
- */
17308
- async reset() {
17309
- this.value = '';
17310
- this.focusedValue = null;
17311
- this.hasFocus = false;
17312
- this.inputRefs.forEach((input) => {
17313
- input.blur();
17314
- });
17315
- this.updateTabIndexes();
17316
- }
17317
- /**
17318
- * Sets focus to an input box.
17319
- * @param index - The index of the input box to focus (0-based).
17320
- * If provided and the input box has a value, the input box at that index will be focused.
17321
- * Otherwise, the first empty input box or the last input if all are filled will be focused.
17322
- */
17323
- async setFocus(index) {
17324
- var _a, _b;
17325
- if (typeof index === 'number') {
17326
- const validIndex = Math.max(0, Math.min(index, this.length - 1));
17327
- (_a = this.inputRefs[validIndex]) === null || _a === void 0 ? void 0 : _a.focus();
17328
- }
17329
- else {
17330
- const tabbableIndex = this.getTabbableIndex();
17331
- (_b = this.inputRefs[tabbableIndex]) === null || _b === void 0 ? void 0 : _b.focus();
17332
- }
17333
- }
17334
17310
  /**
17335
17311
  * Get the regex pattern for allowed characters.
17336
17312
  * If a pattern is provided, use it to create a regex pattern
@@ -17367,6 +17343,30 @@ class InputOTP {
17367
17343
  return 'text';
17368
17344
  }
17369
17345
  }
17346
+ /**
17347
+ * Initializes the input values array based on the current value prop.
17348
+ * This splits the value into individual characters and validates them against
17349
+ * the allowed pattern. The values are then used as the values in the native
17350
+ * input boxes and the value of the input group is updated.
17351
+ */
17352
+ initializeValues() {
17353
+ // Clear all input values
17354
+ this.inputValues = Array(this.length).fill('');
17355
+ // If the value is null, undefined, or an empty string, return
17356
+ if (this.value == null || String(this.value).length === 0) {
17357
+ return;
17358
+ }
17359
+ // Split the value into individual characters and validate
17360
+ // them against the allowed pattern
17361
+ const chars = String(this.value).split('').slice(0, this.length);
17362
+ chars.forEach((char, index) => {
17363
+ if (this.validKeyPattern.test(char)) {
17364
+ this.inputValues[index] = char;
17365
+ }
17366
+ });
17367
+ // Update the value without emitting events
17368
+ this.value = this.inputValues.join('');
17369
+ }
17370
17370
  /**
17371
17371
  * Updates the value of the input group.
17372
17372
  * This updates the value of the input group and emits an `ionChange` event.
@@ -17425,12 +17425,27 @@ class InputOTP {
17425
17425
  }
17426
17426
  }
17427
17427
  /**
17428
- * Determines if a separator should be shown for a given index by
17429
- * checking if the index is included in the parsed separators array.
17428
+ * Searches through the input values and returns the index
17429
+ * of the first empty input.
17430
+ * Returns -1 if all inputs are filled.
17430
17431
  */
17431
- showSeparator(index) {
17432
+ getFirstEmptyIndex() {
17433
+ var _a;
17434
+ const { inputValues, length } = this;
17435
+ // Create an array of the same length as the input OTP
17436
+ // and fill it with the input values
17437
+ const values = Array.from({ length }, (_, i) => inputValues[i] || '');
17438
+ return (_a = values.findIndex((value) => !value || value === '')) !== null && _a !== void 0 ? _a : -1;
17439
+ }
17440
+ /**
17441
+ * Returns the index of the input that should be tabbed to.
17442
+ * If all inputs are filled, returns the last input's index.
17443
+ * Otherwise, returns the index of the first empty input.
17444
+ */
17445
+ getTabbableIndex() {
17432
17446
  const { length } = this;
17433
- return this.parsedSeparators.includes(index + 1) && index < length - 1;
17447
+ const firstEmptyIndex = this.getFirstEmptyIndex();
17448
+ return firstEmptyIndex === -1 ? length - 1 : firstEmptyIndex;
17434
17449
  }
17435
17450
  /**
17436
17451
  * Updates the tabIndexes for the input boxes.
@@ -17458,27 +17473,12 @@ class InputOTP {
17458
17473
  });
17459
17474
  }
17460
17475
  /**
17461
- * Searches through the input values and returns the index
17462
- * of the first empty input.
17463
- * Returns -1 if all inputs are filled.
17464
- */
17465
- getFirstEmptyIndex() {
17466
- var _a;
17467
- const { inputValues, length } = this;
17468
- // Create an array of the same length as the input OTP
17469
- // and fill it with the input values
17470
- const values = Array.from({ length }, (_, i) => inputValues[i] || '');
17471
- return (_a = values.findIndex((value) => !value || value === '')) !== null && _a !== void 0 ? _a : -1;
17472
- }
17473
- /**
17474
- * Returns the index of the input that should be tabbed to.
17475
- * If all inputs are filled, returns the last input's index.
17476
- * Otherwise, returns the index of the first empty input.
17476
+ * Determines if a separator should be shown for a given index by
17477
+ * checking if the index is included in the parsed separators array.
17477
17478
  */
17478
- getTabbableIndex() {
17479
+ showSeparator(index) {
17479
17480
  const { length } = this;
17480
- const firstEmptyIndex = this.getFirstEmptyIndex();
17481
- return firstEmptyIndex === -1 ? length - 1 : firstEmptyIndex;
17481
+ return this.parsedSeparators.includes(index + 1) && index < length - 1;
17482
17482
  }
17483
17483
  render() {
17484
17484
  var _a, _b;
@@ -17523,9 +17523,9 @@ class InputOTP {
17523
17523
  "length": [2],
17524
17524
  "pattern": [1],
17525
17525
  "readonly": [516],
17526
- "size": [1],
17527
17526
  "separators": [1],
17528
17527
  "shape": [1],
17528
+ "size": [1],
17529
17529
  "type": [1],
17530
17530
  "value": [1032],
17531
17531
  "inputValues": [32],