-
Notifications
You must be signed in to change notification settings - Fork 470
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cdk): support provide custom query selector for auto focus direc…
…tive
- Loading branch information
Showing
7 changed files
with
51 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 7 additions & 4 deletions
11
projects/cdk/directives/auto-focus/handlers/abstract.handler.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,25 @@ | ||
import type {ElementRef} from '@angular/core'; | ||
|
||
import type {TuiAutofocusHandler} from '../autofocus.options'; | ||
import type {TuiAutofocusHandler, TuiAutofocusOptions} from '../autofocus.options'; | ||
|
||
export abstract class AbstractTuiAutofocusHandler implements TuiAutofocusHandler { | ||
constructor(protected readonly el: ElementRef<HTMLElement>) {} | ||
constructor( | ||
protected readonly el: ElementRef<HTMLElement>, | ||
protected readonly options: TuiAutofocusOptions, | ||
) {} | ||
|
||
public abstract setFocus(): void; | ||
|
||
protected get element(): HTMLElement { | ||
// TODO: Remove when legacy controls are dropped | ||
const el = this.el.nativeElement.tagName.includes('-') | ||
? this.el.nativeElement.querySelector<HTMLElement>('input,textarea') | ||
? this.el.nativeElement.querySelector<HTMLElement>(this.options.query) | ||
: this.el.nativeElement; | ||
|
||
return el || this.el.nativeElement; | ||
} | ||
|
||
protected get isTextFieldElement(): boolean { | ||
return this.element.matches('input, textarea, [contenteditable]'); | ||
return this.element.matches(this.options.query); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
import {InjectionToken} from '@angular/core'; | ||
|
||
export function tuiCreateToken<T>(defaults: T): InjectionToken<T> { | ||
export function tuiCreateToken<T>(defaults?: T): InjectionToken<T> { | ||
return tuiCreateTokenFromFactory(() => defaults); | ||
} | ||
|
||
export function tuiCreateTokenFromFactory<T>(factory: () => T): InjectionToken<T> { | ||
return new InjectionToken<T>('', {factory}); | ||
export function tuiCreateTokenFromFactory<T>(factory?: () => T): InjectionToken<T> { | ||
return factory ? new InjectionToken<T>('', {factory}) : new InjectionToken<T>(''); | ||
} |