@descope/web-components-ui 1.0.320 → 1.0.321

Sign up to get free protection for your applications and to get access to all the features.
@@ -3475,6 +3475,8 @@ const customMixin$9 = (superclass) =>
3475
3475
  // create external input
3476
3476
  const externalInput = createExternalInputEle('external-input', this.getAutocompleteType());
3477
3477
 
3478
+ this.handlePasswordVisibility(externalInput);
3479
+
3478
3480
  // apply original input's styles to external input
3479
3481
  setTimeout(() => {
3480
3482
  applyExternalInputStyles(origInput, externalInput);
@@ -3485,6 +3487,7 @@ const customMixin$9 = (superclass) =>
3485
3487
 
3486
3488
  // sync input stateful attributes: `type` (for visibility state change) and `readonly`
3487
3489
  syncAttrs(origInput, externalInput, { includeAttrs: ['type', 'readonly'] });
3490
+ syncAttrs(this, externalInput, { includeAttrs: ['focused'] });
3488
3491
 
3489
3492
  origInput.addEventListener('focus', (e) => {
3490
3493
  e.preventDefault();
@@ -3502,6 +3505,59 @@ const customMixin$9 = (superclass) =>
3502
3505
  this.appendChild(externalInput);
3503
3506
  }
3504
3507
 
3508
+ // override vaadin's password visibility toggle.
3509
+ // we need this override in order to to resolve the external input `focus` race condition,
3510
+ // which is caused due to the focus sync between the two inputs.
3511
+ handlePasswordVisibility(externalInput) {
3512
+ // disable vaadin's `__boundRevealButtonMouseDown` mouse-down event lisetener
3513
+ const origBoundRevealButtonMouseDown = this.baseElement.__boundRevealButtonMouseDown;
3514
+ this.baseElement
3515
+ .querySelector('vaadin-password-field-button')
3516
+ .removeEventListener('mousedown', origBoundRevealButtonMouseDown);
3517
+
3518
+ // disable vaadin's `_passwordVisibleChanged` observer
3519
+ this.baseElement._passwordVisibleChanged = () => {};
3520
+
3521
+ // override vaadin's `_togglePasswordVisibility`
3522
+ this.baseElement._togglePasswordVisibility = () => {
3523
+ const currVisibility = externalInput.getAttribute('type');
3524
+ if (currVisibility === 'password') {
3525
+ this.showPasswordVisibility(externalInput);
3526
+ } else {
3527
+ this.hidePasswordVisibility(externalInput);
3528
+ }
3529
+ };
3530
+
3531
+ // on component blur, if password is revealed - hide it
3532
+ // this behaves differently from vaadin's focus handling, and checks if the blur takes the component out of focus
3533
+ // (which menas the click was made outside the component) or if the blur was called due to clicking the Reveal Button
3534
+ // and then focusing in the input again
3535
+ this.addEventListener('blur', () => {
3536
+ setTimeout(() => {
3537
+ const isHiddenAndFocused =
3538
+ externalInput.getAttribute('type') !== 'password' &&
3539
+ externalInput.getAttribute('focused') !== 'true';
3540
+ if (isHiddenAndFocused) {
3541
+ this.hidePasswordVisibility(externalInput);
3542
+ }
3543
+ });
3544
+ });
3545
+ }
3546
+
3547
+ hidePasswordVisibility(input) {
3548
+ // handle input element's type
3549
+ input.setAttribute('type', 'password');
3550
+ // handle vaadin's `password-visible` attribute
3551
+ this.setAttribute('password-visible', 'false');
3552
+ }
3553
+
3554
+ showPasswordVisibility(input) {
3555
+ // handle input element's type
3556
+ input.setAttribute('type', 'text');
3557
+ // handle vaadin's `password-visible` attribute
3558
+ this.setAttribute('password-visible', 'true');
3559
+ }
3560
+
3505
3561
  getAutocompleteType() {
3506
3562
  return this.getAttribute('autocomplete') || 'current-password';
3507
3563
  }