Skip to content

Commit

Permalink
feat: add hostlisener binding (#135)
Browse files Browse the repository at this point in the history
  • Loading branch information
omridevk authored May 16, 2022
1 parent 7e64a3c commit 1f8ec42
Show file tree
Hide file tree
Showing 14 changed files with 158 additions and 12,834 deletions.
2 changes: 1 addition & 1 deletion apps/playground/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { MediaMatcher } from "@angular/cdk/layout";
import {
KeyboardShortcutsHelpService,
KeyboardShortcutsSelectService
} from "@ng-keyboard-shortcuts/ng-keyboard-shortcuts";
} from "ng-keyboard-shortcuts";
@Component({
selector: "ng-keyboard-shortcuts-demo-app",
templateUrl: "./app.component.html",
Expand Down
2 changes: 1 addition & 1 deletion apps/playground/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { NgModule } from "@angular/core";
import { BrowserModule } from "@angular/platform-browser";
import { BrowserAnimationsModule } from "@angular/platform-browser/animations";
import { AppComponent } from "./app.component";
import { KeyboardShortcutsModule } from "@ng-keyboard-shortcuts/ng-keyboard-shortcuts";
import { KeyboardShortcutsModule } from "ng-keyboard-shortcuts";
import { AppRoutingModule } from "./app-routing.module";
import { GettingStartedComponent } from "./getting-started/getting-started.component";
import { HomeComponent } from "./home/home.component";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AfterViewInit, Component, OnDestroy, OnInit, ViewChild } from "@angular/core";
import { ShortcutInput } from "@ng-keyboard-shortcuts/ng-keyboard-shortcuts";
import { KeyboardShortcutsComponent } from "@ng-keyboard-shortcuts/ng-keyboard-shortcuts";
import { ShortcutInput } from "ng-keyboard-shortcuts";
import { KeyboardShortcutsComponent } from "ng-keyboard-shortcuts";
import { Subscription } from "rxjs";

@Component({
Expand Down
2 changes: 1 addition & 1 deletion apps/playground/src/app/home/home.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
ShortcutDirectiveInput,
ShortcutEventOutput,
ShortcutInput
} from '@ng-keyboard-shortcuts/ng-keyboard-shortcuts';
} from 'ng-keyboard-shortcuts';

@Component({
selector: "app-home",
Expand Down
14 changes: 12 additions & 2 deletions apps/playground/src/app/nested/nested.component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Component, OnInit, ChangeDetectionStrategy, AfterViewInit} from '@angular/core';
import {ShortcutInput} from '@ng-keyboard-shortcuts/ng-keyboard-shortcuts';
import {Component, OnInit, AfterViewInit, HostListener} from '@angular/core';
import {ShortcutInput} from 'ng-keyboard-shortcuts';

@Component({
selector: "ng-keyboard-shortcuts-nested",
Expand All @@ -17,6 +17,16 @@ export class NestedComponent implements OnInit, AfterViewInit {
selectedIndex = 0;
disabledShortcuts = false;

@HostListener("shortcut.t k", ['$event'])
onShortcut(event) {
console.log(event);
}

@HostListener("shortcut.shift + y.prevent")
onShift() {
console.log("ty")
}

ngAfterViewInit() {
this.shortcuts.push(
{
Expand Down
8 changes: 8 additions & 0 deletions docs/docs/host-listener/_category_.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"label": "@HostListener",
"position": 2,
"link": {
"type": "generated-index",
"description": "@HostListener to bind events"
}
}
21 changes: 21 additions & 0 deletions docs/docs/host-listener/host-listener.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
id: host-listener
title: HostListener to bind events
sidebar_position: 3
---

Keyboard shortcuts can also be bind using HostListener in a component
This is a quick way to add shortcut to your application

Events are defined using the __shortcut__ prefix and then the shortcut
You can use sequences and combinations.

## Usage
```typescript
import {HostListener} from '@angular/core';

@HostListener("shortcut.k + t")
onShortcut() {
console.log("shortcut clicked!!")
}
```
Loading

1 comment on commit 1f8ec42

@vercel
Copy link

@vercel vercel bot commented on 1f8ec42 May 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.