autoNumeric / autoNumeric

AutoNumeric is a standalone library that provides live as-you-type formatting for international numbers and currencies.

Home Page:https://autonumeric.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add option to not select input when hitting Escape

mpsijm opened this issue · comments

Given that isCancellable: false and selectOnFocus: false:

Current behavior

When I hit Escape, the input value is selected.

Expected behavior

When I hit Escape, the input value should not be selected.

Steps to reproduce the problem

  1. Use autoNumeric version v4.10.4
  2. In both Firefox 123 and Chrome 122
  3. On the Arch Linux operating system
  4. Then instantiate the autoNumeric object with the following options:
new AutoNumeric(domElement, { isCancellable: false, selectOnFocus: false });
  1. Then my computer exploded, for real. If I type some numbers and hit Escape, the input value is selected.

Reproduction example: https://jsfiddle.net/Lxh8aned/

Code exploration

I found this code:

            // ...and lastly we update the caret selection, even if the option `isCancellable` is false
            this.select();
            //TODO Add an option to select either the integer or decimal part with `Esc`

I would expect that the update to the caret selection would at least follow the options that already exist, e.g. selectOnFocus and selectNumberOnly.

I fail to see how selectOnFocus is related to the Escape key allowing to select when hitting the Escape key.
Also, as per the documentation, isCancellable also allow the Esc key to select everything:
2024-03-06_103612_Screenshot

So those options and behaviors are working as expected, and will not change.

However there could be a use case where hitting the Esc key only cancel the changes (or not), and do not select anything.

Yes, it feels like those two options could be separated, thanks for the elaboration 🙂