@@ -23,35 +23,16 @@ export default Component.extend({
23
23
actions : {
24
24
toggleDropdown ( ) {
25
25
this . toggleProperty ( 'isDropdownOpen' ) ;
26
-
26
+
27
27
if ( this . isDropdownOpen ) {
28
28
// if it's open, let's make sure it can do some things
29
29
schedule ( 'afterRender' , this , function ( ) {
30
30
31
31
// move focus to the first item in the dropdown
32
- this . handleFirstElementFocus ( ) ;
33
-
34
- // add event listeners
35
- let dropdownList = this . element . querySelector ( '.navbar-dropdown-list' ) ;
36
-
37
- //TODO ...for click events outside this dropdown
38
-
39
- //...for certain keypress events
40
- dropdownList . addEventListener ( 'keydown' , event => {
41
-
42
- // ESC key should close the dropdown and return focus to the toggle
43
- if ( event . keyCode === 27 && this . isDropdownOpen ) {
44
- this . closeDropdown ( ) ;
45
- this . returnFocus ( ) ;
32
+ this . processFirstElementFocus ( ) ;
33
+ this . processKeyPress ( ) ;
46
34
47
- // if focus leaves the open dropdown via keypress, close it (without trying to otherwise control focus)
48
- } else if ( this . isDropdownOpen ) {
49
- this . handleBlur ( ) ;
50
35
51
- } else {
52
- return ;
53
- }
54
- } ) ;
55
36
} ) ;
56
37
}
57
38
}
@@ -65,10 +46,10 @@ export default Component.extend({
65
46
openDropdown ( ) { //might not need this
66
47
// open the dropdown and set the focus to the first item inside
67
48
this . set ( 'isDropdownOpen' , true ) ;
68
- this . handleFirstElementFocus ( ) ;
49
+ this . processFirstElementFocus ( ) ;
69
50
} ,
70
51
71
- handleBlur ( ) { //TODO is this working?
52
+ processBlur ( ) { //TODO is this working?
72
53
next ( this , function ( ) {
73
54
let subItems = Array . from ( this . element . querySelectorAll ( '.navbar-dropdown-list li' ) ) ;
74
55
let focused = subItems . find ( item => document . activeElement === item . querySelector ( 'a' ) ) ;
@@ -80,12 +61,38 @@ export default Component.extend({
80
61
} ) ;
81
62
} ,
82
63
83
- handleFirstElementFocus ( ) {
64
+ processClick ( ) {
65
+
66
+ } ,
67
+
68
+ processFirstElementFocus ( ) {
84
69
// Identify the first item in the dropdown list & set focus on it
85
70
let firstFocusable = this . element . querySelector ( '.navbar-dropdown-list li:first-of-type a' ) ;
86
71
firstFocusable . focus ( ) ;
87
72
} ,
88
73
74
+ processKeyPress ( ) {
75
+ // add event listeners
76
+ let dropdownList = this . element . querySelector ( '.navbar-dropdown-list' ) ;
77
+
78
+ //...for certain keypress events
79
+ dropdownList . addEventListener ( 'keydown' , event => {
80
+
81
+ // ESC key should close the dropdown and return focus to the toggle
82
+ if ( event . keyCode === 27 && this . isDropdownOpen ) {
83
+ this . closeDropdown ( ) ;
84
+ this . returnFocus ( ) ;
85
+
86
+ // if focus leaves the open dropdown via keypress, close it (without trying to otherwise control focus)
87
+ } else if ( this . isDropdownOpen ) {
88
+ this . processBlur ( ) ;
89
+
90
+ } else {
91
+ return ;
92
+ }
93
+ } ) ;
94
+ } ,
95
+
89
96
returnFocus ( ) {
90
97
// after that rendering bit happens, we need to return the focus to the trigger
91
98
schedule ( 'afterRender' , this , function ( ) {
0 commit comments