Skip to content

Commit

Permalink
refactor: reuse cursor position after showing password
Browse files Browse the repository at this point in the history
  • Loading branch information
splincode committed Aug 5, 2024
1 parent 864e50e commit fd19064
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 16 deletions.
18 changes: 2 additions & 16 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, timer} from 'rxjs';
import {map, startWith, takeUntil} from 'rxjs/operators';
import {combineLatest, EMPTY, Observable} from 'rxjs';
import {map, startWith} from 'rxjs/operators';

import {
TUI_INPUT_PASSWORD_OPTIONS,
Expand Down Expand Up @@ -128,23 +128,9 @@ 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),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
[tuiHintAppearance]="(computedAppearance$ | async) || ''"
[tuiHintDirection]="hintOptions?.direction || 'bottom-left'"
(click)="togglePasswordVisibility()"
(mousedown.silent.prevent)="(0)"
(mouseup.silent.prevent)="(0)"
></tui-svg>

<ng-template
Expand Down

0 comments on commit fd19064

Please sign in to comment.