Skip to content

Commit

Permalink
fix(cdk): FocusTrap blur manually to prevent ExpressionChanged error (
Browse files Browse the repository at this point in the history
#40)

* fix(cdk): `FocusTrap` blur manually to prevent ExpressionChanged error

* improve types for matchers
  • Loading branch information
waterplea committed Nov 23, 2020
1 parent 3a9f2db commit 339df70
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
14 changes: 7 additions & 7 deletions projects/cdk/constants/matcher.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {TuiIdentityMatcher, TuiMatcher, TuiStringHandler} from '@taiga-ui/cdk/types';
import {TuiIdentityMatcher, TuiStringHandler} from '@taiga-ui/cdk/types';
import {TUI_DEFAULT_STRINGIFY} from './stringify';

/**
Expand All @@ -7,10 +7,10 @@ import {TUI_DEFAULT_STRINGIFY} from './stringify';
* @param search search query
* @param stringify handler to turn item into a string
*/
export const TUI_DEFAULT_MATCHER: TuiMatcher<any> = (
item,
export const TUI_DEFAULT_MATCHER = <T>(
item: T,
search: string,
stringify: TuiStringHandler<any> = TUI_DEFAULT_STRINGIFY,
stringify: TuiStringHandler<T> = TUI_DEFAULT_STRINGIFY,
) => stringify(item).toLowerCase().includes(search.toLowerCase());

/**
Expand All @@ -19,10 +19,10 @@ export const TUI_DEFAULT_MATCHER: TuiMatcher<any> = (
* @param search search query
* @param stringify handler to turn item into a string
*/
export const TUI_STRICT_MATCHER: TuiMatcher<any> = (
item,
export const TUI_STRICT_MATCHER = <T>(
item: T,
search: string,
stringify: TuiStringHandler<any> = TUI_DEFAULT_STRINGIFY,
stringify: TuiStringHandler<T> = TUI_DEFAULT_STRINGIFY,
) => stringify(item).toLowerCase() === search.toLowerCase();

/**
Expand Down
6 changes: 5 additions & 1 deletion projects/cdk/directives/focus-trap/focus-trap.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ export class TuiFocusTrapDirective implements AfterViewInit, OnDestroy {
@Inject(ElementRef)
private readonly elementRef: ElementRef<HTMLElement>,
@Inject(Renderer2) private readonly renderer: Renderer2,
) {}
) {
if (this.activeElement instanceof HTMLElement) {
setNativeFocused(this.activeElement, false);
}
}

ngAfterViewInit() {
setNativeFocused(this.elementRef.nativeElement);
Expand Down

0 comments on commit 339df70

Please sign in to comment.