@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.
- package/components/ion-input-otp.js +156 -169
- package/dist/cjs/ion-input-otp.cjs.entry.js +155 -167
- 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 +175 -204
- package/dist/docs.json +1 -23
- package/dist/esm/ion-input-otp.entry.js +155 -167
- 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-c66cc708.entry.js +4 -0
- package/dist/types/components/input-otp/input-otp.d.ts +60 -64
- package/dist/types/components.d.ts +0 -4
- package/hydrate/index.js +156 -169
- package/hydrate/index.mjs +156 -169
- package/package.json +1 -1
- package/dist/ionic/p-702c7264.entry.js +0 -4
|
@@ -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,13 @@ export declare class InputOTP implements ComponentInterface {
|
|
|
128
128
|
* Emitted when the input group has focus.
|
|
129
129
|
*/
|
|
130
130
|
ionFocus: EventEmitter<FocusEvent>;
|
|
131
|
+
/**
|
|
132
|
+
* Sets focus to an input box.
|
|
133
|
+
* @param index - The index of the input box to focus (0-based).
|
|
134
|
+
* If provided and the input box has a value, the input box at that index will be focused.
|
|
135
|
+
* Otherwise, the first empty input box or the last input if all are filled will be focused.
|
|
136
|
+
*/
|
|
137
|
+
setFocus(index?: number): Promise<void>;
|
|
131
138
|
valueChanged(): void;
|
|
132
139
|
/**
|
|
133
140
|
* Processes the separators prop into an array of numbers.
|
|
@@ -142,24 +149,6 @@ export declare class InputOTP implements ComponentInterface {
|
|
|
142
149
|
private processSeparators;
|
|
143
150
|
componentWillLoad(): void;
|
|
144
151
|
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
152
|
/**
|
|
164
153
|
* Get the regex pattern for allowed characters.
|
|
165
154
|
* If a pattern is provided, use it to create a regex pattern
|
|
@@ -177,6 +166,13 @@ export declare class InputOTP implements ComponentInterface {
|
|
|
177
166
|
* Otherwise, use the default inputmode based on type
|
|
178
167
|
*/
|
|
179
168
|
private getInputmode;
|
|
169
|
+
/**
|
|
170
|
+
* Initializes the input values array based on the current value prop.
|
|
171
|
+
* This splits the value into individual characters and validates them against
|
|
172
|
+
* the allowed pattern. The values are then used as the values in the native
|
|
173
|
+
* input boxes and the value of the input group is updated.
|
|
174
|
+
*/
|
|
175
|
+
private initializeValues;
|
|
180
176
|
/**
|
|
181
177
|
* Updates the value of the input group.
|
|
182
178
|
* This updates the value of the input group and emits an `ionChange` event.
|
|
@@ -195,44 +191,6 @@ export declare class InputOTP implements ComponentInterface {
|
|
|
195
191
|
* backspaces, or pastes.
|
|
196
192
|
*/
|
|
197
193
|
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
194
|
/**
|
|
237
195
|
* Handles the focus behavior for the input OTP component.
|
|
238
196
|
*
|
|
@@ -251,11 +209,13 @@ export declare class InputOTP implements ComponentInterface {
|
|
|
251
209
|
*/
|
|
252
210
|
private onBlur;
|
|
253
211
|
/**
|
|
254
|
-
*
|
|
255
|
-
* This is used to ensure that the correct input is
|
|
256
|
-
* focused when the user navigates using the tab key.
|
|
212
|
+
* Focuses the next input box.
|
|
257
213
|
*/
|
|
258
|
-
private
|
|
214
|
+
private focusNext;
|
|
215
|
+
/**
|
|
216
|
+
* Focuses the previous input box.
|
|
217
|
+
*/
|
|
218
|
+
private focusPrevious;
|
|
259
219
|
/**
|
|
260
220
|
* Searches through the input values and returns the index
|
|
261
221
|
* of the first empty input.
|
|
@@ -268,5 +228,41 @@ export declare class InputOTP implements ComponentInterface {
|
|
|
268
228
|
* Otherwise, returns the index of the first empty input.
|
|
269
229
|
*/
|
|
270
230
|
private getTabbableIndex;
|
|
231
|
+
/**
|
|
232
|
+
* Updates the tabIndexes for the input boxes.
|
|
233
|
+
* This is used to ensure that the correct input is
|
|
234
|
+
* focused when the user navigates using the tab key.
|
|
235
|
+
*/
|
|
236
|
+
private updateTabIndexes;
|
|
237
|
+
/**
|
|
238
|
+
* Handles keyboard navigation and input for the OTP component.
|
|
239
|
+
*
|
|
240
|
+
* Navigation:
|
|
241
|
+
* - Backspace: Clears current input and moves to previous box if empty
|
|
242
|
+
* - Arrow Left/Right: Moves focus between input boxes
|
|
243
|
+
* - Tab: Allows normal tab navigation between components
|
|
244
|
+
*
|
|
245
|
+
* Input Behavior:
|
|
246
|
+
* - Validates input against the allowed pattern
|
|
247
|
+
* - When entering a key in a filled box:
|
|
248
|
+
* - Shifts existing values right if there is room
|
|
249
|
+
* - Updates the value of the input group
|
|
250
|
+
* - Prevents default behavior to avoid automatic focus shift
|
|
251
|
+
*/
|
|
252
|
+
private onKeyDown;
|
|
253
|
+
private onInput;
|
|
254
|
+
/**
|
|
255
|
+
* Handles pasting text into the input OTP component.
|
|
256
|
+
* This function prevents the default paste behavior and
|
|
257
|
+
* validates the pasted text against the allowed pattern.
|
|
258
|
+
* It then updates the value of the input group and focuses
|
|
259
|
+
* the next empty input after pasting.
|
|
260
|
+
*/
|
|
261
|
+
private onPaste;
|
|
262
|
+
/**
|
|
263
|
+
* Determines if a separator should be shown for a given index by
|
|
264
|
+
* checking if the index is included in the parsed separators array.
|
|
265
|
+
*/
|
|
266
|
+
private showSeparator;
|
|
271
267
|
render(): any;
|
|
272
268
|
}
|
|
@@ -1354,10 +1354,6 @@ export namespace Components {
|
|
|
1354
1354
|
* If `true`, the user cannot modify the value.
|
|
1355
1355
|
*/
|
|
1356
1356
|
"readonly": boolean;
|
|
1357
|
-
/**
|
|
1358
|
-
* Resets the value and focus state.
|
|
1359
|
-
*/
|
|
1360
|
-
"reset": () => Promise<void>;
|
|
1361
1357
|
/**
|
|
1362
1358
|
* Where separators should be shown between input boxes. Can be a comma-separated string or an array of numbers. For example: `"3"` will show a separator after the 3rd input box. `[1,4]` will show a separator after the 1st and 4th input boxes. `"all"` will show a separator between every input box.
|
|
1363
1359
|
*/
|
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
|
-
|
|
17008
|
-
|
|
17009
|
-
|
|
17010
|
-
|
|
17011
|
-
|
|
17012
|
-
|
|
17013
|
-
|
|
17014
|
-
|
|
17015
|
-
|
|
17016
|
-
|
|
17017
|
-
|
|
17018
|
-
|
|
17019
|
-
|
|
17020
|
-
|
|
17021
|
-
|
|
17022
|
-
|
|
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
|
-
|
|
17026
|
-
|
|
17027
|
-
|
|
17028
|
-
|
|
17029
|
-
|
|
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
|
-
|
|
17032
|
-
|
|
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,67 +17218,27 @@ class InputOTP {
|
|
|
17160
17218
|
(_c = inputRefs[length - 1]) === null || _c === void 0 ? void 0 : _c.focus();
|
|
17161
17219
|
}
|
|
17162
17220
|
};
|
|
17163
|
-
|
|
17164
|
-
|
|
17165
|
-
|
|
17166
|
-
|
|
17167
|
-
|
|
17168
|
-
|
|
17169
|
-
|
|
17170
|
-
|
|
17171
|
-
|
|
17172
|
-
|
|
17173
|
-
|
|
17174
|
-
|
|
17175
|
-
|
|
17176
|
-
|
|
17177
|
-
|
|
17178
|
-
|
|
17179
|
-
|
|
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
|
+
* Sets focus to an input box.
|
|
17224
|
+
* @param index - The index of the input box to focus (0-based).
|
|
17225
|
+
* If provided and the input box has a value, the input box at that index will be focused.
|
|
17226
|
+
* Otherwise, the first empty input box or the last input if all are filled will be focused.
|
|
17227
|
+
*/
|
|
17228
|
+
async setFocus(index) {
|
|
17229
|
+
var _a, _b;
|
|
17230
|
+
if (typeof index === 'number') {
|
|
17231
|
+
const validIndex = Math.max(0, Math.min(index, this.length - 1));
|
|
17232
|
+
(_a = this.inputRefs[validIndex]) === null || _a === void 0 ? void 0 : _a.focus();
|
|
17233
|
+
}
|
|
17234
|
+
else {
|
|
17235
|
+
const tabbableIndex = this.getTabbableIndex();
|
|
17236
|
+
(_b = this.inputRefs[tabbableIndex]) === null || _b === void 0 ? void 0 : _b.focus();
|
|
17237
|
+
}
|
|
17221
17238
|
}
|
|
17222
17239
|
valueChanged() {
|
|
17223
17240
|
this.initializeValues();
|
|
17241
|
+
this.updateTabIndexes();
|
|
17224
17242
|
}
|
|
17225
17243
|
/**
|
|
17226
17244
|
* Processes the separators prop into an array of numbers.
|
|
@@ -17278,59 +17296,6 @@ class InputOTP {
|
|
|
17278
17296
|
componentDidLoad() {
|
|
17279
17297
|
this.updateTabIndexes();
|
|
17280
17298
|
}
|
|
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
17299
|
/**
|
|
17335
17300
|
* Get the regex pattern for allowed characters.
|
|
17336
17301
|
* If a pattern is provided, use it to create a regex pattern
|
|
@@ -17367,6 +17332,30 @@ class InputOTP {
|
|
|
17367
17332
|
return 'text';
|
|
17368
17333
|
}
|
|
17369
17334
|
}
|
|
17335
|
+
/**
|
|
17336
|
+
* Initializes the input values array based on the current value prop.
|
|
17337
|
+
* This splits the value into individual characters and validates them against
|
|
17338
|
+
* the allowed pattern. The values are then used as the values in the native
|
|
17339
|
+
* input boxes and the value of the input group is updated.
|
|
17340
|
+
*/
|
|
17341
|
+
initializeValues() {
|
|
17342
|
+
// Clear all input values
|
|
17343
|
+
this.inputValues = Array(this.length).fill('');
|
|
17344
|
+
// If the value is null, undefined, or an empty string, return
|
|
17345
|
+
if (this.value == null || String(this.value).length === 0) {
|
|
17346
|
+
return;
|
|
17347
|
+
}
|
|
17348
|
+
// Split the value into individual characters and validate
|
|
17349
|
+
// them against the allowed pattern
|
|
17350
|
+
const chars = String(this.value).split('').slice(0, this.length);
|
|
17351
|
+
chars.forEach((char, index) => {
|
|
17352
|
+
if (this.validKeyPattern.test(char)) {
|
|
17353
|
+
this.inputValues[index] = char;
|
|
17354
|
+
}
|
|
17355
|
+
});
|
|
17356
|
+
// Update the value without emitting events
|
|
17357
|
+
this.value = this.inputValues.join('');
|
|
17358
|
+
}
|
|
17370
17359
|
/**
|
|
17371
17360
|
* Updates the value of the input group.
|
|
17372
17361
|
* This updates the value of the input group and emits an `ionChange` event.
|
|
@@ -17380,7 +17369,6 @@ class InputOTP {
|
|
|
17380
17369
|
if (newValue.length === length) {
|
|
17381
17370
|
this.ionComplete.emit({ value: newValue });
|
|
17382
17371
|
}
|
|
17383
|
-
this.updateTabIndexes();
|
|
17384
17372
|
}
|
|
17385
17373
|
/**
|
|
17386
17374
|
* Emits an `ionChange` event.
|
|
@@ -17425,12 +17413,27 @@ class InputOTP {
|
|
|
17425
17413
|
}
|
|
17426
17414
|
}
|
|
17427
17415
|
/**
|
|
17428
|
-
*
|
|
17429
|
-
*
|
|
17416
|
+
* Searches through the input values and returns the index
|
|
17417
|
+
* of the first empty input.
|
|
17418
|
+
* Returns -1 if all inputs are filled.
|
|
17430
17419
|
*/
|
|
17431
|
-
|
|
17420
|
+
getFirstEmptyIndex() {
|
|
17421
|
+
var _a;
|
|
17422
|
+
const { inputValues, length } = this;
|
|
17423
|
+
// Create an array of the same length as the input OTP
|
|
17424
|
+
// and fill it with the input values
|
|
17425
|
+
const values = Array.from({ length }, (_, i) => inputValues[i] || '');
|
|
17426
|
+
return (_a = values.findIndex((value) => !value || value === '')) !== null && _a !== void 0 ? _a : -1;
|
|
17427
|
+
}
|
|
17428
|
+
/**
|
|
17429
|
+
* Returns the index of the input that should be tabbed to.
|
|
17430
|
+
* If all inputs are filled, returns the last input's index.
|
|
17431
|
+
* Otherwise, returns the index of the first empty input.
|
|
17432
|
+
*/
|
|
17433
|
+
getTabbableIndex() {
|
|
17432
17434
|
const { length } = this;
|
|
17433
|
-
|
|
17435
|
+
const firstEmptyIndex = this.getFirstEmptyIndex();
|
|
17436
|
+
return firstEmptyIndex === -1 ? length - 1 : firstEmptyIndex;
|
|
17434
17437
|
}
|
|
17435
17438
|
/**
|
|
17436
17439
|
* Updates the tabIndexes for the input boxes.
|
|
@@ -17458,27 +17461,12 @@ class InputOTP {
|
|
|
17458
17461
|
});
|
|
17459
17462
|
}
|
|
17460
17463
|
/**
|
|
17461
|
-
*
|
|
17462
|
-
*
|
|
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.
|
|
17464
|
+
* Determines if a separator should be shown for a given index by
|
|
17465
|
+
* checking if the index is included in the parsed separators array.
|
|
17477
17466
|
*/
|
|
17478
|
-
|
|
17467
|
+
showSeparator(index) {
|
|
17479
17468
|
const { length } = this;
|
|
17480
|
-
|
|
17481
|
-
return firstEmptyIndex === -1 ? length - 1 : firstEmptyIndex;
|
|
17469
|
+
return this.parsedSeparators.includes(index + 1) && index < length - 1;
|
|
17482
17470
|
}
|
|
17483
17471
|
render() {
|
|
17484
17472
|
var _a, _b;
|
|
@@ -17488,7 +17476,7 @@ class InputOTP {
|
|
|
17488
17476
|
const tabbableIndex = this.getTabbableIndex();
|
|
17489
17477
|
const pattern = this.getPattern();
|
|
17490
17478
|
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()) !== '';
|
|
17491
|
-
return (hAsync(Host, { key: '
|
|
17479
|
+
return (hAsync(Host, { key: 'e87987e639fcff31612db32baa45ef928f1214fe', class: createColorClasses$1(color, {
|
|
17492
17480
|
[mode]: true,
|
|
17493
17481
|
'has-focus': hasFocus,
|
|
17494
17482
|
[`input-otp-size-${size}`]: true,
|
|
@@ -17496,10 +17484,10 @@ class InputOTP {
|
|
|
17496
17484
|
[`input-otp-fill-${fill}`]: true,
|
|
17497
17485
|
'input-otp-disabled': disabled,
|
|
17498
17486
|
'input-otp-readonly': readonly,
|
|
17499
|
-
}) }, hAsync("div", Object.assign({ key: '
|
|
17487
|
+
}) }, hAsync("div", Object.assign({ key: '10d82d5c21171e3673b337da472139e8c9e077d7', role: "group", "aria-label": "One-time password input", class: "input-otp-group" }, inheritedAttributes), Array.from({ length }).map((_, index) => (hAsync(Fragment, null, hAsync("div", { class: "native-wrapper" }, hAsync("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) && hAsync("div", { class: "input-otp-separator" }))))), hAsync("div", { key: '3cbb5dd138c5640c71c51a5088ad1047a74d3ad6', class: {
|
|
17500
17488
|
'input-otp-description': true,
|
|
17501
17489
|
'input-otp-description-hidden': !hasDescription,
|
|
17502
|
-
} }, hAsync("slot", { key: '
|
|
17490
|
+
} }, hAsync("slot", { key: '9fdeca4d1eebd60334a48b103229d43849bbb0ac' }))));
|
|
17503
17491
|
}
|
|
17504
17492
|
get el() { return getElement(this); }
|
|
17505
17493
|
static get watchers() { return {
|
|
@@ -17523,14 +17511,13 @@ class InputOTP {
|
|
|
17523
17511
|
"length": [2],
|
|
17524
17512
|
"pattern": [1],
|
|
17525
17513
|
"readonly": [516],
|
|
17526
|
-
"size": [1],
|
|
17527
17514
|
"separators": [1],
|
|
17528
17515
|
"shape": [1],
|
|
17516
|
+
"size": [1],
|
|
17529
17517
|
"type": [1],
|
|
17530
17518
|
"value": [1032],
|
|
17531
17519
|
"inputValues": [32],
|
|
17532
17520
|
"hasFocus": [32],
|
|
17533
|
-
"reset": [64],
|
|
17534
17521
|
"setFocus": [64]
|
|
17535
17522
|
},
|
|
17536
17523
|
"$listeners$": undefined,
|