Skip to content

Commit 8811ff9

Browse files
committed
using programatic selection/styling (keyboard support)
1 parent c861a78 commit 8811ff9

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

addon/components/x-tree-node.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,29 @@
11
import Component from '@ember/component';
2+
import { computed } from '@ember/object';
23
import layout from '../templates/components/x-tree-node';
34

45
export default Component.extend({
56
layout,
6-
classNameBindings: ['model.isSelected:tree-highlight'],
7+
classNameBindings: ['model.isSelected:tree-highlight', 'isChosen:tree-chosen'],
8+
9+
isChosen: computed('model.id', 'chosenId', function() {
10+
let chosenId = this.get('chosenId');
11+
return chosenId ? this.get('model.id') === chosenId : false;
12+
}),
713

814
click() {
915
this.attrs.select(this.get('model'));
1016
},
11-
1217
mouseEnter() {
18+
this.set('model.isSelected', true);
1319
let hover = this.get('hover');
1420
if (hover) {
1521
hover(this.get('model'));
1622
}
1723
},
24+
mouseLeave() {
25+
this.set('model.isSelected', false);
26+
},
1827

1928
actions: {
2029
toggleCheck() {
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
{{x-tree-node model=model select=select hover=hover}}
1+
{{x-tree-node model=model select=select hover=hover chosenId=chosenId}}
22

33
{{#if model.isExpanded}}
4-
{{x-tree model=model.children select=select hover=hover}}
4+
{{x-tree model=model.children select=select hover=hover chosenId=chosenId}}
55
{{/if}}

addon/templates/components/x-tree.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
{{#if hasBlock}}
44
{{yield child}}
55
{{else}}
6-
{{x-tree-children model=child select=select hover=hover}}
6+
{{x-tree-children model=child select=select hover=hover chosenId=chosenId}}
77
{{/if}}
88
{{/if}}
99
{{/each}}

0 commit comments

Comments
 (0)