datle-dev / yubi

Minimalist typing test
MIT License
0 stars 0 forks source link

Pressing space during typing test after button clicks causing unexpected behavior #16

Closed datle-dev closed 4 months ago

datle-dev commented 4 months ago

Expected Behavior

Pressing space at the completion of a word to move to the next (or in the middle of a word to skip to the next one) should move the cursor to the next word.

Actual Behavior

If you configure the test (timed vs. word mode, timed test duration or word test word count) by pressing a button, then immediately start typing, the test will proceed since the keydown event listener is active in the entire window. However, pressing space will instead repeat the last button press. Sometimes this throws off the cursor position because things aren't being reset correctly.

Steps to Reproduce the Problem

  1. Click any of the config options (timed test duration, word test word count) or an available word list at least once
  2. Begin the typing test
  3. When you press space, the last button pressed will be pressed again, producing undefined and undesired behavior
datle-dev commented 4 months ago

One easy solution is to call event.preventDefault() in the keydown event handler function. This has some implications on accessibility for keyboard-centric use or navigation of the page, but for now it solves the issue.

Another workaround discovered online was to add another event handler that would remove focus (i.e. blur) when a button is focused, which occurs when the button is pressed. For now, I've elected to not implement this, though it's an option to consider if more issues arise regarding this issue.