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
- Use autoNumeric version
v4.10.4
- In both Firefox 123 and Chrome 122
- On the Arch Linux operating system
- Then instantiate the autoNumeric object with the following options:
new AutoNumeric(domElement, { isCancellable: false, selectOnFocus: false });
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:
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 🙂