Coder Social home page Coder Social logo

ngneat / hotkeys Goto Github PK

View Code? Open in Web Editor NEW
328.0 8.0 17.0 1.38 MB

πŸ€– A declarative library for handling hotkeys in Angular applications

Home Page: https://netbasal.com/diy-keyboard-shortcuts-in-your-angular-application-4704734547a2

License: MIT License

JavaScript 6.22% TypeScript 87.65% HTML 3.69% CSS 0.30% SCSS 1.85% Shell 0.29%
hotkeys angular shortcuts

hotkeys's Introduction


Test MIT commitizen PRs styled with prettier All Contributors ngneat spectator

Shortcut like a pro!

A declarative library for handling hotkeys in Angular applications.

Web apps are getting closer and closer to be desktop-class applications. With this in mind, it makes sense to add hotkeys for those power users that are looking to navigate their favorite websites using hotkeys just as they do on their regular native apps. To help you have a better experience we developed Hotkeys.

Features

  • βœ… Support Element Scope
  • βœ… Support Global Listeners
  • βœ… Platform Agnostic
  • βœ… Hotkeys Cheatsheet

Table of Contents

Compatibility with Angular Versions

@ngneat/hotkeys Angular
3.x.x >=17.2
2.x.x >=16
1.3.x >=14
1.2.x <=13

Installation

npm install @ngneat/hotkeys

Usage

Module

Add HotkeysModule in your AppModule:

import { HotkeysModule } from '@ngneat/hotkeys';

@NgModule({
  imports: [HotkeysModule]
})
export class AppModule {}

Standalone

Add HotkeysService in the standalone components :

@Component({
  standalone: true,
  imports: [HotkeysDirective],
})
export class AppComponent {}

Now you have two ways to start adding shortcuts to your application:

Hotkeys Directive

<input hotkeys="meta.a" (hotkey)="handleHotkey($event)" />

Hotkeys take care of transforming keys from macOS to Linux and Windows and vice-versa.

Additionally, the directive accepts three more inputs:

  • hotkeysGroup - define the group name.
  • hotkeysDescription - add a description.
  • hotkeysOptions - See Options
  • isSequence - indicate hotkey is a sequence of keys.

For example:

<input hotkeys="meta.n" 
      hotkeysGroup="File" 
      hotkeysDescription="New Document" 
      (hotkey)="handleHotkey($event)"

Example sequence hotkey:

<input hotkeys="g>i" hotkeysGroup="Navigate" hotkeysDescription="Go to Inbox" (hotkey)="handleHotkey($event)"

Hotkeys Service

This is a global service that can be injected anywhere:

import { HotkeysService } from '@ngneat/hotkeys';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  constructor(private hotkeys: HotkeysService) {}

  ngOnInit() {
    this.hotkeys.addShortcut({ keys: 'meta.a' }).subscribe(e => console.log('Hotkey', e));
    this.hotkeys.addSequenceShortcut({ keys: 'g>i' }).subscribe(e => console.log('Hotkey', e));
  }
}

Options

There are additional properties we can provide:

interface Options {
  // The group name
  group: string;
  // hotkey target element (defaults to `document`)
  element: HTMLElement;
  // The type of event (defaults to `keydown`)
  trigger: 'keydown' | 'keyup';
  // Allow input, textarea and select as key event sources (defaults to []).
  // It can be 'INPUT', 'TEXTAREA', 'SELECT' or 'CONTENTEDITABLE'.
  allowIn: AllowInElement[];
  // hotkey description
  description: string;
  // Included in the shortcut list to be display in the help dialog (defaults to `true`)
  showInHelpMenu: boolean;
  // Whether to prevent the default behavior of the event. (defaults to `true`)
  preventDefault: boolean;
}

onShortcut

Listen to any registered hotkey. For example:

const unsubscribe = this.hotkeys.onShortcut((event, key, target) => console.log('callback', key));

// When you're done listening, unsubscribe
unsubscribe();

registerHelpModal

Display a help dialog listing all visible hotkeys:

import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
import { HotkeysHelpComponent, HotkeysService } from '@ngneat/hotkeys';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent implements AfterViewInit {
  constructor(private hotkeys: HotkeysService, private dialog: NgbModal) {}

  ngAfterViewInit() {
    this.hotkeys.registerHelpModal(() => {
      const ref = this.modalService.open(HotkeysHelpComponent, { size: 'lg' });
      ref.componentInstance.title = 'Custom Shortcuts Title';
      ref.componentInstance.dismiss.subscribe(() => ref.close());
    });
  }
}

It accepts a second input that allows defining the hotkey that should open the dialog. The default shortcut is Shift + ?. Here's how HotkeysHelpComponent looks like:

<p align="center">
 <img width="50%" height="50%" src="./help_screenshot.png">
</p>

You can also provide a custom component. To help you with that, the service exposes the getShortcuts method.

