@@ -11,7 +11,6 @@ export default Component.extend({
11
11
classNames : [ 'navbar-list-item' ] ,
12
12
classNameBindings : [ 'isDropdown:dropdown' ] ,
13
13
isDropdown : equal ( 'link.type' , 'dropdown' ) ,
14
-
15
14
isDropdownOpen : false ,
16
15
17
16
// because aria-expanded requires a string value instead of a boolean
@@ -22,24 +21,22 @@ export default Component.extend({
22
21
navbar : service ( ) ,
23
22
24
23
actions : {
25
- triggerDropdown ( ) {
24
+ toggleDropdown ( ) {
26
25
this . toggleProperty ( 'isDropdownOpen' ) ;
27
-
26
+
28
27
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
30
29
schedule ( 'afterRender' , this , function ( ) {
31
30
32
31
// move focus to the first item in the dropdown
33
- let dropdownList = this . element . querySelector ( '.navbar-dropdown-list' ) ;
34
32
this . handleFirstElementFocus ( ) ;
35
33
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
41
38
42
- // add event listeners for keyboard events
39
+ //... for certain keypress events
43
40
dropdownList . addEventListener ( 'keydown' , event => {
44
41
45
42
// ESC key should close the dropdown and return focus to the toggle
@@ -65,11 +62,16 @@ export default Component.extend({
65
62
this . set ( 'isDropdownOpen' , false ) ;
66
63
} ,
67
64
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?
69
72
next ( this , function ( ) {
70
73
let subItems = Array . from ( this . element . querySelectorAll ( '.navbar-dropdown-list li' ) ) ;
71
74
let focused = subItems . find ( item => document . activeElement === item . querySelector ( 'a' ) ) ;
72
- console . log ( focused ) ;
73
75
74
76
//if the dropdown isn't focused, close it
75
77
if ( ! focused ) {
@@ -92,7 +94,7 @@ export default Component.extend({
92
94
} ) ;
93
95
} ,
94
96
95
- willDestroy ( ) {
97
+ willDestroyElement ( ) {
96
98
document . removeEventListener ( 'keydown' , this . triggerDropdown ) ;
97
99
document . removeEventListener ( 'click' , this . triggerDropdown ) ;
98
100
}
0 commit comments