Change-Id: Ie48e56666c43450c47015067879fdc604c7ac843tags/7.3.1
@@ -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()); | |||
} | |||
/** |
@@ -161,6 +161,8 @@ public class PopupDateFieldConnector extends TextualDateConnector { | |||
getWidget().setDescriptionForAssistiveDevices( | |||
getState().descriptionForAssistiveDevices); | |||
getWidget().setTextFieldTabIndex(); | |||
} | |||
@Override |
@@ -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; | |||
} | |||
} |
@@ -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"); | |||
} | |||
} |