-
-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(attach-focus): make work as boolean attr
see #349 for more details
- Loading branch information
1 parent
f29d8cb
commit f75abb4
Showing
3 changed files
with
67 additions
and
40 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,23 @@ | ||
import { bindingMode } from 'aurelia-binding'; | ||
import { customAttribute, ComponentAttached } from 'aurelia-templating'; | ||
import { DOM } from 'aurelia-pal'; | ||
|
||
@customAttribute('attach-focus') | ||
export default class AttachFocus implements ComponentAttached { | ||
@customAttribute('attach-focus', bindingMode.oneTime) | ||
export class AttachFocus implements ComponentAttached { | ||
public value: boolean | string; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
// tslint:disable-next-line:member-ordering | ||
public static inject() { return [DOM.Element]; } | ||
public static inject = [DOM.Element]; | ||
constructor(private element: HTMLElement) { | ||
this.value = true; | ||
} | ||
|
||
public attached(): void { | ||
if (this.value && this.value !== 'false') { | ||
if (this.value === '' || (this.value && this.value !== 'false')) { | ||
this.element.focus(); | ||
} | ||
} | ||
|
||
public valueChanged(newValue: string) { | ||
this.value = newValue; | ||
} | ||
} |
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