@ionic/core 8.5.7-dev.11748379940.12698faf → 8.5.7-dev.11748466845.12de1519
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/components/ion-input-otp.js +164 -164
- package/dist/cjs/ion-input-otp.cjs.entry.js +163 -163
- package/dist/cjs/ionic.cjs.js +1 -1
- package/dist/cjs/loader.cjs.js +1 -1
- package/dist/collection/components/input-otp/input-otp.js +183 -183
- package/dist/docs.json +1 -1
- package/dist/esm/ion-input-otp.entry.js +163 -163
- package/dist/esm/ionic.js +1 -1
- package/dist/esm/loader.js +1 -1
- package/dist/ionic/ionic.esm.js +1 -1
- package/dist/ionic/{p-702c7264.entry.js → p-cc51b53c.entry.js} +1 -1
- package/dist/types/components/input-otp/input-otp.d.ts +64 -64
- package/hydrate/index.js +164 -164
- package/hydrate/index.mjs +164 -164
- package/package.json +1 -1
package/hydrate/index.mjs
CHANGED
|
@@ -16983,10 +16983,6 @@ class InputOTP {
|
|
|
16983
16983
|
* If `true`, the user cannot modify the value.
|
|
16984
16984
|
*/
|
|
16985
16985
|
this.readonly = false;
|
|
16986
|
-
/**
|
|
16987
|
-
* The size of the input boxes.
|
|
16988
|
-
*/
|
|
16989
|
-
this.size = 'medium';
|
|
16990
16986
|
/**
|
|
16991
16987
|
* The shape of the input boxes.
|
|
16992
16988
|
* If "round" they will have an increased border radius.
|
|
@@ -16994,6 +16990,10 @@ class InputOTP {
|
|
|
16994
16990
|
* If "soft" they will have a soft border radius.
|
|
16995
16991
|
*/
|
|
16996
16992
|
this.shape = 'round';
|
|
16993
|
+
/**
|
|
16994
|
+
* The size of the input boxes.
|
|
16995
|
+
*/
|
|
16996
|
+
this.size = 'medium';
|
|
16997
16997
|
/**
|
|
16998
16998
|
* The type of input allowed in the input boxes.
|
|
16999
16999
|
*/
|
|
@@ -17002,34 +17002,63 @@ class InputOTP {
|
|
|
17002
17002
|
* The value of the input group.
|
|
17003
17003
|
*/
|
|
17004
17004
|
this.value = '';
|
|
17005
|
-
|
|
17006
|
-
|
|
17007
|
-
|
|
17008
|
-
|
|
17009
|
-
|
|
17010
|
-
|
|
17011
|
-
|
|
17012
|
-
|
|
17013
|
-
|
|
17014
|
-
|
|
17015
|
-
|
|
17016
|
-
|
|
17017
|
-
|
|
17018
|
-
|
|
17019
|
-
|
|
17020
|
-
|
|
17021
|
-
|
|
17005
|
+
/**
|
|
17006
|
+
* Handles the focus behavior for the input OTP component.
|
|
17007
|
+
*
|
|
17008
|
+
* Focus behavior:
|
|
17009
|
+
* 1. Keyboard navigation: Allow normal focus movement
|
|
17010
|
+
* 2. Mouse click:
|
|
17011
|
+
* - If clicked box has value: Focus that box
|
|
17012
|
+
* - If clicked box is empty: Focus first empty box
|
|
17013
|
+
*
|
|
17014
|
+
* Emits the `ionFocus` event when the input group gains focus.
|
|
17015
|
+
*/
|
|
17016
|
+
this.onFocus = (index) => (event) => {
|
|
17017
|
+
var _a;
|
|
17018
|
+
const { inputRefs } = this;
|
|
17019
|
+
// Only emit ionFocus and set the focusedValue when the
|
|
17020
|
+
// component first gains focus
|
|
17021
|
+
if (!this.hasFocus) {
|
|
17022
|
+
this.ionFocus.emit(event);
|
|
17023
|
+
this.focusedValue = this.value;
|
|
17022
17024
|
}
|
|
17023
|
-
|
|
17024
|
-
|
|
17025
|
-
|
|
17026
|
-
|
|
17027
|
-
|
|
17025
|
+
this.hasFocus = true;
|
|
17026
|
+
let finalIndex = index;
|
|
17027
|
+
if (!this.isKeyboardNavigation) {
|
|
17028
|
+
// If the clicked box has a value, focus it
|
|
17029
|
+
// Otherwise focus the first empty box
|
|
17030
|
+
const targetIndex = this.inputValues[index] ? index : this.getFirstEmptyIndex();
|
|
17031
|
+
finalIndex = targetIndex === -1 ? this.length - 1 : targetIndex;
|
|
17032
|
+
// Focus the target box
|
|
17033
|
+
(_a = this.inputRefs[finalIndex]) === null || _a === void 0 ? void 0 : _a.focus();
|
|
17028
17034
|
}
|
|
17029
|
-
|
|
17030
|
-
|
|
17035
|
+
// Update tabIndexes to match the focused box
|
|
17036
|
+
inputRefs.forEach((input, i) => {
|
|
17037
|
+
input.tabIndex = i === finalIndex ? 0 : -1;
|
|
17038
|
+
});
|
|
17039
|
+
// Reset the keyboard navigation flag
|
|
17040
|
+
this.isKeyboardNavigation = false;
|
|
17041
|
+
};
|
|
17042
|
+
/**
|
|
17043
|
+
* Handles the blur behavior for the input OTP component.
|
|
17044
|
+
* Emits the `ionBlur` event when the input group loses focus.
|
|
17045
|
+
*/
|
|
17046
|
+
this.onBlur = (event) => {
|
|
17047
|
+
const { inputRefs } = this;
|
|
17048
|
+
const relatedTarget = event.relatedTarget;
|
|
17049
|
+
// Do not emit blur if we're moving to another input box in the same component
|
|
17050
|
+
const isInternalFocus = relatedTarget != null && inputRefs.includes(relatedTarget);
|
|
17051
|
+
if (!isInternalFocus) {
|
|
17052
|
+
this.hasFocus = false;
|
|
17053
|
+
// Reset tabIndexes when focus leaves the component
|
|
17054
|
+
this.updateTabIndexes();
|
|
17055
|
+
// Always emit ionBlur when focus leaves the component
|
|
17056
|
+
this.ionBlur.emit(event);
|
|
17057
|
+
// Only emit ionChange if the value has actually changed
|
|
17058
|
+
if (this.focusedValue !== this.value) {
|
|
17059
|
+
this.emitIonChange(event);
|
|
17060
|
+
}
|
|
17031
17061
|
}
|
|
17032
|
-
this.updateValue(event);
|
|
17033
17062
|
};
|
|
17034
17063
|
/**
|
|
17035
17064
|
* Handles keyboard navigation and input for the OTP component.
|
|
@@ -17115,6 +17144,35 @@ class InputOTP {
|
|
|
17115
17144
|
event.preventDefault();
|
|
17116
17145
|
}
|
|
17117
17146
|
};
|
|
17147
|
+
this.onInput = (index) => (event) => {
|
|
17148
|
+
const { validKeyPattern } = this;
|
|
17149
|
+
const value = event.target.value;
|
|
17150
|
+
// Only allow input if it's a single character and matches the pattern
|
|
17151
|
+
if (value.length > 1 || (value.length > 0 && !validKeyPattern.test(value))) {
|
|
17152
|
+
// Reset the input value if not valid
|
|
17153
|
+
this.inputRefs[index].value = '';
|
|
17154
|
+
this.inputValues[index] = '';
|
|
17155
|
+
return;
|
|
17156
|
+
}
|
|
17157
|
+
// Find the first empty box before or at the current index
|
|
17158
|
+
let targetIndex = index;
|
|
17159
|
+
for (let i = 0; i < index; i++) {
|
|
17160
|
+
if (!this.inputValues[i] || this.inputValues[i] === '') {
|
|
17161
|
+
targetIndex = i;
|
|
17162
|
+
break;
|
|
17163
|
+
}
|
|
17164
|
+
}
|
|
17165
|
+
// Set the value at the target index
|
|
17166
|
+
this.inputValues[targetIndex] = value;
|
|
17167
|
+
// If the value was entered in a later box, clear the current box
|
|
17168
|
+
if (targetIndex !== index) {
|
|
17169
|
+
this.inputRefs[index].value = '';
|
|
17170
|
+
}
|
|
17171
|
+
if (value.length > 0) {
|
|
17172
|
+
this.focusNext(targetIndex);
|
|
17173
|
+
}
|
|
17174
|
+
this.updateValue(event);
|
|
17175
|
+
};
|
|
17118
17176
|
/**
|
|
17119
17177
|
* Handles pasting text into the input OTP component.
|
|
17120
17178
|
* This function prevents the default paste behavior and
|
|
@@ -17158,64 +17216,35 @@ class InputOTP {
|
|
|
17158
17216
|
(_c = inputRefs[length - 1]) === null || _c === void 0 ? void 0 : _c.focus();
|
|
17159
17217
|
}
|
|
17160
17218
|
};
|
|
17161
|
-
|
|
17162
|
-
|
|
17163
|
-
|
|
17164
|
-
|
|
17165
|
-
|
|
17166
|
-
|
|
17167
|
-
|
|
17168
|
-
|
|
17169
|
-
|
|
17170
|
-
|
|
17171
|
-
|
|
17172
|
-
this.
|
|
17173
|
-
|
|
17174
|
-
|
|
17175
|
-
|
|
17176
|
-
|
|
17177
|
-
|
|
17178
|
-
|
|
17179
|
-
|
|
17180
|
-
|
|
17181
|
-
|
|
17182
|
-
|
|
17183
|
-
|
|
17184
|
-
|
|
17185
|
-
|
|
17186
|
-
|
|
17187
|
-
|
|
17188
|
-
|
|
17189
|
-
|
|
17190
|
-
}
|
|
17191
|
-
// Update tabIndexes to match the focused box
|
|
17192
|
-
inputRefs.forEach((input, i) => {
|
|
17193
|
-
input.tabIndex = i === finalIndex ? 0 : -1;
|
|
17194
|
-
});
|
|
17195
|
-
// Reset the keyboard navigation flag
|
|
17196
|
-
this.isKeyboardNavigation = false;
|
|
17197
|
-
};
|
|
17198
|
-
/**
|
|
17199
|
-
* Handles the blur behavior for the input OTP component.
|
|
17200
|
-
* Emits the `ionBlur` event when the input group loses focus.
|
|
17201
|
-
*/
|
|
17202
|
-
this.onBlur = (event) => {
|
|
17203
|
-
const { inputRefs } = this;
|
|
17204
|
-
const relatedTarget = event.relatedTarget;
|
|
17205
|
-
// Do not emit blur if we're moving to another input box in the same component
|
|
17206
|
-
const isInternalFocus = relatedTarget != null && inputRefs.includes(relatedTarget);
|
|
17207
|
-
if (!isInternalFocus) {
|
|
17208
|
-
this.hasFocus = false;
|
|
17209
|
-
// Reset tabIndexes when focus leaves the component
|
|
17210
|
-
this.updateTabIndexes();
|
|
17211
|
-
// Always emit ionBlur when focus leaves the component
|
|
17212
|
-
this.ionBlur.emit(event);
|
|
17213
|
-
// Only emit ionChange if the value has actually changed
|
|
17214
|
-
if (this.focusedValue !== this.value) {
|
|
17215
|
-
this.emitIonChange(event);
|
|
17216
|
-
}
|
|
17217
|
-
}
|
|
17218
|
-
};
|
|
17219
|
+
}
|
|
17220
|
+
/**
|
|
17221
|
+
* Resets the value and focus state.
|
|
17222
|
+
*/
|
|
17223
|
+
async reset() {
|
|
17224
|
+
this.value = '';
|
|
17225
|
+
this.focusedValue = null;
|
|
17226
|
+
this.hasFocus = false;
|
|
17227
|
+
this.inputRefs.forEach((input) => {
|
|
17228
|
+
input.blur();
|
|
17229
|
+
});
|
|
17230
|
+
this.updateTabIndexes();
|
|
17231
|
+
}
|
|
17232
|
+
/**
|
|
17233
|
+
* Sets focus to an input box.
|
|
17234
|
+
* @param index - The index of the input box to focus (0-based).
|
|
17235
|
+
* If provided and the input box has a value, the input box at that index will be focused.
|
|
17236
|
+
* Otherwise, the first empty input box or the last input if all are filled will be focused.
|
|
17237
|
+
*/
|
|
17238
|
+
async setFocus(index) {
|
|
17239
|
+
var _a, _b;
|
|
17240
|
+
if (typeof index === 'number') {
|
|
17241
|
+
const validIndex = Math.max(0, Math.min(index, this.length - 1));
|
|
17242
|
+
(_a = this.inputRefs[validIndex]) === null || _a === void 0 ? void 0 : _a.focus();
|
|
17243
|
+
}
|
|
17244
|
+
else {
|
|
17245
|
+
const tabbableIndex = this.getTabbableIndex();
|
|
17246
|
+
(_b = this.inputRefs[tabbableIndex]) === null || _b === void 0 ? void 0 : _b.focus();
|
|
17247
|
+
}
|
|
17219
17248
|
}
|
|
17220
17249
|
valueChanged() {
|
|
17221
17250
|
this.initializeValues();
|
|
@@ -17276,59 +17305,6 @@ class InputOTP {
|
|
|
17276
17305
|
componentDidLoad() {
|
|
17277
17306
|
this.updateTabIndexes();
|
|
17278
17307
|
}
|
|
17279
|
-
/**
|
|
17280
|
-
* Initializes the input values array based on the current value prop.
|
|
17281
|
-
* This splits the value into individual characters and validates them against
|
|
17282
|
-
* the allowed pattern. The values are then used as the values in the native
|
|
17283
|
-
* input boxes and the value of the input group is updated.
|
|
17284
|
-
*/
|
|
17285
|
-
initializeValues() {
|
|
17286
|
-
// Clear all input values
|
|
17287
|
-
this.inputValues = Array(this.length).fill('');
|
|
17288
|
-
// If the value is null, undefined, or an empty string, return
|
|
17289
|
-
if (this.value == null || String(this.value).length === 0) {
|
|
17290
|
-
return;
|
|
17291
|
-
}
|
|
17292
|
-
// Split the value into individual characters and validate
|
|
17293
|
-
// them against the allowed pattern
|
|
17294
|
-
const chars = String(this.value).split('').slice(0, this.length);
|
|
17295
|
-
chars.forEach((char, index) => {
|
|
17296
|
-
if (this.validKeyPattern.test(char)) {
|
|
17297
|
-
this.inputValues[index] = char;
|
|
17298
|
-
}
|
|
17299
|
-
});
|
|
17300
|
-
// Update the value without emitting events
|
|
17301
|
-
this.value = this.inputValues.join('');
|
|
17302
|
-
}
|
|
17303
|
-
/**
|
|
17304
|
-
* Resets the value and focus state.
|
|
17305
|
-
*/
|
|
17306
|
-
async reset() {
|
|
17307
|
-
this.value = '';
|
|
17308
|
-
this.focusedValue = null;
|
|
17309
|
-
this.hasFocus = false;
|
|
17310
|
-
this.inputRefs.forEach((input) => {
|
|
17311
|
-
input.blur();
|
|
17312
|
-
});
|
|
17313
|
-
this.updateTabIndexes();
|
|
17314
|
-
}
|
|
17315
|
-
/**
|
|
17316
|
-
* Sets focus to an input box.
|
|
17317
|
-
* @param index - The index of the input box to focus (0-based).
|
|
17318
|
-
* If provided and the input box has a value, the input box at that index will be focused.
|
|
17319
|
-
* Otherwise, the first empty input box or the last input if all are filled will be focused.
|
|
17320
|
-
*/
|
|
17321
|
-
async setFocus(index) {
|
|
17322
|
-
var _a, _b;
|
|
17323
|
-
if (typeof index === 'number') {
|
|
17324
|
-
const validIndex = Math.max(0, Math.min(index, this.length - 1));
|
|
17325
|
-
(_a = this.inputRefs[validIndex]) === null || _a === void 0 ? void 0 : _a.focus();
|
|
17326
|
-
}
|
|
17327
|
-
else {
|
|
17328
|
-
const tabbableIndex = this.getTabbableIndex();
|
|
17329
|
-
(_b = this.inputRefs[tabbableIndex]) === null || _b === void 0 ? void 0 : _b.focus();
|
|
17330
|
-
}
|
|
17331
|
-
}
|
|
17332
17308
|
/**
|
|
17333
17309
|
* Get the regex pattern for allowed characters.
|
|
17334
17310
|
* If a pattern is provided, use it to create a regex pattern
|
|
@@ -17365,6 +17341,30 @@ class InputOTP {
|
|
|
17365
17341
|
return 'text';
|
|
17366
17342
|
}
|
|
17367
17343
|
}
|
|
17344
|
+
/**
|
|
17345
|
+
* Initializes the input values array based on the current value prop.
|
|
17346
|
+
* This splits the value into individual characters and validates them against
|
|
17347
|
+
* the allowed pattern. The values are then used as the values in the native
|
|
17348
|
+
* input boxes and the value of the input group is updated.
|
|
17349
|
+
*/
|
|
17350
|
+
initializeValues() {
|
|
17351
|
+
// Clear all input values
|
|
17352
|
+
this.inputValues = Array(this.length).fill('');
|
|
17353
|
+
// If the value is null, undefined, or an empty string, return
|
|
17354
|
+
if (this.value == null || String(this.value).length === 0) {
|
|
17355
|
+
return;
|
|
17356
|
+
}
|
|
17357
|
+
// Split the value into individual characters and validate
|
|
17358
|
+
// them against the allowed pattern
|
|
17359
|
+
const chars = String(this.value).split('').slice(0, this.length);
|
|
17360
|
+
chars.forEach((char, index) => {
|
|
17361
|
+
if (this.validKeyPattern.test(char)) {
|
|
17362
|
+
this.inputValues[index] = char;
|
|
17363
|
+
}
|
|
17364
|
+
});
|
|
17365
|
+
// Update the value without emitting events
|
|
17366
|
+
this.value = this.inputValues.join('');
|
|
17367
|
+
}
|
|
17368
17368
|
/**
|
|
17369
17369
|
* Updates the value of the input group.
|
|
17370
17370
|
* This updates the value of the input group and emits an `ionChange` event.
|
|
@@ -17423,12 +17423,27 @@ class InputOTP {
|
|
|
17423
17423
|
}
|
|
17424
17424
|
}
|
|
17425
17425
|
/**
|
|
17426
|
-
*
|
|
17427
|
-
*
|
|
17426
|
+
* Searches through the input values and returns the index
|
|
17427
|
+
* of the first empty input.
|
|
17428
|
+
* Returns -1 if all inputs are filled.
|
|
17428
17429
|
*/
|
|
17429
|
-
|
|
17430
|
+
getFirstEmptyIndex() {
|
|
17431
|
+
var _a;
|
|
17432
|
+
const { inputValues, length } = this;
|
|
17433
|
+
// Create an array of the same length as the input OTP
|
|
17434
|
+
// and fill it with the input values
|
|
17435
|
+
const values = Array.from({ length }, (_, i) => inputValues[i] || '');
|
|
17436
|
+
return (_a = values.findIndex((value) => !value || value === '')) !== null && _a !== void 0 ? _a : -1;
|
|
17437
|
+
}
|
|
17438
|
+
/**
|
|
17439
|
+
* Returns the index of the input that should be tabbed to.
|
|
17440
|
+
* If all inputs are filled, returns the last input's index.
|
|
17441
|
+
* Otherwise, returns the index of the first empty input.
|
|
17442
|
+
*/
|
|
17443
|
+
getTabbableIndex() {
|
|
17430
17444
|
const { length } = this;
|
|
17431
|
-
|
|
17445
|
+
const firstEmptyIndex = this.getFirstEmptyIndex();
|
|
17446
|
+
return firstEmptyIndex === -1 ? length - 1 : firstEmptyIndex;
|
|
17432
17447
|
}
|
|
17433
17448
|
/**
|
|
17434
17449
|
* Updates the tabIndexes for the input boxes.
|
|
@@ -17456,27 +17471,12 @@ class InputOTP {
|
|
|
17456
17471
|
});
|
|
17457
17472
|
}
|
|
17458
17473
|
/**
|
|
17459
|
-
*
|
|
17460
|
-
*
|
|
17461
|
-
* Returns -1 if all inputs are filled.
|
|
17462
|
-
*/
|
|
17463
|
-
getFirstEmptyIndex() {
|
|
17464
|
-
var _a;
|
|
17465
|
-
const { inputValues, length } = this;
|
|
17466
|
-
// Create an array of the same length as the input OTP
|
|
17467
|
-
// and fill it with the input values
|
|
17468
|
-
const values = Array.from({ length }, (_, i) => inputValues[i] || '');
|
|
17469
|
-
return (_a = values.findIndex((value) => !value || value === '')) !== null && _a !== void 0 ? _a : -1;
|
|
17470
|
-
}
|
|
17471
|
-
/**
|
|
17472
|
-
* Returns the index of the input that should be tabbed to.
|
|
17473
|
-
* If all inputs are filled, returns the last input's index.
|
|
17474
|
-
* Otherwise, returns the index of the first empty input.
|
|
17474
|
+
* Determines if a separator should be shown for a given index by
|
|
17475
|
+
* checking if the index is included in the parsed separators array.
|
|
17475
17476
|
*/
|
|
17476
|
-
|
|
17477
|
+
showSeparator(index) {
|
|
17477
17478
|
const { length } = this;
|
|
17478
|
-
|
|
17479
|
-
return firstEmptyIndex === -1 ? length - 1 : firstEmptyIndex;
|
|
17479
|
+
return this.parsedSeparators.includes(index + 1) && index < length - 1;
|
|
17480
17480
|
}
|
|
17481
17481
|
render() {
|
|
17482
17482
|
var _a, _b;
|
|
@@ -17521,9 +17521,9 @@ class InputOTP {
|
|
|
17521
17521
|
"length": [2],
|
|
17522
17522
|
"pattern": [1],
|
|
17523
17523
|
"readonly": [516],
|
|
17524
|
-
"size": [1],
|
|
17525
17524
|
"separators": [1],
|
|
17526
17525
|
"shape": [1],
|
|
17526
|
+
"size": [1],
|
|
17527
17527
|
"type": [1],
|
|
17528
17528
|
"value": [1032],
|
|
17529
17529
|
"inputValues": [32],
|