removeShortcuts

Remove previously registered shortcuts.

// Remove a single shortcut
this.hotkeys.removeShortcuts('meta.a');
// Remove several shortcuts
this.hotkeys.removeShortcuts(['meta.1', 'meta.2']);

setSequenceDebounce

Set the number of milliseconds to debounce a sequence of keys

this.hotkeys.setSequenceDebounce(500);

Hotkeys Shortcut Pipe

The hotkeysShortcut formats the shortcuts when presenting them in a custom help screen:

<div class="help-dialog-shortcut-key">
  <kbd [innerHTML]="hotkey.keys | hotkeysShortcut"></kbd>
</div>

The pipe accepts and additional parameter the way key combinations are separated. By default, the separator is +. In the following example, a - is used as separator.

<div class="help-dialog-shortcut-key">
  <kbd [innerHTML]="hotkey.keys | hotkeysShortcut: '-'"></kbd>
</div>

Allowing hotkeys in form elements

By default, the library prevents hotkey callbacks from firing when their event originates from an input, select, or textarea element or any elements that are contenteditable. To enable hotkeys in these elements, specify them in the allowIn parameter:

import { HotkeysService } from '@ngneat/hotkeys';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  constructor(private hotkeys: HotkeysService) {}

  ngOnInit() {
    this.hotkeys
      .addShortcut({ keys: 'meta.a', allowIn: ['INPUT', 'SELECT', 'TEXTAREA', 'CONTENTEDITABLE'] })
      .subscribe(e => console.log('Hotkey', e));
  }
}

It's possible to enable them in the template as well:

<input hotkeys="meta.n" 
      hotkeysGroup="File" 
      hotkeysDescription="New Document" 
      hotkeysOptions="{allowIn: ['INPUT','SELECT', 'TEXTAREA', 'CONTENTEDITABLE']}" 
      (hotkey)="handleHotkey($event)"

That's all for now! Make sure to check out the playground inside the src folder.

FAQ

Can I define duplicated hotkeys?

No. It's not possible to define a hotkey multiple times. Each hotkey has a description and a group, so it doesn't make sense assigning a hotkey to different actions.

Why am I not receiving any event?

If you've added a hotkey to a particular element of your DOM, make sure it's focusable. Otherwise, hotkeys cannot capture any keyboard event.

How to ...

Listening to the same shortcut in different places.

You can always use onShortcut. This method allows listening to all registered hotkeys without affecting the original definition.

Contributors ✨

Thanks goes to these wonderful people (emoji key):


Carlos Vilacha

πŸ’» πŸ–‹ πŸ“–

Netanel Basal

πŸ“ πŸ’» πŸ“– πŸ€”

Álvaro Martínez

πŸ’» πŸ“–

This project follows the all-contributors specification. Contributions of any kind welcome!

hotkeys's People

Contributors

alvaromartmart avatar kiesman99 avatar netanelbasal avatar pilpin avatar rars avatar roennibus avatar solkaz avatar soyuka avatar vilacha avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

hotkeys's Issues

Angular v16 Support

I'm submitting a...

I want to help upgrade this library to support the latest version of angular.

Current behavior

Docs mention proper support till 14

Expected behavior

Should support 16 and beyond also.

What is the motivation / use case for changing the behavior?

Support for the latest version of angular.

Environment

Angular version: 16.2.0

For Tooling issues:

  • Node version: v18.16.0
  • Platform: Mac

Example code?

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report  
[ ] Performance issue
[ ] Feature request
[x] Documentation issue or request
[ ] Support request
[ ] Other... Please describe:

Current behavior

I followed the readme, and can't get this thing to work.

What I did:

  1. Installed the package
  2. Imported it in app.module
  3. Used the directive like so:
<input hotkeys="meta.a" (hotkey)="handleHotkey($event)" />
  1. TS file:
 handleHotkey(event: any) {
    console.log(event);
  }
  1. Nothing

Am I misunderstanding something?
Also, I'm not that familiar with the hotkey annotation, it would be good with a section in the docs explaining the different combinations. What's the difference (if any) between meta.a and meta+a?

Expected behavior

An event

Minimal reproduction of the problem with instructions

See above.

What is the motivation / use case for changing the behavior?

Environment


Angular version: ^16.1.0


Browser:
- [x] Chrome (desktop) version 115.0.5790.173
- [ ] Chrome (Android) version XX
- [ ] Chrome (iOS) version XX
- [ ] Firefox version XX
- [ ] Safari (desktop) version XX
- [ ] Safari (iOS) version XX
- [ ] IE version XX
- [ ] Edge version XX
 
For Tooling issues:
- Node version: v16.17.1  
- Platform:  Widows 

Others:

Misleading return value when registering duplicate value

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[x] Bug report  
[ ] Performance issue
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request
[ ] Other... Please describe:

Current behavior

