@@ -25,13 +25,13 @@ class SLDSLookup extends React.Component {
2525 this . state = {
2626 searchTerm : '' ,
2727 isOpen :false ,
28- selectedItem : null ,
28+ selectedIndex : null ,
2929 activeIndex :null ,
3030 } ;
3131 }
3232
3333 //=================================================
34- // Set Active Descendant (currently focused/hovered item in list)
34+ // Set Active Descendant (on key down/up, set currently focused/hovered item in list)
3535 increaseIndex ( ) {
3636 this . setState ( {
3737 activeIndex : this . state . activeIndex <= this . props . items . length ? this . state . activeIndex + 1 : 0
@@ -44,6 +44,22 @@ class SLDSLookup extends React.Component {
4444 } )
4545 }
4646
47+ getActiveDescendant ( ) {
48+ console . log ( "aria-activedescendant is " , 'item-' + this . state . activeIndex ) ;
49+ return this . state . activeIndex !== null ? 'item-' + this . state . activeIndex : "" ;
50+ }
51+
52+ //=================================================
53+ // Select menu item (onClick or on key enter/space)
54+ selectItem ( index ) {
55+ this . setState ( {
56+ selectedIndex : index ,
57+ searchTerm : null
58+ } ) ;
59+ console . log ( "Selected Item is " , this . props . items [ index ] ) ;
60+ }
61+
62+
4763 //=================================================
4864 // Basic Event Listeners on Input
4965 handleClose ( ) {
@@ -101,6 +117,7 @@ class SLDSLookup extends React.Component {
101117 return < Menu
102118 searchTerm = { this . state . searchTerm }
103119 filterWith = { this . props . filterWith }
120+ onSelect = { this . selectItem . bind ( this ) }
104121 label = { this . props . label }
105122 items = { this . props . items }
106123 activeIndex = { this . state . activeIndex } /> ;
@@ -125,7 +142,7 @@ class SLDSLookup extends React.Component {
125142 aria-label = "lookup"
126143 aria-haspopup = "true"
127144 aria-autocomplete = "list"
128- aria-activedescendant = { this . state . activeIndex !== null ? "item-" + this . state . activeIndex : "" }
145+ aria-activedescendant = { this . getActiveDescendant ( ) }
129146 aria-expanded = { this . state . isOpen }
130147 role = "combobox"
131148 onChange = { this . handleChange . bind ( this ) }
0 commit comments