PolymerElements / iron-a11y-keys

A basic element implementation of iron-a11y-keys-behavior
19 stars 22 forks source link

Alt modifier keys not working in chrome on mac but works in windows. #31

Open anandanand84 opened 7 years ago

anandanand84 commented 7 years ago

Description

The iron-ally-keys element does not work with alt modifier in chrome,firefox,opera on mac. But works with safari and windows. It can be seen in the demo page. https://elements.polymer-project.org/elements/iron-a11y-keys?view=demo:demo/index.html&active=iron-a11y-keys Navigate to demo page in chrome on mac and press alt+a

Expected outcome

It should display alt+a.

Actual outcome

Nothing is displayed

Live Demo

https://elements.polymer-project.org/elements/iron-a11y-keys?view=demo:demo/index.html&active=iron-a11y-keys

Steps to reproduce

  1. Navigate to https://elements.polymer-project.org/elements/iron-a11y-keys?view=demo:demo/index.html&active=iron-a11y-keys in chrome on mac
  2. press alt+a.

    Browsers Affected

valdrinkoshi commented 7 years ago

alt + a produces a keyboard event which has event.key = 'å'. I'm not sure this can be solved by iron-a11y-keys, as it's clearly a different behavior on what's returned by the event.key.

rshmtud commented 6 years ago

+1

freshp86 commented 4 years ago

@danbeam

alt + a produces a keyboard event which has event.key = 'å'. I'm not sure this can be solved by iron-a11y-keys, as it's clearly a different behavior on what's returned by the event.key.

Actually, the problem is not the fact that a key like "å"is produced. Even if one registers a keyboard shortcut as follows on Mac, it does not trigger at all.

behaviors: [
  Polymer.IronA11yKeysBehavior,
],
keyBindings: {
  'alt+ç': 'onMyShortcut_',
},

Digging through the code, there seems to be an arbitrary limitation in iron-a11y-keys-behavior, at https://github.com/PolymerElements/iron-a11y-keys-behavior/blob/dd98dccceb6db2d8fab9204d0bc45a192911c7f6/iron-a11y-keys-behavior.js#L190-L191, where only alpha-numeric keys are allowed when modifiers are used.

// For combos with modifiers we support only alpha-numeric keys
var keyEvent = normalizedKeyForEvent(event, keyCombo.hasModifiers);

Further following this codepath, it goes into transformKey at https://github.com/PolymerElements/iron-a11y-keys-behavior/blob/dd98dccceb6db2d8fab9204d0bc45a192911c7f6/iron-a11y-keys-behavior.js#L104, which basically converts "ç" to the empty string, therefore causing such shortcuts to never fire.

Is there a good reason for this limitation? If noSpecialChars is always passed as false then shortcuts like Alt+c on Mac work fine, as long as they are registered in the code as alt+ç.

Or at the very least, there should be a way to turn off the noSpecialChars logic from a specific element that uses the IronA11yKeysBehavior.