If a duplicate shortcut is registered, the library logs an error to the console and resolves with an observable holding null (https://github.com/ngneat/hotkeys/blob/master/projects/ngneat/hotkeys/src/lib/hotkeys.service.ts#L160). This leads to unexpected behaviour, because the callback to execute when the shortcut has been pressed, is still executed but the event is null. This becomes especially confusing, because of the of(null) the callback is immediately executed, even if the key has not been pressed.

Expected behavior

The observable should error, if an error occurs, thus not executing the callback.

Minimal reproduction of the problem with instructions

Just register a callback twice.

Environment


Angular version: 15.x

Browser:
- [x] Chrome (desktop) version XX
- [ ] Chrome (Android) version XX
- [ ] Chrome (iOS) version XX
- [ ] Firefox version XX
- [ ] Safari (desktop) version XX
- [ ] Safari (iOS) version XX
- [ ] IE version XX
- [ ] Edge version XX

Pressing hotkeys removed by removeShortcuts() may cause TypeError

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[x] Bug report  
[ ] Performance issue
[ ] Feature request
[x] Documentation issue or request
[ ] Support request
[ ] Other... Please describe:

Current behavior

Pressing the hotkey removed by removeShortcuts() may cause TypeError.

Assume that a user presses the hotkey which is already removed by removeShortcuts().

example 1:

    ngOnInit(): void {
        const subscription = this.hotkeys.addShortcut({keys: 'shift.a'}).subscribe((e) => {console.log('e;',e)});
        subscription.unsubscribe();
        this.hotkeys.removeShortcuts('shift.a');
    }

This works fine. Pressing shift.a does nothing as expected.

example 2:

  ngOnInit(): void {
    const subscription = this.hotkeys.addShortcut({keys: 'shift.a'}).subscribe((e) => {console.log('e;',e)});
    this.hotkeys.removeShortcuts('shift.a');
  }

In this case, pressing shift.a causes ERROR TypeError: Cannot read property 'allowIn' of undefined
on

const excludedTargets = this.getExcludedTargets(hotkey.allowIn || []);
.

It seems that unsubscribing addShortcut()'s subscription disposes Angular EventManager's eventListener, but removeShortcuts() does not.

Expected behavior

#6
#9

Reading the original issue & PR, I could not find whether the current behavior is by design or not.

If it's not by design, removeShortcuts() should dispose EventManager's eventListener.
If it's by design, adding the explanation of this behavior to the docs might be helpful.

Minimal reproduction of the problem with instructions

https://github.com/ebichan38/hotkeys-unsubscribe

unsubscribe.component for example 1, and no-unsubscribe.component is for example 2.

What is the motivation / use case for changing the behavior?

removeShortcuts() might not work properly.

Environment


Angular CLI: 12.1.1


Browser:
- [x] Chrome (desktop) version XX
- [ ] Chrome (Android) version XX
- [ ] Chrome (iOS) version XX
- [ ] Firefox version XX
- [ ] Safari (desktop) version XX
- [ ] Safari (iOS) version XX
- [ ] IE version XX
- [ ] Edge version XX

Sequence shortcuts stop working after being removed and (re-)added

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[X] Bug report
[ ] Performance issue
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request
[ ] Other... Please describe:

Current behavior

Sequence shortcuts stop working after adding, removing and re-adding them.

Expected behavior

Like normal shortcuts, sequence shortcuts can be arbitrarily added and removed with the expectation that active shortcuts are responding to user input.

Minimal reproduction of the problem with instructions


service.addSequenceShortcut({ keys: 'g>h' })
service.removeShortcuts('g>h');
service.addSequenceShortcut({ keys: 'g>j' }).subscribe(e => console.log(e));

Nothing is logged after pressing G and J.

Environment


Angular version: 13.3.6

Browser:
- [X] Chrome (desktop) version 102
- [ ] Chrome (Android) version XX
- [ ] Chrome (iOS) version XX
- [X] Firefox version 101
- [ ] Safari (desktop) version XX
- [ ] Safari (iOS) version XX
- [ ] IE version XX
- [ ] Edge version XX
 

How to define a hotkey which contains '.' key

How to define a hotkey which contains '.' key

ngneat/[email protected]


[ ] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report  
[ ] Performance issue
[x] Feature request
[x] Documentation issue or request
[ ] Support request
[ ] Other... Please describe:

Current behavior


hotkeys.addShortcut({keys: 'alt..'})  // how to specify hotkey of alt + .

Expected behavior

Hotkey Combo = alt + .

Minimal reproduction of the problem with instructions

Does nothing and can't seem to find a way to do it out of the box.


hotkeys.addShortcut({keys: 'alt..'});

What is the motivation / use case for changing the behavior?

Would be nice to include '.' character in hotkey combination.

Environment


Angular version: 9.1.7
Latest Version of Angular Untested.

Browser:
- [x] Chrome (desktop) version 84.0.4147.105
- [ ] Chrome (Android) version XX
- [ ] Chrome (iOS) version XX
- [ ] Firefox version XX
- [ ] Safari (desktop) version XX
- [ ] Safari (iOS) version XX
- [ ] IE version XX
- [x] Edge version 84.0.522.49
 
For Tooling issues:
- Node version: 10.16.0
- Platform:  Windows

Others:
N/A

Removing / un-registering hotkeys

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report  
[ ] Performance issue
[x] Feature request
[ ] Documentation issue or request
[ ] Support request
[ ] Other... Please describe:

Current behavior

Hotkeys can be added programatically using HotkeyService.addShortcut, but they can't be un-registered.

Expected behavior

A HotkeyService.removeShortcut allowing to delete shortcuts would be nice.

Minimal reproduction of the problem with instructions

What is the motivation / use case for changing the behavior?

I'm using the library to implement a functionality where the users can assign hotkeys to specific actions. This is done through a custom service that keeps track of keyboard assignments, so I need a way to un-register hotkeys.

Environment


Angular version: X.Y.Z


Browser:
- [ ] Chrome (desktop) version XX
- [ ] Chrome (Android) version XX
- [ ] Chrome (iOS) version XX
- [ ] Firefox version XX
- [ ] Safari (desktop) version XX
- [ ] Safari (iOS) version XX
- [ ] IE version XX
- [ ] Edge version XX
 
For Tooling issues:
- Node version: XX  
- Platform:  

Others:

Hotkeys doesn't work when the focus is in iframe

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[X ] Bug report  
[ ] Performance issue
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request
[ ] Other... Please describe:

Current behavior

When I have focus into an iframe, hotkeys stop to work

Expected behavior

Hotkeys continue to work

Minimal reproduction of the problem with instructions

Create a page with an iframe and configure 1 hotkey
take focus to the iframe
press hotkey configured

What is the motivation / use case for changing the behavior?

Environment


Angular version: 14.2.11 


Browser:
- [x] Chrome (desktop) version  119.0.6045.124
- [ ] Chrome (Android) version XX
- [ ] Chrome (iOS) version XX
- [ ] Firefox version XX
- [ ] Safari (desktop) version XX
- [ ] Safari (iOS) version XX
- [ ] IE version XX
- [ ] Edge version XX
 
For Tooling issues:
- Node version:  
- Platform:  Windows 

Others:

Accessibility issue for some key identifier names

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report  
[ ] Performance issue
[ ] Feature request
[X] Documentation issue or request
[X] Support request
[ ] Other... Please describe:

Current behavior

All current examples demonstrate key bindings (including screenshots) relative to MacOS key-bindings.

Expected behavior

Make README.md/documentation more accessible by providing examples from other platforms as well. The README.md although mentions:

Hotkeys take care of transforming keys from macOS to Linux and Windows and vice-versa.

it is not immediately clear (at least to me), that should one be using exclusive Mac key-bindings that internally translate that to the host platform, or that providing strings like super, alt works equally well. If it is so, then I believe the API should not transform internally to ease code maintainability, but rather be explicit via API documentation and implement the same platform specific bindings via the API thereby easing the cognitive load on the end-developer.

Minimal reproduction of the problem with instructions

What is the motivation / use case for changing the behavior?

Not many developers have knowledge about Mac, let alone use it. A sizeable portion of the developer community still prefer using Windows. If dual-boot isn't affordable to use a Linux distro, then Windows Subsystem for Linux (WSL2) is preferred by attaching an X-Windows environment via Remote Desktop Protocol.

Alternatively, there exists Linux/BSD users, who neither know what meta nor Windows key is. They are comfortable using the term super key.

Environment


Angular version: 14.1.2


Browser:
- [ ] Chrome (desktop) version XX
- [ ] Chrome (Android) version XX
- [ ] Chrome (iOS) version XX
- [ ] Firefox version XX
- [ ] Safari (desktop) version XX
- [ ] Safari (iOS) version XX
- [ ] IE version XX
- [ ] Edge version XX
- [X] Immaterial to this context
 
For Tooling issues:
- Node version: XX  
- Platform:  

Others:

Version 1.4.0 with Angular >=16 compatibility

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report  
[ ] Performance issue
[ ] Feature request
[ x ] Documentation issue or request
[ x ] Support request
[ ] Other... Please describe:

Current behavior

Firstly thanks for the library. I have a small question regarding the releases.
The readme mentions version 1.4.0 which is supposed to support Angular >=16 and which probably still uses @angular/material. Unfortunately I couldn't find it anywhere, is there a release planned for this or is it available somewhere and am I missing it?

Upgrade dependencies to Angular 10

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report  
[ ] Performance issue
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request
[x] Other... Please describe: Upgrade dependencies to Angular 10

Current behavior

When trying:

ng update @angular/core @angular/cli

We get:

Package "@ngneat/hotkeys" has an incompatible peer dependency to "@angular/core" (requires "^8.0.0" (extended), would install "10.0.2").
Package "@ngneat/hotkeys" has an incompatible peer dependency to "@angular/common" (requires "^8.0.0" (extended), would install "10.0.2").

Expected behavior

No warnings.

Minimal reproduction of the problem with instructions

What is the motivation / use case for changing the behavior?

dependencies, devDependencies and peerDependencies should be aligned with the latest Angular version.

Environment


Angular CLI: 9.1.5
Node: 12.13.1
OS: darwin x64

Angular: 9.1.4
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router
Ivy Workspace: Yes

Package                            Version
------------------------------------------------------------
@angular-devkit/architect          0.901.5
@angular-devkit/build-angular      0.901.5
@angular-devkit/build-ng-packagr   0.901.5
@angular-devkit/build-optimizer    0.901.5
@angular-devkit/build-webpack      0.901.5
@angular-devkit/core               9.1.5
@angular-devkit/schematics         9.1.5
@angular/cdk                       9.2.3
@angular/cli                       9.1.5
@angular/material                  9.2.3
@angular/material-moment-adapter   9.2.4
@ngtools/webpack                   9.1.5
@schematics/angular                9.1.5
@schematics/update                 0.901.5
ng-packagr                         9.1.3
rxjs                               6.5.5
typescript                         3.8.3
webpack                            4.42.0

Support sequential hot keys

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report  
[ ] Performance issue
[X] Feature request
[ ] Documentation issue or request
[ ] Support request
[ ] Other... Please describe:

Expected behavior

Handle sequential hot keys like Gmail. For example you hit 'g' then 'i' and it goes to inbox. Something like '>' could be used as an indicator instead of '.', when splitting the string.

The alt.p shortcut does not work on MacOs

I just added this library to manage more easily my different shortcuts in my application. But I notice that the shortcuts alt + p for example or alt + s do not work. While it works using hotkeysjs

//It's ok
hotkeys('alt+p', function(event, handler){
  alert('alt+p')
});

//It's not ok
this.hotkeys.addShortcut({ keys: 'alt.p' }).subscribe(e => console.warn('Hotkey', e));
this.hotkeys.addShortcut({ keys: 'alt.s' }).subscribe(e => console.warn('Hotkey', e));
 

Any ideas?
Thanks

Better Icon for Enter / configurable icons in HotkeysHelpComponent

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report  
[ ] Performance issue
[x] Feature request
[ ] Documentation issue or request
[ ] Support request
[ ] Other... Please describe:

Current behavior

The enter icon (⌀) in the HotkeysHelpComponent is not recognized by our users.

Expected behavior

It would be nice if the icon is changed if the Device is not a Apple-Device
or if we can configure the icon
or if it is replaced by just 'enter'

Minimal reproduction of the problem with instructions

open the HotkeysHelpComponent when a shortcut with 'enter' is added.

Environment


Angular version: 14.2.2

Browser:
- [x] Chrome (desktop) version XX
- [ ] Chrome (Android) version XX
- [ ] Chrome (iOS) version XX
- [x] Firefox version XX
- [ ] Safari (desktop) version XX
- [ ] Safari (iOS) version XX
- [ ] IE version XX
- [x] Edge version XX

Others: 
 - [x] Windows

[documentation] HotkeysHelpComponent example using MatDialog cannot be closed using the button

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report  
[ ] Performance issue
[ ] Feature request
[x] Documentation issue or request
[ ] Support request
[ ] Other... Please describe:

Current behavior

I find the current example in the README for the HotkeysHelpComponent a bit misleading. The "close" button in the component emits an event, but it doesn't close the MatDialog that is used in the example to display the component. I think this can be a bit confusing for newcomers.
I can think of two possible workarounds:

  • Improve the example with the necessary steps to close the MatDialog when the dimiss event is fired
  • Optionally injecting the MatDialog into the HotkeysHelpComponent so it supports the example out of the box.
constructor(
    private hotkeysService: HotkeysService,
    @Optional() private _dialog: MatDialog
){
    /* [...] */
    handleDismiss(){
        this._dialog?.close();
        /* [...] */
    }
}

Expected behavior

Minimal reproduction of the problem with instructions

What is the motivation / use case for changing the behavior?

Environment


Angular version: X.Y.Z


Browser:
- [ ] Chrome (desktop) version XX
- [ ] Chrome (Android) version XX
- [ ] Chrome (iOS) version XX
- [ ] Firefox version XX
- [ ] Safari (desktop) version XX
- [ ] Safari (iOS) version XX
- [ ] IE version XX
- [ ] Edge version XX
 
For Tooling issues:
- Node version: XX  
- Platform:  

Others:

Cannot define keyup handlers for hotkeys that have keydown handlers defined.

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report  
[ ] Performance issue
[x] Feature request
[ ] Documentation issue or request
[ ] Support request
[ ] Other... Please describe:

Current behavior

I cannot write the following without getting a warning:

this.hotkeys
      .addShortcut({ keys: 'space' })
      .pipe(untilDestroyed(this))
      .subscribe(()=> this.onSpaceKeyDown());

this.hotkeys
      .addShortcut({ keys: 'space', trigger: 'keyup' })
      .pipe(untilDestroyed(this))
      .subscribe(()=> this.onSpaceKeyUp());

The warning:

Duplicated shortcut

Expected behavior

I should be able to write the above code snippet without getting a warning.

This may be a mis-understanding on my part, as I thought that my scenario shouldn't be considered a duplicate key (while it is referring to the same key, it's for different events). If my assumption isn't correct, then maybe the FAQs need to be updated.

