Skip to content

Commit

Permalink
Merge pull request #387 from vaadin/fix/input-focus
Browse files Browse the repository at this point in the history
Prevent focus from being stolen for focusable elements inside cells
  • Loading branch information
manolo authored Jun 14, 2016
2 parents 3c37785 + 4e612c5 commit 107c0d4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
15 changes: 14 additions & 1 deletion java/src/main/java/com/vaadin/elements/grid/ViolatedGrid.java
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,24 @@ public void onBrowserEvent(Event event) {
focusGridIfSelectAllClicked(event);

Element targetElement = (Element)event.getEventTarget().cast();
if (targetElement != WidgetUtil.getFocusedElement() || isElementOutsideStaticSection(targetElement)) {

// by default Grid steals focus from focusable elements inside cells,
// so we need to prevent that.
Element focusedElement = WidgetUtil.getFocusedElement();
if (elementContains(targetElement, focusedElement)) {
return;
}

if (targetElement != focusedElement || isElementOutsideStaticSection(targetElement)) {
super.onBrowserEvent(event);
}
}

private native Boolean elementContains(Element parent, Element child)
/*-{
return parent.contains(child);
}-*/;

private boolean isElementOutsideStaticSection(Element element) {
TableSectionElement headerElement = getEscalator().getHeader().getElement();
TableSectionElement footerElement = getEscalator().getFooter().getElement();
Expand Down
8 changes: 4 additions & 4 deletions vaadin-grid.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 107c0d4

Please # to comment.