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 31, 2024
1 parent 276879b commit 95e0275
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 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,23 @@ export class TuiInputPasswordComponent

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

this.reuseCursorPosition();
}

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

private reuseCursorPosition(): void {
const {selectionStart: start = 0, selectionEnd: end = 0} =
this.textfield?.nativeFocusableElement ?? {};

timer(0)
.pipe(takeUntil(this.destroy$))
.subscribe(
() =>
this.textfield?.nativeFocusableElement?.setSelectionRange(start, end),
);
}
}

0 comments on commit 95e0275

Please sign in to comment.