Minimal reproduction of the problem with instructions

https://github.com/solkaz/ngneat-hotkeys-issue/

What is the motivation / use case for changing the behavior?

Being able to define a "keyup" handler for a hotkey that already has a "keydown" handler defined.

Environment


Angular version: X.Y.Z


Browser:
- [ ] Chrome (desktop) version XX
- [ ] Chrome (Android) version XX
- [ ] Chrome (iOS) version XX
- [ ] Firefox version XX
- [ ] Safari (desktop) version XX
- [ ] Safari (iOS) version XX
- [ ] IE version XX
- [ ] Edge version XX
 
Others:

N/A

[bug] SHIFT+numeric key shortcuts not working?

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[x] Bug report  
[ ] Performance issue
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request
[ ] Other... Please describe:

Current behavior

Shortcuts such as shift+1 don't seem to work.

Expected behavior

shift + [numeric key] shortcuts should work.

Minimal reproduction of the problem with instructions

I've put up an example on Stackblitz to illustrate the issue.
https://stackblitz.com/edit/ngneathotkeysdemo?embed=1&file=src/app/app.component.html

What is the motivation / use case for changing the behavior?

Environment


Angular version: X.Y.Z


Browser:
- [ ] Chrome (desktop) version XX
- [ ] Chrome (Android) version XX
- [ ] Chrome (iOS) version XX
- [ ] Firefox version XX
- [ ] Safari (desktop) version XX
- [ ] Safari (iOS) version XX
- [ ] IE version XX
- [ ] Edge version XX
 
