Skip to content

Commit

Permalink
fix(kit): reuse cursor position after showing password
Browse files Browse the repository at this point in the history
  • Loading branch information
splincode committed Jul 24, 2024
1 parent 276879b commit 417cce3
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions projects/kit/components/input-password/input-password.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ import {
} from '@taiga-ui/core';
import {TUI_PASSWORD_TEXTS} from '@taiga-ui/kit/tokens';
import {PolymorpheusContent} from '@tinkoff/ng-polymorpheus';
import {combineLatest, EMPTY, Observable} from 'rxjs';
import {map, startWith} from 'rxjs/operators';
import {combineLatest, EMPTY, Observable, timer} from 'rxjs';
import {map, startWith, takeUntil} from 'rxjs/operators';

import {
TUI_INPUT_PASSWORD_OPTIONS,
Expand Down Expand Up @@ -128,9 +128,24 @@ export class TuiInputPasswordComponent

togglePasswordVisibility(): void {
this.isPasswordHidden = !this.isPasswordHidden;

this.reuseCursorPosition();
}

protected getFallbackValue(): string {
return '';
}

private reuseCursorPosition(): void {
const selectionStart =
this.textfield?.nativeFocusableElement?.selectionStart ?? 0;

timer(0)
.pipe(takeUntil(this.destroy$))
.subscribe(() => {
if (this.textfield?.nativeFocusableElement) {
this.textfield.nativeFocusableElement.selectionStart = selectionStart;
}
});
}
}

0 comments on commit 417cce3

Please sign in to comment.