summaryrefslogtreecommitdiffstats
path: root/client
diff options
context:
space:
mode:
authorAhmed Ashour <asashour@yahoo.com>2017-11-23 06:54:27 +0100
committercaalador <mikael.grankvist@gmail.com>2017-11-23 07:54:27 +0200
commitacfd75ee2ec8ad97f8dd54e2ae454257e7284159 (patch)
tree420846e20f0ca84121549b851f6b26018518fd99 /client
parente38ad29499328ddbf995d64612d932832d5bd628 (diff)
downloadvaadin-framework-acfd75ee2ec8ad97f8dd54e2ae454257e7284159.tar.gz
vaadin-framework-acfd75ee2ec8ad97f8dd54e2ae454257e7284159.zip
DateField not to fire focus/blur event when going to sub-components (#10246)
Fixes `DateField blur event fires when focus gets to the "calendar button"` #1008
Diffstat (limited to 'client')
-rw-r--r--client/src/main/java/com/vaadin/client/ui/VAbstractCalendarPanel.java1
-rw-r--r--client/src/main/java/com/vaadin/client/ui/VAbstractPopupCalendar.java28
-rw-r--r--client/src/main/java/com/vaadin/client/ui/VAbstractTextualDate.java54
3 files changed, 60 insertions, 23 deletions
diff --git a/client/src/main/java/com/vaadin/client/ui/VAbstractCalendarPanel.java b/client/src/main/java/com/vaadin/client/ui/VAbstractCalendarPanel.java
index 70bec08e4f..f009f483e0 100644
--- a/client/src/main/java/com/vaadin/client/ui/VAbstractCalendarPanel.java
+++ b/client/src/main/java/com/vaadin/client/ui/VAbstractCalendarPanel.java
@@ -1997,7 +1997,6 @@ public abstract class VAbstractCalendarPanel<R extends Enum<R>>
renderCalendar();
}
}
-
}
/**
diff --git a/client/src/main/java/com/vaadin/client/ui/VAbstractPopupCalendar.java b/client/src/main/java/com/vaadin/client/ui/VAbstractPopupCalendar.java
index d894653609..4df4d0e325 100644
--- a/client/src/main/java/com/vaadin/client/ui/VAbstractPopupCalendar.java
+++ b/client/src/main/java/com/vaadin/client/ui/VAbstractPopupCalendar.java
@@ -377,7 +377,6 @@ public abstract class VAbstractPopupCalendar<PANEL extends VAbstractCalendarPane
* Opens the calendar panel popup.
*/
public void openCalendarPanel() {
-
if (!open && !readonly && isEnabled()) {
open = true;
@@ -393,6 +392,8 @@ public abstract class VAbstractPopupCalendar<PANEL extends VAbstractCalendarPane
popup.setWidth("");
popup.setHeight("");
popup.setPopupPositionAndShow(new PopupPositionCallback());
+
+ checkGroupFocus(true);
} else {
getLogger().severe("Cannot reopen popup, it is already open!");
}
@@ -451,6 +452,7 @@ public abstract class VAbstractPopupCalendar<PANEL extends VAbstractCalendarPane
* Sets focus to Calendar panel.
*
* @param focus
+ * {@code true} for {@code focus}, {@code false} for {@code blur}
*/
public void setFocus(boolean focus) {
calendar.setFocus(focus);
@@ -683,19 +685,16 @@ public abstract class VAbstractPopupCalendar<PANEL extends VAbstractCalendarPane
// are in the lower right corner of the screen
if (overflow) {
return left;
- } else {
- return left + calendarToggle.getOffsetWidth();
- }
- } else {
- int[] margins = style.getMargin();
- int desiredLeftPosition = calendarToggle.getAbsoluteLeft()
- - width - margins[1] - margins[3];
- if (desiredLeftPosition >= 0) {
- return desiredLeftPosition;
- } else {
- return left;
}
+ return left + calendarToggle.getOffsetWidth();
}
+ int[] margins = style.getMargin();
+ int desiredLeftPosition = calendarToggle.getAbsoluteLeft() - width
+ - margins[1] - margins[3];
+ if (desiredLeftPosition >= 0) {
+ return desiredLeftPosition;
+ }
+ return left;
}
private boolean positionRightSide() {
@@ -721,6 +720,11 @@ public abstract class VAbstractPopupCalendar<PANEL extends VAbstractCalendarPane
}
}
+ @Override
+ protected boolean hasChildFocus() {
+ return open;
+ }
+
private static Logger getLogger() {
return Logger.getLogger(VAbstractPopupCalendar.class.getName());
}
diff --git a/client/src/main/java/com/vaadin/client/ui/VAbstractTextualDate.java b/client/src/main/java/com/vaadin/client/ui/VAbstractTextualDate.java
index 66ddf1d829..11102a218e 100644
--- a/client/src/main/java/com/vaadin/client/ui/VAbstractTextualDate.java
+++ b/client/src/main/java/com/vaadin/client/ui/VAbstractTextualDate.java
@@ -21,6 +21,7 @@ import java.util.logging.Level;
import java.util.logging.Logger;
import com.google.gwt.aria.client.Roles;
+import com.google.gwt.core.client.Scheduler;
import com.google.gwt.dom.client.Element;
import com.google.gwt.event.dom.client.ChangeEvent;
import com.google.gwt.event.dom.client.ChangeHandler;
@@ -76,14 +77,19 @@ public abstract class VAbstractTextualDate<R extends Enum<R>>
/** For internal use only. May be removed or replaced in the future. */
private TimeZone timeZone;
+ /**
+ * Specifies whether the group of components has focus or not.
+ */
+ private boolean groupFocus;
+
public VAbstractTextualDate(R resoluton) {
super(resoluton);
text = new TextBox();
text.addChangeHandler(this);
text.addFocusHandler(
- event -> fireBlurFocusEvent(event, true, EventId.FOCUS));
+ event -> fireBlurFocusEvent(event, true));
text.addBlurHandler(
- event -> fireBlurFocusEvent(event, false, EventId.BLUR));
+ event -> fireBlurFocusEvent(event, false));
if (BrowserInfo.get().isIE()) {
addDomHandler(this, KeyDownEvent.getType());
}
@@ -394,27 +400,54 @@ public abstract class VAbstractTextualDate<R extends Enum<R>>
}
private void fireBlurFocusEvent(DomEvent<?> event,
- boolean addFocusStyleName, String eventId) {
+ boolean focus) {
String styleName = VTextField.CLASSNAME + "-"
+ VTextField.CLASSNAME_FOCUS;
- if (addFocusStyleName) {
+ if (focus) {
text.addStyleName(styleName);
} else {
text.removeStyleName(styleName);
}
- if (getClient() != null && connector.hasEventListener(eventId)) {
- // may excessively send events if if focus went to another
- // sub-component
- if (EventId.FOCUS.equals(eventId)) {
+
+ Scheduler.get().scheduleDeferred(() -> checkGroupFocus(focus));
+
+ // Needed for tooltip event handling
+ fireEvent(event);
+ }
+
+ /**
+ * Checks if the group focus has changed, and sends to the server if needed.
+ *
+ * @param textFocus
+ * the focus of the {@link #text}
+ * @since
+ */
+ protected void checkGroupFocus(boolean textFocus) {
+ boolean newGroupFocus = textFocus | hasChildFocus();
+ if (getClient() != null
+ && connector.hasEventListener(
+ textFocus ? EventId.FOCUS : EventId.BLUR)
+ && groupFocus != newGroupFocus) {
+
+ if (newGroupFocus) {
rpc.focus();
} else {
rpc.blur();
}
sendBufferedValues();
+ groupFocus = newGroupFocus;
}
+ }
- // Needed for tooltip event handling
- fireEvent(event);
+ /**
+ * Returns whether any of the child components has focus.
+ *
+ * @return {@code true} if any of the child component has focus,
+ * {@code false} otherwise
+ * @since
+ */
+ protected boolean hasChildFocus() {
+ return false;
}
/**
@@ -479,4 +512,5 @@ public abstract class VAbstractTextualDate<R extends Enum<R>>
private static Logger getLogger() {
return Logger.getLogger(VAbstractTextualDate.class.getName());
}
+
}