For Tooling issues:
- Node version: XX  
- Platform:  

Others:

contenteditable attribute is not handled.

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report  
[ ] Performance issue
[X] Feature request
[ ] Documentation issue or request
[ ] Support request
[ ] Other... Please describe:

Current behavior

Currently, By default, the library prevents hotkey callbacks from firing when their event originates from an input, select, or textarea element. It should also consider contenteditable attribute

Expected behavior

  • Hotkeys callback should not be triggered if event originates from contenteditable element.

Minimal reproduction of the problem with instructions

What is the motivation / use case for changing the behavior?

Environment


Angular version: X.Y.Z


Browser:
- [ ] Chrome (desktop) version XX
- [ ] Chrome (Android) version XX
- [ ] Chrome (iOS) version XX
- [ ] Firefox version XX
- [ ] Safari (desktop) version XX
- [ ] Safari (iOS) version XX
- [ ] IE version XX
- [ ] Edge version XX
 
For Tooling issues:
- Node version: XX  
- Platform:  

Others:

Multi-language issues: check key code, instead of value

[ ] Regression (a behavior that used to work and stopped working in a new release)
[X] Bug report  
[ ] Performance issue
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request
[ ] Other... Please describe:

Current behavior

If you have multiple languages in your system, like I do, this module will work exaclty for language you're defined: shift.meta.p will work for English, but not for russian shift.meta.Π·, which has same key code, but different key value.

