Skip to content

Commit

Permalink
Merge pull request #803 from qonto/use-keyboard-event-key
Browse files Browse the repository at this point in the history
feat: use KeyboardEvent.key instead of KeyboardEvent.keyCode
  • Loading branch information
AntoineMoues committed Apr 29, 2024
2 parents 2ffcfb1 + 6ff26f6 commit ed16c4a
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions ember-amount-input/src/components/amount-input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import Component from '@glimmer/component';
import { action } from '@ember/object';
import './amount-input.css';

const KEY_CODE_E = 69;
const KEY_CODE_FULLSTOP = 190;
const KEY_CODE_COMMA = 188;
const KEY_E = 'e';
const KEY_FULLSTOP = '.';
const KEY_COMMA = ',';

export interface AmountInputArgs {
/**
Expand Down Expand Up @@ -130,12 +130,13 @@ export default class AmountInput extends Component<AmountInputSignature> {

@action
onKeyDown(event: KeyboardEvent): boolean {
if (event.keyCode === KEY_CODE_E) {
const pressedKey = event.key.toLowerCase();
if (pressedKey === KEY_E) {
event.preventDefault();
return false;
} else if (
this.numberOfDecimal === 0 &&
[KEY_CODE_FULLSTOP, KEY_CODE_COMMA].includes(event.keyCode)
[KEY_FULLSTOP, KEY_COMMA].includes(pressedKey)
) {
event.preventDefault();
return false;
Expand Down

0 comments on commit ed16c4a

Please sign in to comment.