Skip to content

Improve user experience for input field / keydown event listener #7

@daniel-j-h

Description

@daniel-j-h

Right now we add a keydown event listener, so we can act on the "botton down" event already - which feels more responsive than waiting for the "button up" event. The downside is, we have to re-implement special keys such as backspace and remove the last character from the right.

postcode.addEventListener("keydown", function (e) {
var code;
// We want to fitBounds when the key is down already;
// this means we have to handle special keys such as
// backspace manually and delete the last character.
// Maybe there is a better way, because this e.g.
// doesn't handle text copy & paste or cut events.
if (e.keyCode === 8) { // backspace
code = postcode.value.slice(0, Math.max(0, postcode.value.length - 1));
} else {
var digit = parseInt(e.key, 10);
if (isNaN(digit) || postcode.value.length >= 5) {
return;
}
code = postcode.value.concat(digit);
}

This is pretty hacky, does not work with composite keys (think ctrl+x), and it does not seem to work properly on Firefox for Android.

We should look into improving the user experience around the input field.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions