changhuixu / ngx-digit-only

An Angular directive to only allow [0-9] in the input box when typing, pasting or drag/dropping.
https://changhuixu.github.io/ngx-digit-only/
MIT License
161 stars 70 forks source link

Does not support hotkeys in another language #35

Closed bondarvladislave closed 4 years ago

bondarvladislave commented 4 years ago

Does not support hotkeys when the keyboard is in another language

(e.key === 'a' && e.ctrlKey) || // Allow: Ctrl+A
(e.key === 'c' && e.ctrlKey) || // Allow: Ctrl+C
(e.key === 'v' && e.ctrlKey) || // Allow: Ctrl+V

I think the best way is to replace it with

(e.code === 'KeyA' && e.ctrlKey) || // Allow: Ctrl+A
(e.code === 'KeyC' && e.ctrlKey) || // Allow: Ctrl+C
(e.code === 'KeyV' && e.ctrlKey) || // Allow: Ctrl+V
changhuixu commented 4 years ago

Hi @bondarvladislave

Thanks for pointing it out. https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/code https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key

I will work on it soon.

changhuixu commented 4 years ago

@bondarvladislave

After I update the code, it doesn't work for IE... So I have to pause this update a little bit.

quinkk commented 4 years ago

u no need to replace it just add OR condition

        (e.key === 'a' && e.ctrlKey === true) || // Allow: Ctrl+A
        (e.key === 'c' && e.ctrlKey === true) || // Allow: Ctrl+C
        (e.key === 'v' && e.ctrlKey === true) || // Allow: Ctrl+V
        (e.key === 'x' && e.ctrlKey === true) || // Allow: Ctrl+X
        (e.key === 'a' && e.metaKey === true) || // Allow: Cmd+A (Mac)
        (e.key === 'c' && e.metaKey === true) || // Allow: Cmd+C (Mac)
        (e.key === 'v' && e.metaKey === true) || // Allow: Cmd+V (Mac)
        (e.key === 'x' && e.metaKey === true) || // Allow: Cmd+X (Mac)
        (e.code === 'KeyA' && e.ctrlKey === true) || // Allow: Ctrl+A
        (e.code === 'KeyC' && e.ctrlKey === true) || // Allow: Ctrl+C
        (e.code === 'KeyV' && e.ctrlKey === true) // Allow: Ctrl+V
changhuixu commented 4 years ago

@quinkk I see, thank you. I will try it out.

changhuixu commented 4 years ago

Hi @bondarvladislave and @quinkk ,

Could you try it out https://digit-only.firebaseapp.com/ to see if the app is working for your language keyboards now? If it works, then I will release this change.

Thanks.

bondarvladislave commented 4 years ago

@changhuixu thanks Now everything works correctly on the Russian keyboard layout And thanks @quinkk for the solution

changhuixu commented 4 years ago

Thank you. I released v2.2.0 just now.