@@ -690,7 +690,7 @@ function SelectMenuDirective($parse, $mdUtil, $mdConstant, $mdTheming) {
690
690
element . on ( 'keypress' , keyListener ) ;
691
691
692
692
function keyListener ( e ) {
693
- if ( e . keyCode == 13 || e . keyCode == 32 ) {
693
+ if ( e . keyCode === 13 || e . keyCode = == 32 ) {
694
694
clickListener ( e ) ;
695
695
}
696
696
}
@@ -796,10 +796,10 @@ function SelectMenuDirective($parse, $mdUtil, $mdConstant, $mdTheming) {
796
796
} ;
797
797
798
798
/**
799
- * @param {KeyboardEvent } e keyboard event to handle
800
- * @return {DOMElement |HTMLElement|undefined }
799
+ * @param {KeyboardEvent } keyboardEvent keyboard event to handle
800
+ * @return {Element |HTMLElement|undefined }
801
801
*/
802
- self . optNodeForKeyboardSearch = function ( e ) {
802
+ self . optNodeForKeyboardSearch = function ( keyboardEvent ) {
803
803
var search , i ;
804
804
clearSearchTimeout && clearTimeout ( clearSearchTimeout ) ;
805
805
clearSearchTimeout = setTimeout ( function ( ) {
@@ -809,7 +809,7 @@ function SelectMenuDirective($parse, $mdUtil, $mdConstant, $mdTheming) {
809
809
optNodes = undefined ;
810
810
} , CLEAR_SEARCH_AFTER ) ;
811
811
812
- searchStr += e . key ;
812
+ searchStr += keyboardEvent . key ;
813
813
search = new RegExp ( '^' + $mdUtil . sanitize ( searchStr ) , 'i' ) ;
814
814
if ( ! optNodes ) {
815
815
optNodes = $element . find ( 'md-option' ) ;
@@ -818,12 +818,12 @@ function SelectMenuDirective($parse, $mdUtil, $mdConstant, $mdTheming) {
818
818
optText [ i ] = el . textContent . trim ( ) ;
819
819
} ) ;
820
820
}
821
+
821
822
for ( i = 0 ; i < optText . length ; ++ i ) {
822
823
if ( search . test ( optText [ i ] ) ) {
823
824
return optNodes [ i ] ;
824
825
}
825
826
}
826
-
827
827
} ;
828
828
829
829
self . init = function ( ngModel , binding ) {
@@ -1523,6 +1523,7 @@ function SelectProvider($$interimElementProvider) {
1523
1523
1524
1524
/**
1525
1525
* Initialize container and dropDown menu positions/scale, then animate to show.
1526
+ * @return {* } a Promise that resolves after the menu is animated in and an item is focused
1526
1527
*/
1527
1528
function positionAndFocusMenu ( ) {
1528
1529
return $q ( function ( resolve ) {
@@ -1576,12 +1577,11 @@ function SelectProvider($$interimElementProvider) {
1576
1577
}
1577
1578
1578
1579
/**
1579
- * @param {DOMElement|HTMLElement|null= } previousNode
1580
- * @param {DOMElement|HTMLElement } node
1581
- * @param {SelectMenuController|Function } menuController SelectMenuController instance
1582
- * @param {Function|* } selectController SelectController instance
1580
+ * @param {Element|HTMLElement|null= } previousNode
1581
+ * @param {Element|HTMLElement } node
1582
+ * @param {SelectMenuController|Function|Object= } menuController SelectMenuController instance
1583
1583
*/
1584
- function focusOptionNode ( previousNode , node , menuController , selectController ) {
1584
+ function focusOptionNode ( previousNode , node , menuController ) {
1585
1585
var listboxContentNode = opts . contentEl [ 0 ] ;
1586
1586
1587
1587
if ( node ) {
@@ -1590,7 +1590,9 @@ function SelectProvider($$interimElementProvider) {
1590
1590
}
1591
1591
1592
1592
node . classList . add ( 'md-focused' ) ;
1593
- menuController . setActiveDescendant ( node . id ) ;
1593
+ if ( menuController && menuController . setActiveDescendant ) {
1594
+ menuController . setActiveDescendant ( node . id ) ;
1595
+ }
1594
1596
1595
1597
// Scroll the node into view if needed.
1596
1598
if ( listboxContentNode . scrollHeight > listboxContentNode . clientHeight ) {
@@ -1603,18 +1605,20 @@ function SelectProvider($$interimElementProvider) {
1603
1605
}
1604
1606
}
1605
1607
opts . focusedNode = node ;
1606
- menuController . refreshViewValue ( ) ;
1608
+ if ( menuController && menuController . refreshViewValue ) {
1609
+ menuController . refreshViewValue ( ) ;
1610
+ }
1607
1611
}
1608
1612
}
1609
1613
1610
1614
/**
1611
- * @param {DOMElement |HTMLElement } nodeToFocus
1615
+ * @param {Element |HTMLElement } nodeToFocus
1612
1616
*/
1613
1617
function autoFocus ( nodeToFocus ) {
1614
1618
var selectMenuController ;
1615
1619
if ( nodeToFocus && ! nodeToFocus . hasAttribute ( 'disabled' ) ) {
1616
1620
selectMenuController = opts . selectEl . controller ( 'mdSelectMenu' ) ;
1617
- focusOptionNode ( null , nodeToFocus , selectMenuController , opts . selectCtrl ) ;
1621
+ focusOptionNode ( null , nodeToFocus , selectMenuController ) ;
1618
1622
}
1619
1623
}
1620
1624
@@ -1757,7 +1761,7 @@ function SelectProvider($$interimElementProvider) {
1757
1761
if ( shouldHandleKey ( ev , $mdConstant ) ) {
1758
1762
var optNode = selectMenuController . optNodeForKeyboardSearch ( ev ) ;
1759
1763
if ( optNode && ! optNode . hasAttribute ( 'disabled' ) ) {
1760
- focusOptionNode ( opts . focusedNode , optNode , selectMenuController , opts . selectCtrl ) ;
1764
+ focusOptionNode ( opts . focusedNode , optNode , selectMenuController ) ;
1761
1765
}
1762
1766
}
1763
1767
}
@@ -1790,7 +1794,7 @@ function SelectProvider($$interimElementProvider) {
1790
1794
}
1791
1795
} while ( ! newOption && index < optionsArray . length - 1 && index > 0 ) ;
1792
1796
1793
- focusOptionNode ( prevOption , newOption , selectMenuController , opts . selectCtrl ) ;
1797
+ focusOptionNode ( prevOption , newOption , selectMenuController ) ;
1794
1798
}
1795
1799
1796
1800
function focusNextOption ( ) {
@@ -1801,8 +1805,11 @@ function SelectProvider($$interimElementProvider) {
1801
1805
focusOption ( 'prev' ) ;
1802
1806
}
1803
1807
1804
- function checkCloseMenu ( ev ) {
1805
- if ( ev && ( ev . type === 'click' ) && ( ev . currentTarget != dropDown [ 0 ] ) ) {
1808
+ /**
1809
+ * @param {KeyboardEvent|MouseEvent } event
1810
+ */
1811
+ function checkCloseMenu ( event ) {
1812
+ if ( event && ( event . type === 'click' ) && ( event . currentTarget !== dropDown [ 0 ] ) ) {
1806
1813
return ;
1807
1814
}
1808
1815
if ( mouseOnScrollbar ( ) ) {
@@ -1811,8 +1818,8 @@ function SelectProvider($$interimElementProvider) {
1811
1818
1812
1819
if ( opts . focusedNode && opts . focusedNode . hasAttribute &&
1813
1820
! opts . focusedNode . hasAttribute ( 'disabled' ) ) {
1814
- ev . preventDefault ( ) ;
1815
- ev . stopPropagation ( ) ;
1821
+ event . preventDefault ( ) ;
1822
+ event . stopPropagation ( ) ;
1816
1823
if ( ! selectMenuController . isMultiple ) {
1817
1824
opts . restoreFocus = true ;
1818
1825
@@ -1821,16 +1828,17 @@ function SelectProvider($$interimElementProvider) {
1821
1828
} , true ) ;
1822
1829
}
1823
1830
}
1831
+
1824
1832
/**
1825
1833
* check if the mouseup event was on a scrollbar
1826
1834
*/
1827
1835
function mouseOnScrollbar ( ) {
1828
1836
var clickOnScrollbar = false ;
1829
- if ( ev && ( ev . currentTarget . children . length > 0 ) ) {
1830
- var child = ev . currentTarget . children [ 0 ] ;
1837
+ if ( event && ( event . currentTarget . children . length > 0 ) ) {
1838
+ var child = event . currentTarget . children [ 0 ] ;
1831
1839
var hasScrollbar = child . scrollHeight > child . clientHeight ;
1832
1840
if ( hasScrollbar && child . children . length > 0 ) {
1833
- var relPosX = ev . pageX - ev . currentTarget . getBoundingClientRect ( ) . left ;
1841
+ var relPosX = event . pageX - event . currentTarget . getBoundingClientRect ( ) . left ;
1834
1842
if ( relPosX > child . querySelector ( 'md-option' ) . offsetWidth )
1835
1843
clickOnScrollbar = true ;
1836
1844
}
0 commit comments