Skip to content

Instantly share code, notes, and snippets.

@embarq
Created June 28, 2018 11:01
Show Gist options
  • Select an option

  • Save embarq/8ba44b37630cfafd5c7ec96c59ca2b08 to your computer and use it in GitHub Desktop.

Select an option

Save embarq/8ba44b37630cfafd5c7ec96c59ca2b08 to your computer and use it in GitHub Desktop.
@Directive({
selector: '[openNextField]'
})
/**
* @example
* <form>
* <ion-list>
* <ion-item>
* <ion-label>Text field</ion-label>
* <ion-input [openNextField]="selectFieldRef"></ion-input>
* </ion-item>
* <ion-item>
* <ion-label>Select field</ion-label>
* <ion-select #selectFieldRef>
* <ion-option>1</ion-option>
* <ion-option>2</ion-option>
* </ion-select>
* </ion-item>
* </ion-list>
* </form>
*/
export class OpenNextFieldDirective {
@Input('openNextField')
private nextFieldRef: Select | Datetime;
private readonly tabKeyCode = 9;
@HostListener('keyup', ['$event'])
public handleNextKey(event) {
if (event.keyCode === this.tabKeyCode && this.nextFieldRef != null) {
this.nextFieldRef.open();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment