@descope/web-components-ui 3.14.9 → 3.14.10

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/dist/index.esm.js CHANGED
@@ -9383,6 +9383,13 @@ class PasscodeInternal extends BaseInputClass$d {
9383
9383
 
9384
9384
  const debouncedHandleParseInput = debounce(handleParseInput, 0, { trailing: true });
9385
9385
 
9386
+ // Per-input flag: set in keydown, consumed in the input event.
9387
+ // Fallback for WebKit/Safari, where the native input event can fire
9388
+ // non-composed; proxyInputMixin then re-dispatches it as a plain Event
9389
+ // (no inputType), so the 'deleteContentBackward' check misses the
9390
+ // backspace and navigation is skipped.
9391
+ let lastKeyWasBackspace = false;
9392
+
9386
9393
  // sanitize the input
9387
9394
  input.addEventListener('input', (e) => {
9388
9395
  input.value = sanitizeStr(input.value);
@@ -9391,29 +9398,50 @@ class PasscodeInternal extends BaseInputClass$d {
9391
9398
  toggleMaskVisibility(input, input.value[0]);
9392
9399
  }
9393
9400
 
9394
- setTimeout(() => {
9395
- if (e?.inputType === 'deleteContentBackward') {
9396
- focusElement(this.getPrevInput(input));
9397
- }
9398
- });
9401
+ // inputType covers iOS (unreliable keydown); the flag covers WebKit
9402
+ // (missing inputType). See flag declaration above.
9403
+ const isBackspace = e?.inputType === 'deleteContentBackward' || lastKeyWasBackspace;
9404
+ lastKeyWasBackspace = false;
9405
+
9406
+ if (isBackspace) {
9407
+ // Navigate synchronously (no setTimeout) to prevent WebKit key-event
9408
+ // leakage: with setTimeout(0), WebKit can dispatch the next key-repeat
9409
+ // backspace event to the newly focused element, deleting a second digit.
9410
+ // Calling focusElement here (inside the input event, not keydown) is safe
9411
+ // because the browser has already finished processing the deletion.
9412
+ focusElement(this.getPrevInput(input));
9413
+ }
9414
+
9399
9415
  debouncedHandleParseInput(input.value);
9400
9416
  });
9401
9417
 
9402
9418
  // we want backspace to focus on the previous digit
9403
- input.onkeydown = ({ key }) => {
9404
- // when user deletes a digit, we want to focus the previous digit
9419
+ input.onkeydown = (e) => {
9420
+ const { key } = e;
9405
9421
  if (key === 'Backspace') {
9406
- // if value is empty then the input element does not fire `input` event
9407
- // if this is the case, we focus the element here.
9408
- // otherwise, the focusElement occurs as part of the `input` event listener
9409
9422
  if (!input.value) {
9410
- setTimeout(() => focusElement(this.getPrevInput(input)), 0);
9423
+ // Empty field: the input event will not fire (nothing to delete),
9424
+ // so we must handle navigation here.
9425
+ // e.preventDefault() stops WebKit from leaking this keypress to
9426
+ // the element that receives focus (key-event leakage).
9427
+ e.preventDefault();
9428
+ lastKeyWasBackspace = false;
9429
+ focusElement(this.getPrevInput(input));
9411
9430
  } else {
9431
+ // Non-empty field: let the browser delete normally so the input
9432
+ // event fires (needed on older iOS where keydown is unreliable).
9433
+ // Move the caret to the end first so Backspace deletes the digit
9434
+ // even if a direct tap left the caret before it (caret at index 0).
9412
9435
  input.setSelectionRange(1, 1);
9436
+ // Fallback signal for the input handler (see flag declaration above).
9437
+ lastKeyWasBackspace = true;
9438
+ }
9439
+ } else {
9440
+ lastKeyWasBackspace = false;
9441
+ if (key.length === 1) {
9442
+ // we want only characters and not command keys
9443
+ input.value = ''; // we are clearing the previous value so we can override it with the new value
9413
9444
  }
9414
- } else if (key.length === 1) {
9415
- // we want only characters and not command keys
9416
- input.value = ''; // we are clearing the previous value so we can override it with the new value
9417
9445
  }
9418
9446
  };
9419
9447