Closed masakudamatsu closed 4 years ago
References
The event.keyCode
is deprecated. Use the event.key
instead.
Docs on event.key
: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key
stepValue
as 0.1
keydown
event listener on input field.event.key === "ArrowDown"
, return event.target.value + stepValue
.event.key === "ArrowUp"
, return event.target.value - stepValue
We first need to convert the input value into number. Otherwise, 0.1 will be added as string concatenation.
Simply adding 0.1 will cause the floating number problem.
.toFixed(1)
function.But this implementation will round up the user's input value with more than one decimal places. We need to deal with it.
To deal with input values of 2+ decimal places, we convert the input value into an integer to avoid the floating-point math quirks (e.g. adding 0.1 to 10.2 will return 10.299999....)
.toFixed(4)
to avoid the floating-point math fractional valueNumber()
to remove trailing zeros from (5).toString()
to convert (6) back into stringFor the technique in steps 5-6, see https://stackoverflow.com/a/19623253/11847654
We now work on ArrowDown.
We share the code for steps 4-7 for both ArrowUp and ArrowDown key events
We implement the code for KeyDown event only if the pressed key was ArrowUp or ArrowDown.
Two issues arise
Done with the cursor position bug after pressing the ArrowUp key, by following the solution in https://stackoverflow.com/a/1081114/11847654
But it seems event.preventDefault()
is the only necessary code. I'm not sure why we need the ignoreKey
state and the resetting of the cursor position. Maybe for cross-browser compatibility...
Next up: Deal with the case of an input value with 5+ decimal places
Done with invalid input values when pressing arrow keys.
validateXHeight
function if the input is invalidNow we implement the same for modular-scale boxes.
Done with modular-scale boxes.
handleArrowKey
function into handleArrowKey.js
which is imported into XHeightBox.js
and ModularScaleBox.js
ModularScaleBox.js
, the handleArrowKey
function is called separately for x-height and line-height ratio values.Two problems:
Solutions:
So far it took 6.5 hours
The two problems mentioned above appear to be very hard to solve.
We delegate these problems to issue #209
Why? For wide screen layouts, it's best to adjust the x-height and modular scale values by some interval, say, 0.1.