ember-native-dom-helpers icon indicating copy to clipboard operation
ember-native-dom-helpers copied to clipboard

Add a `pressKey` helper?

Open leizhao4 opened this issue 8 years ago • 6 comments

How about adding a pressKey helper which fires keydown, keypress and then keyup?

EDIT: Updated helper name.

leizhao4 avatar Mar 22 '17 02:03 leizhao4

@leizhao4 did you notice the example in the README that shows keyEvent ? https://github.com/cibernox/ember-native-dom-helpers#usage

keyEvent('.other-input', 'keyup', 40); // down arrow

pixelhandler avatar Mar 22 '17 14:03 pixelhandler

Actually having a single helper that simulates a full key interation (fires keydown, keyup and keypress in sequence) sounds reasonable, the same way click fires mousedown, focus, mouseup and click in sequence.

I'd call it pressKey tho, but it sounds reasonable.

cibernox avatar Mar 22 '17 14:03 cibernox

I created the under consideration label and added to this issue. To see what other think. I'm personally :+1:, but I don't feel strongly either way.

cibernox avatar Mar 22 '17 14:03 cibernox

Yes that's exactly what I mean. After playing around with keyboard events (in Chrome), it looks more complex than I expected and I think there's plenty of room for a new helper.

The events seems to fire in this sequence:

  1. keydown.
  2. beforeinput - Only for keys which produce a character value.
  3. keypress - Legacy event. Device dependent. Only for keys which produce a character value.
  4. input - Only for keys which have updated the DOM.
  5. keyup.

Sources:

There are also combinations, for example, a Cmd-Shift-4 would fire three keydowns, one beforeinput, one input, and three keyups.

leizhao4 avatar Mar 22 '17 14:03 leizhao4

I'm in favor, though I would rather see pressKey also.

rwjblue avatar Mar 22 '17 16:03 rwjblue

Green light then for someone to implement it.

cibernox avatar Mar 24 '17 09:03 cibernox