Expected behavior

Add ability to check key code, not just key value.

Minimal reproduction of the problem with instructions

  • Add some localization to your system with letters, different than English;
  • Create shortcut for English keys;
  • Switch localization and try to use this hotkey.

Can't hotkey a period (dot)

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[X] Bug report  
[ ] Performance issue
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request
[ ] Other... Please describe:

Current behavior

Can't hotkey a period (dot).

Expected behavior

To be able to hotkey a period

Minimal reproduction of the problem with instructions

Attempted:

{ keys: 'control.\.', description: 'Go To Settings' }
{ keys: 'control..', description: 'Go To Settings' }
{ keys: 'control.&#46;', description: 'Go To Settings' }
{ keys: 'control.46;', description: 'Go To Settings' }

What is the motivation / use case for changing the behavior?

Using this specific hotkey to go to settings

Environment


Angular version: 13.x


Browser:
- [X] Chrome (desktop) version XX
- [ ] Chrome (Android) version XX
- [ ] Chrome (iOS) version XX
- [ ] Firefox version XX
- [ ] Safari (desktop) version XX
- [ ] Safari (iOS) version XX
- [ ] IE version XX
- [ ] Edge version XX
 

Setting [hotkeys] on a button only activates hotkey if focused on the button

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[X] Bug report  
[ ] Performance issue
[X] Feature request
[ ] Documentation issue or request
[X] Support request
[ ] Other... Please describe:

