]> source.dussan.org Git - vaadin-framework.git/commitdiff
Override IE disabled style for text field (#14565)
authorMikael Grankvist <mgrankvi@vaadin.com>
Thu, 4 Sep 2014 12:01:20 +0000 (15:01 +0300)
committerSauli Tähkäpää <sauli@vaadin.com>
Fri, 12 Sep 2014 13:29:50 +0000 (16:29 +0300)
Change-Id: Ie48e56666c43450c47015067879fdc604c7ac843

client/src/com/vaadin/client/ui/VPopupCalendar.java
client/src/com/vaadin/client/ui/datefield/PopupDateFieldConnector.java
uitest/src/com/vaadin/tests/components/datefield/PopupDateFieldStates.java [new file with mode: 0644]
uitest/src/com/vaadin/tests/components/datefield/PopupDateFieldStatesTest.java [new file with mode: 0644]

index 1474ad3b71526c4b9272d2f44cd3488286a55665..577e267d3b40720ddf51ec3f695c1321c8582ab6 100644 (file)
@@ -240,7 +240,23 @@ public class VPopupCalendar extends VTextualDate implements Field,
      */
     public void setTextFieldEnabled(boolean textFieldEnabled) {
         this.textFieldEnabled = textFieldEnabled;
-        text.setEnabled(textFieldEnabled);
+        // IE has a non input disabled themeing that can not be overridden so we
+        // must fake the functionality using readonly and unselectable
+        if (BrowserInfo.get().isIE()) {
+            if (!textFieldEnabled) {
+                text.getElement().setAttribute("unselectable", "on");
+                text.getElement().setAttribute("readonly", "");
+                text.setTabIndex(-2);
+            } else if (textFieldEnabled
+                    && text.getElement().hasAttribute("unselectable")) {
+                text.getElement().removeAttribute("unselectable");
+                text.getElement().removeAttribute("readonly");
+                text.setTabIndex(0);
+            }
+        } else {
+            text.setEnabled(textFieldEnabled);
+        }
+
         if (textFieldEnabled) {
             calendarToggle.setTabIndex(-1);
             Roles.getButtonRole().setAriaHiddenState(
@@ -254,6 +270,20 @@ public class VPopupCalendar extends VTextualDate implements Field,
         handleAriaAttributes();
     }
 
+    /**
+     * Set correct tab index for disabled text field in IE as the value set in
+     * setTextFieldEnabled(...) gets overridden in
+     * TextualDateConnection.updateFromUIDL(...)
+     * 
+     * @since
+     */
+    public void setTextFieldTabIndex() {
+        if (BrowserInfo.get().isIE() && !textFieldEnabled) {
+            // index needs to be -2 because FocusWidget updates -1 to 0 onAttach
+            text.setTabIndex(-2);
+        }
+    }
+
     @Override
     public void bindAriaCaption(
             com.google.gwt.user.client.Element captionElement) {
@@ -426,10 +456,10 @@ public class VPopupCalendar extends VTextualDate implements Field,
     public void onClose(CloseEvent<PopupPanel> event) {
         if (event.getSource() == popup) {
             buildDate();
-            if (!BrowserInfo.get().isTouchDevice()) {
+            if (!BrowserInfo.get().isTouchDevice() && textFieldEnabled) {
                 /*
                  * Move focus to textbox, unless on touch device (avoids opening
-                 * virtual keyboard).
+                 * virtual keyboard) or if textField is disabled.
                  */
                 focus();
             }
@@ -494,7 +524,7 @@ public class VPopupCalendar extends VTextualDate implements Field,
         }
 
         // superclass sets the text field independently when building date
-        text.setEnabled(isEnabled() && isTextFieldEnabled());
+        setTextFieldEnabled(isEnabled() && isTextFieldEnabled());
     }
 
     /**
index 6f059a7c16ca2bc4b19fd6e30ab5a4ea7ef40f4b..7bcaaba04e9e69311e8d8acec0b800ae43ae3c50 100644 (file)
@@ -161,6 +161,8 @@ public class PopupDateFieldConnector extends TextualDateConnector {
 
         getWidget().setDescriptionForAssistiveDevices(
                 getState().descriptionForAssistiveDevices);
+
+        getWidget().setTextFieldTabIndex();
     }
 
     @Override
diff --git a/uitest/src/com/vaadin/tests/components/datefield/PopupDateFieldStates.java b/uitest/src/com/vaadin/tests/components/datefield/PopupDateFieldStates.java
new file mode 100644 (file)
index 0000000..aae4a21
--- /dev/null
@@ -0,0 +1,57 @@
+package com.vaadin.tests.components.datefield;
+
+import java.util.Calendar;
+import java.util.Date;
+import java.util.GregorianCalendar;
+
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUI;
+import com.vaadin.ui.GridLayout;
+import com.vaadin.ui.PopupDateField;
+
+@SuppressWarnings("serial")
+public class PopupDateFieldStates extends AbstractTestUI {
+
+    @Override
+    protected void setup(VaadinRequest request) {
+        final GridLayout gridLayout = new GridLayout(2, 2);
+        gridLayout.setSpacing(true);
+
+        gridLayout.addComponent(createPopupDateField(true, true));
+        gridLayout.addComponent(createPopupDateField(true, false));
+        gridLayout.addComponent(createPopupDateField(false, true));
+        gridLayout.addComponent(createPopupDateField(false, false));
+
+        getLayout().addComponent(gridLayout);
+    }
+
+    @Override
+    protected String getTestDescription() {
+        return "Test that PopupDateField is rendered consistently across browsers";
+    }
+
+    @Override
+    protected Integer getTicketNumber() {
+        return 14565;
+    }
+
+    private static PopupDateField createPopupDateField(final boolean enabled,
+            final boolean textFieldEnabled) {
+        final PopupDateField popupDatefield = new PopupDateField();
+
+        Calendar cal = GregorianCalendar.getInstance();
+        cal.set(Calendar.DATE, 3);
+        cal.set(Calendar.MONTH, Calendar.SEPTEMBER);
+        cal.set(Calendar.YEAR, 2014);
+        cal.set(Calendar.HOUR_OF_DAY, 8);
+        final Date currentDate = cal.getTime();
+
+        popupDatefield.setValue(currentDate);
+        popupDatefield.setCaption("Enabled: " + enabled
+                + ", Text field enabled: " + textFieldEnabled);
+        popupDatefield.setEnabled(enabled);
+        popupDatefield.setTextFieldEnabled(textFieldEnabled);
+        return popupDatefield;
+    }
+
+}
diff --git a/uitest/src/com/vaadin/tests/components/datefield/PopupDateFieldStatesTest.java b/uitest/src/com/vaadin/tests/components/datefield/PopupDateFieldStatesTest.java
new file mode 100644 (file)
index 0000000..8c5ba20
--- /dev/null
@@ -0,0 +1,19 @@
+package com.vaadin.tests.components.datefield;
+
+import java.io.IOException;
+
+import org.junit.Test;
+
+import com.vaadin.tests.tb3.MultiBrowserTest;
+
+public class PopupDateFieldStatesTest extends MultiBrowserTest {
+
+    @Test
+    public void readOnlyDateFieldPopupShouldNotOpen() throws IOException,
+            InterruptedException {
+        openTestURL();
+
+        compareScreen("dateFieldStates");
+    }
+
+}