tleunen / react-number-editor

Custom number editor (text field) react component
MIT License
70 stars 15 forks source link

Add an onKeyDown prop to allow custom shortcuts #16

Closed yoink00 closed 9 years ago

yoink00 commented 9 years ago
yoink00 commented 9 years ago

I'm not sure if this is generally applicable but in my use case it is useful to be able to quickly enter large values using short cuts.

This change will also prevent backspace from going back through history when non in edit mode and the field was doing unexpected things when there were invalid characters in the field. To fix this I've limited the accepted keys in the field.

tleunen commented 9 years ago

I like it, but what does t stand for?

yoink00 commented 9 years ago

It stands for thousands (so you can use either 't' or 'k'). I have to admit the 't' comes from a legacy application I am replacing :-)

tleunen commented 9 years ago

Instead of adding all this logic inside this component, maybe we can add a onKeyDown prop so it will allow developers the possibility to change the value based on the received key event?

yoink00 commented 9 years ago

Sure. That makes sense. I'll tweak the pull request along these lines.

I was thinking of splitting this in two. The k,t and m shortcuts would be removed and implemented using the new onkeydown prop and the key filter to prevent non-numeric characters would stay.

Does that make sense?

tleunen commented 9 years ago

Actually . and , could be allowed as well. But otherwise it makes sense :)

yoink00 commented 9 years ago

Of course :-) On Tue, 29 Sep 2015 at 23:13, Tommy notifications@github.com wrote:

Actually . and , could be allowed as well. But otherwise it makes sense :)

— Reply to this email directly or view it on GitHub https://github.com/tleunen/react-number-editor/pull/16#issuecomment-144206239 .

Thanks,

Stuart

Tel: 07989 301439

yoink00 commented 9 years ago

I didn't add ',' to the list of allowed characters as the way strings being converted to numbers (using a Number cast) doesn't support commas either as thousand separators or decimal points. I think do that we should use something like numeral.js to format and parse the strings.

tleunen commented 9 years ago

Thanks for the work @yoink00 !