Current behavior

<button
	(click)="console.log('click')"
	hotkeys="meta.shift.5"
	(hotkey)="console.log('hotkey')"
>
	CLICK ME
</button>

I have a form with a bunch of buttons, much like the one above. Long as the form is open, I want the hotkey defined on each button to perform the action of the button. At first, I didn't have the (hotkey) handler, since I assumed it would invoke the (click) handler, but then I looked at the docs and added the (hotkey) handler, but it still didn't work.

The culprit is this piece of code setting the element option without being allowed to override it. I would want to set it as "document.documentElement", for example.

Expected behavior

When I set a hotkey on an element, I want to be able to have the hotkey work without having the element be focused.
Perhaps it can be an input flag of the directive, changing the ...hotkeys to happen after setting element to be the host element.

Minimal reproduction of the problem with instructions

See example in "Current Behavior"

What is the motivation / use case for changing the behavior?

I want to easily set hotkeys for buttons for the duration the button lives. Moreover, I want to not have to use HotkeysService directly to force the element to be document.

Environment


Angular version: 10.0.0
@ngneat/hotkeys version: 1.1.1



Browser:
- [X] Chrome (desktop) version 75.0.3770.100
- [ ] Chrome (Android) version XX
- [ ] Chrome (iOS) version XX
- [ ] Firefox version XX
- [ ] Safari (desktop) version XX
- [ ] Safari (iOS) version XX
- [ ] IE version XX
- [ ] Edge version XX
 
For Tooling issues:
- Node version: XX  
- Platform:  

Others:

Dependency free help modal?

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report  
[ ] Performance issue
[ ] Feature request?
[ ] Documentation issue or request?
[ ] Support request
[x] Other: Question to document or support

Current behavior

The documentation for the help modal relies on MatDialog dependency:

this.hotkeys.registerHelpModal(() => {
  const ref = this.dialog.open(HotkeysHelpComponent, { width: '500px' });
  ref.componentInstance.dismiss.subscribe(() => ref.close());
});

Expected behavior

It would be nice if it was possible to have a help modal without the need to install extra dependencies

Minimal reproduction of the problem with instructions

What is the motivation / use case for changing the behavior?

Environment


Angular version: X.Y.Z


Browser:
- [ ] Chrome (desktop) version XX
- [ ] Chrome (Android) version XX
- [ ] Chrome (iOS) version XX
- [ ] Firefox version XX
- [ ] Safari (desktop) version XX
- [ ] Safari (iOS) version XX
- [ ] IE version XX
- [ ] Edge version XX
 
For Tooling issues:
- Node version: XX  
- Platform:  

Others:

Pause hotkey handling

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report  
[ ] Performance issue
[X] Feature request
[ ] Documentation issue or request
[ ] Support request
[ ] Other... Please describe:

Current behavior

It is impossible (?) to temporarily disable the handling of hotkeys.

Expected behavior

Run hotkeysService.pause() to temporarily interrupt the handling of hotkeys, and .unpause() to resume handling.

What is the motivation / use case for changing the behavior?

When I display modals in my application, I want to prevent any hotkeys until they are dismissed.
It's a simple change, so I'm happy to put together a PR if the functionality would be welcome.

Idea on allowing user to change hotkey.

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report  
[ ] Performance issue
[x] Feature request
[ ] Documentation issue or request
[ ] Support request
[ ] Other... Please describe:

Current behavior

Currently when hotkey is defined by programmer, there is no way for user to override the choice of hotkey.

Expected behavior

User should be able to override hotkey configuration especially on key event.

Minimal reproduction of the problem with instructions

What is the motivation / use case for changing the behavior?

While it is possible to add extra logic to unsubscribe certain hotkey and rebind it with different key, it would be great if user can change them on helpModal.

There is quite abit of code / ui to consider. Please close this if it does not align with the interest of this project.

Environment


Angular version: X.Y.Z


Browser:
- [x] Chrome (desktop) version XX
- [ ] Chrome (Android) version XX
- [ ] Chrome (iOS) version XX
- [ ] Firefox version XX
- [ ] Safari (desktop) version XX
- [ ] Safari (iOS) version XX
- [ ] IE version XX
- [ ] Edge version XX
 
For Tooling issues:
- Node version: XX  
- Platform:  

Others:

Add disallowIn config for web components and ShadowDOM

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report  
[ ] Performance issue
[x] Feature request
[ ] Documentation issue or request
[ ] Support request
[ ] Other... Please describe:

Current behavior

