Folloing the guide http://ift.tt/2iYZN0S. I try to bind event handler for key event for a component but seems it does not work. I do not see an alert when I press a key; however, the doubleClick
event handler can be triggered.
What I want to achive is to use key 1 to select the first radio button.
Updated
The event can only be triggered when the radio button has the focus.
My Question
is there a way to bind the keyboard event with out make particular control in focus?
Code
Component JS,
import Ember from 'ember';
export default Ember.Component.extend({
classNames: ['quiz-control'],
keyUp(e) {
alert(e.keyCode);
},
keyDown(e) {
alert(e.keyCode);
},
keyPress(e) {
alert(e.keyCode);
}
});
Component HTML,
<input name="ans" type="radio" id="op0"/>
<label for="op0">1</label>
<input name="ans" type="radio" id="op1"/>
<label for="op1">2</label>
<input name="ans" type="radio" id="op2"/>
<label for="op2">3</label>
<input name="ans" type="radio" id="op3"/>
<label for="op3">4</label>
Aucun commentaire:
Enregistrer un commentaire