Sunday, June 15, 2014

Re: Suggestbox suggestions not displayed when navigating using arrow keys

Here is a solution without having to change the codebase:

private static class ScrollableDefaultSuggestionDisplay extends SuggestBox.DefaultSuggestionDisplay {
   
private Widget suggestionMenu;
   
   
@Override
   
protected Widget decorateSuggestionList(Widget suggestionList) {
        suggestionMenu
= suggestionList;
       
       
return suggestionList;
   
}
   
   
@Override
   
protected void moveSelectionDown() {
       
super.moveSelectionDown();
        scrollSelectedItemIntoView
();
   
}
   
   
@Override
   
protected void moveSelectionUp() {
       
super.moveSelectionUp();
        scrollSelectedItemIntoView
();
   
}
   
   
private void scrollSelectedItemIntoView() {
       
Element divElement = suggestionMenu.getElement();
       
Node tableNode = (Element)divElement.getChild(divElement.getChildCount() - 1);  // Firefox, Chrome have 2, IE has 1
       
//                      TABLE     TBODY       TR's
       
NodeList<Node> trList = tableNode.getChild(0).getChildNodes();
       
for (int trIndex = 0; trIndex < trList.getLength(); ++trIndex) {
           
Element trElement = (Element)trList.getItem(trIndex);
           
if (((Element)trElement.getChild(0)).getClassName().contains("selected")) {
                trElement
.scrollIntoView();
               
               
break;
           
}
       
}
   
}
}



--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment