PolymerElements / iron-a11y-keys-behavior

A behavior that enables keybindings for greater a11y
24 stars 41 forks source link

Normalize key code in event.detail #14

Closed shashi closed 8 years ago

shashi commented 9 years ago

In core-a11y-keys the keyboard event was passed through keyboardEventToKey function which was very helpful because one didn't have to memorize or look up key codes. event.detail contained exactly the amount of information required. Can we have it back? (can I make a Pull-request or is there a reason this was removed?)

cdata commented 9 years ago

Can you specify which information is missing?

shashi commented 9 years ago

Hello @cdata sorry for the late response. What I did was:

I added this to the prototype, and then call it from my app under the event handler for "keys-pressed" event.

      keyboardEventToKey: function (event) {
        return {
          shift: event.shiftKey,
          ctrl: event.ctrlKey,
          meta: event.metaKey,
          alt: event.altKey,
          key: normalizedKeyForEvent(event)
        };
      },

Notice that normalizedKeyForEvent is only inside the scope of core-a11y-keys and so adding this to the prototype was necessary.

valdrinkoshi commented 8 years ago

Hi @shashi, this information should be available on the keys-pressed event detail, but is not. The bug is here, where instead of doing var detail = Object.create(keyCombo), we should do something like:

var detail = {
  keyCombo: keyCombo,
  keyboardEvent: keyboardEvent
};

Feel free to do a PR for this, it would be much appreciated :)

valdrinkoshi commented 8 years ago

Update: this information is already available in event.detail, in fact you can access to keyCombo properties, e.g. event.detail.combo, event.detail.key, event.detail.hasModifiers etc..

@shashi is your request to add a public method keyboardEventToKey added to iron-a11y-keys-behavior?

valdrinkoshi commented 8 years ago

Closing as pending response for 22 days & not actionable