The library prevents hotkey callbacks from firing when their event originates from an input, select, or textarea element or any elements that are contenteditable. It is not possible to specify additional elements for which the hotkey callbacks are prevented.

Expected behavior

The library offers an additional config for every hotkey called disallowIn (similar to allowIn), where one can specify additional nodeNames that are then checked by the library. If a node is contained in that list, the hotkey will not fire.

What is the motivation / use case for changing the behavior?

We are using hotkeys in combination with custom form elements that are web components with ShadowDOM. For those elements, the triggered events will not contain the native input as an event trigger. Instead (due to shadow DOM) the trigger will be the custom web component itself. The hotkey will thus be triggered. It would be really easy to just add a config with a list of web component names, that should be disallowed.

Environment


Angular version: X.Y.Z


Browser:
- [x] Chrome (desktop) version XX
- [ ] Chrome (Android) version XX
- [ ] Chrome (iOS) version XX
- [ ] Firefox version XX
- [ ] Safari (desktop) version XX
- [ ] Safari (iOS) version XX
- [ ] IE version XX
- [ ] Edge version XX
 
For Tooling issues:
- Node version: 16  
- Platform: Mac

Others:

It would be awesome to bring this change in the v1.2.x

@angular/material hard dep?

Hey, as I was trying to just install this module and tried to use it, it seems it has a hard dep on @angular/material?

ERROR in The target entry-point "@ngneat/hotkeys" has missing dependencies:
 - @angular/material/dialog

imports: [CommonModule, MatDialogModule],

I don't really see why this is necessary (at least in the library code), the example uses it but there's no reason to have this import in the library if that is the only case.

Hotkey is being captured when user if focusing on input element

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[ x ] Bug report  
[ ] Performance issue
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request
[ ] Other... Please describe:

Current behavior

When using trying to enter some key value into element, the key value which coincide with hotkey will not appear and relavent function is triggered.

Expected behavior

Hotkey should not trigger when using typing text.

Minimal reproduction of the problem with instructions

What is the motivation / use case for changing the behavior?

When using hotkeys in the environment where typing value is unavoidable, ie: enter search query.

Environment

Angular version: 9.1.0

Browser:

  • Chrome (desktop) version 83
  • Chrome (Android) version XX
  • Chrome (iOS) version XX
  • Firefox version XX
  • Safari (desktop) version XX
  • Safari (iOS) version XX
  • IE version XX
  • Edge version XX

For Tooling issues:

  • Node version: 12.8.1
  • Platform: Linux

Error: Module not found: Error: Can't resolve '@ng-bootstrap/ng-bootstrap'

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[x] Bug report  
[ ] Performance issue
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request
[ ] Other... Please describe:

Current behavior

Missing dependency on build.

./node_modules/@ngneat/hotkeys/fesm2022/ngneat-hotkeys.mjs:8:0-49 - Error: Module not found: Error: Can't resolve '@ng-bootstrap/ng-bootstrap' in '**\@ngneat\hotkeys\fesm2022'

Error: node_modules/@ngneat/hotkeys/lib/hotkeys-help/hotkeys-help.component.d.ts:3:32 - error TS2307: Cannot find module '@ng-bootstrap/ng-bootstrap' or its corresponding type declarations.

3 import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
                                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expected behavior

Should be able to follow instructions in README.md and get a working installation. No mention of dependencies that need to be manually installed.

Minimal reproduction of the problem with instructions

  1. Create a brand new Angular application
  2. Follow instructions in README.md (npm install @ngneat/hotkeys, add to app module)
  3. Run the app (ng serve)
  4. Above error occurs.

Additional observations:

  • It appears this PR added @ng-bootstrap/ng-bootstrap, @popperjs/core, and bootstrap to the test app. Without them, this package does not work. Shouldn't these be included in @ngneat/hotkeys's package.json as at least peerDependencies?
  • The PR also adds a reference for node_modules/bootstrap/scss/bootstrap.scss in angular.json's styles array.
  • The README should indicate how to provide these dependencies if not provided by the package.

Environment


Angular version: 16.2.12


Browser:
n/a
 
For Tooling issues:
- Node version: v18.17.1  
- Platform: Windows  

Others:

Failed to install in Angular 13

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[X] Bug report  
[ ] Performance issue
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request
[ ] Other... Please describe:

Current behavior

When running npm install @ngneat/hotkeys@^1.2.0 in Angular 13 project I get an error

Could not resolve dependency:
npm ERR! peer tslib@"^1.10.0" from @ngneat/[email protected]

Expected behavior

hotkeys version 1.2.0 should install without any issues (claims Angular 13 compatibility).

Minimal reproduction of the problem with instructions

Typescript 3.9 is used since Angular 10 which requires tslib 2.x

What is the motivation / use case for changing the behavior?

I need hotkey support in my Angular 13 project

Environment

Angular 13.3.0

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.