I'm currently using element.trigger('click') to simulate a regular click, but how could I, using angular simulate a SHIFT-click?
-
Trigger a key down event for the shift, the click event, a key up event for the shiftPaul S.– Paul S.2015-07-02 21:46:21 +00:00Commented Jul 2, 2015 at 21:46
-
element.trigger('click') doesn't actually "click" anything... It executes the click handler Javascript function for the element.Robert Harvey– Robert Harvey2015-07-02 21:46:23 +00:00Commented Jul 2, 2015 at 21:46
-
@PaulS: Note that a real shift-click doesn't require that the element already have the focus.Robert Harvey– Robert Harvey2015-07-02 21:48:02 +00:00Commented Jul 2, 2015 at 21:48
-
related: stackoverflow.com/questions/1165222Robert Harvey– Robert Harvey2015-07-02 21:49:39 +00:00Commented Jul 2, 2015 at 21:49
Add a comment
|
2 Answers
To anyone looking for the answer:
var clickEvent = $.Event('click');
clickEvent.shiftKey = event.shiftKey;
element.trigger(clickEvent);
Thanks to all that responded.
1 Comment
Rahat Ahmed
Just for reference, this uses JQuery so it's not something you can do with just Angular (or vanilla JS).
I know this is old, but if anybody is looking for an updated Angular solution:
const trs: NodeListOf<HTMLTableRowElement> nativeElement.querySelectorAll("tbody > tr");
const ev = new MouseEvent("click", { shiftKey: true });
trs[3].dispatchEvent(ev)
This will shift-click on the third table body row...