Skip to content

Commit b1cea46

Browse files
MelSumnermansona
authored andcommitted
a little refactor
1 parent 03c86a5 commit b1cea46

File tree

2 files changed

+17
-15
lines changed

2 files changed

+17
-15
lines changed

addon/components/es-navbar/link/component.js

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ export default Component.extend({
1111
classNames: ['navbar-list-item'],
1212
classNameBindings: ['isDropdown:dropdown'],
1313
isDropdown: equal('link.type', 'dropdown'),
14-
1514
isDropdownOpen: false,
1615

1716
// because aria-expanded requires a string value instead of a boolean
@@ -22,24 +21,22 @@ export default Component.extend({
2221
navbar: service(),
2322

2423
actions: {
25-
triggerDropdown() {
24+
toggleDropdown() {
2625
this.toggleProperty('isDropdownOpen');
27-
26+
2827
if (this.isDropdownOpen) {
29-
// once it's open, let's make sure it can do some things
28+
// if it's open, let's make sure it can do some things
3029
schedule('afterRender', this, function() {
3130

3231
// move focus to the first item in the dropdown
33-
let dropdownList = this.element.querySelector('.navbar-dropdown-list');
3432
this.handleFirstElementFocus();
3533

36-
dropdownList.addEventListener('click', event =>{
37-
if (this.isDropdownOpen) {
38-
this.handleBlur();
39-
}
40-
});
34+
// add event listeners
35+
let dropdownList = this.element.querySelector('.navbar-dropdown-list');
36+
37+
//TODO ...for click events outside this dropdown
4138

42-
// add event listeners for keyboard events
39+
//...for certain keypress events
4340
dropdownList.addEventListener('keydown', event => {
4441

4542
// ESC key should close the dropdown and return focus to the toggle
@@ -65,11 +62,16 @@ export default Component.extend({
6562
this.set('isDropdownOpen', false);
6663
},
6764

68-
handleBlur() { //TODO this isn't working, figure out why
65+
openDropdown() { //might not need this
66+
// open the dropdown and set the focus to the first item inside
67+
this.set('isDropdownOpen', true);
68+
this.handleFirstElementFocus();
69+
},
70+
71+
handleBlur() { //TODO is this working?
6972
next(this, function() {
7073
let subItems = Array.from(this.element.querySelectorAll('.navbar-dropdown-list li'));
7174
let focused = subItems.find(item => document.activeElement === item.querySelector('a'));
72-
console.log(focused);
7375

7476
//if the dropdown isn't focused, close it
7577
if (!focused) {
@@ -92,7 +94,7 @@ export default Component.extend({
9294
});
9395
},
9496

95-
willDestroy() {
97+
willDestroyElement() {
9698
document.removeEventListener('keydown', this.triggerDropdown);
9799
document.removeEventListener('click', this.triggerDropdown);
98100
}

addon/components/es-navbar/link/template.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
{{/if}}
99
{{#if (eq link.type "dropdown")}}
1010
<button
11-
{{action "triggerDropdown"}}
11+
onclick={{action "toggleDropdown"}}
1212
class="navbar-list-item-dropdown-toggle"
1313
aria-expanded={{isExpanded}}
1414
>

0 commit comments

Comments
 (0)