Skip to content

Commit 1cdc37b

Browse files
committed
Update ListCollection with clickFirstAnchor action
1 parent e3c34b4 commit 1cdc37b

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<EmberNativeScrollable @tagName="ul" @content-size={{_contentSize}} @scroll-left={{_scrollLeft}} @scroll-top={{_scrollTop}} @scrollChange={{action "scrollChange"}} @clientSizeChange={{action "clientSizeChange"}}>
22
<li></li>
33
{{~#each _cells as |cell|~}}
4-
<li style={{{cell.style}}}>{{yield cell.item cell.index }}</li>
4+
<li onclick={{action 'click'}} style={{{cell.style}}}>{{yield cell.item cell.index }}</li>
55
{{~/each~}}
66
</EmberNativeScrollable>

ui-v2/app/components/list-collection/index.js

+5
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,9 @@ export default Component.extend(WithResizing, {
4545
this.updateScrollPosition();
4646
}
4747
},
48+
actions: {
49+
click: function(e) {
50+
return this.dom.clickFirstAnchor(e, 'li');
51+
},
52+
},
4853
});

ui-v2/app/utils/dom/click-first-anchor.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@ const clickEvent = function($el) {
1414
export default function(closest, click = clickEvent) {
1515
// TODO: Decide whether we should use `e` for ease
1616
// or `target`/`el`
17-
return function(e) {
17+
// TODO: currently, using a string stopElement to tell the func
18+
// where to stop looking and currenlty default is 'tr' because
19+
// it's backwards compatible.
20+
// Long-term this func shouldn't default to 'tr'
21+
return function(e, stopElement = 'tr') {
1822
// click on row functionality
1923
// so if you click the actual row but not a link
2024
// find the first link and fire that instead
@@ -26,9 +30,7 @@ export default function(closest, click = clickEvent) {
2630
case 'button':
2731
return;
2832
}
29-
// TODO: why should this be restricted to a tr
30-
// closest should probably be relaced with a finder function
31-
const $a = closest('tr', e.target).querySelector('a');
33+
const $a = closest(stopElement, e.target).querySelector('a');
3234
if ($a) {
3335
click($a);
3436
}

0 commit comments

Comments
 (0)