github.com/DerekStrickland/consul@v1.4.5/ui-v2/app/utils/dom/click-first-anchor.js (about) 1 const clickEvent = function() { 2 return new MouseEvent('click', { 3 bubbles: true, 4 cancelable: true, 5 view: window, 6 }); 7 }; 8 export default function(closest, click = clickEvent) { 9 // TODO: Decide whether we should use `e` for ease 10 // or `target`/`el` 11 return function(e) { 12 // click on row functionality 13 // so if you click the actual row but not a link 14 // find the first link and fire that instead 15 const name = e.target.nodeName.toLowerCase(); 16 switch (name) { 17 case 'input': 18 case 'label': 19 case 'a': 20 case 'button': 21 return; 22 } 23 // TODO: why should this be restricted to a tr 24 // closest should probably be relaced with a finder function 25 const $a = closest('tr', e.target).querySelector('a'); 26 if ($a) { 27 $a.dispatchEvent(click()); 28 } 29 }; 30 }