Skip to content

Commit

Permalink
Stop stealing focus on input elements inside Grid.
Browse files Browse the repository at this point in the history
  • Loading branch information
Saulis committed Jul 2, 2015
1 parent 99575b2 commit 7b8c3c5
Showing 1 changed file with 16 additions and 2 deletions.
Expand Up @@ -2,6 +2,7 @@

import com.google.gwt.dom.client.Document;
import com.google.gwt.dom.client.Element;
import com.google.gwt.dom.client.EventTarget;
import com.google.gwt.dom.client.IFrameElement;
import com.google.gwt.query.client.GQuery;
import com.google.gwt.user.client.DOM;
Expand Down Expand Up @@ -117,11 +118,24 @@ private static int getWidgetUtilNativeScrollbarSize() {

@Override
public void onBrowserEvent(Event event) {

// clicking on the select all checkbox moves focus away from the grid
// causing the :focus transition effect to be reapplied. Forcing focus on the grid
// will mitigate the issue. Grid should always keep the focus anyways when interacting with it.
getElement().focus();
// will mitigate the issue.
focusGridIfSelectAllClicked(event);

super.onBrowserEvent(event);
}

private void focusGridIfSelectAllClicked(Event event) {
EventTarget target = event.getEventTarget();
if(Element.is(target)) {
Element targetElement = Element.as(target);

// Currently targeting all gwt-checkboxes, might need refinement in the future.
if(targetElement.getParentElement().hasClassName("gwt-CheckBox")) {
getElement().focus();

This comment has been minimized.

Copy link
@jouni

jouni Jul 6, 2015

Member

It is becoming clear that this is only a temporary fix.

For example, when you have a grid partially visible in the browser (not focused yet), and press the mouse button down on the "select all" checkbox, the browser will scroll, and the mouseup event will not hit the "select all" checkbox, and the selection will not happen. The user needs to click the checkbox again.

Edit: opened a new issue: #53

}
}
}
}

0 comments on commit 7b8c3c5

Please sign in to comment.