diff options
author | Anastasia Smirnova <anasmi@utu.fi> | 2018-10-17 11:12:03 +0300 |
---|---|---|
committer | Sun Zhe <31067185+ZheSun88@users.noreply.github.com> | 2018-10-17 11:12:03 +0300 |
commit | a52993ba9ca67c15e6ca311ca308528752b589c9 (patch) | |
tree | e5dd7ac201c7eb2f37f3ce5a644d42e3d35a7a14 | |
parent | e94e97444fe086cc3743289cdb9653c16816fea9 (diff) | |
download | vaadin-framework-a52993ba9ca67c15e6ca311ca308528752b589c9.tar.gz vaadin-framework-a52993ba9ca67c15e6ca311ca308528752b589c9.zip |
Rebuild calendar pop-up on readOnly state change (#11249)
* Rebuild calendar pop-up on readOnly state change
Fixes https://github.com/vaadin/framework/issues/6565
4 files changed, 84 insertions, 1 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 8a3c6c3325..655f18669c 100644 --- a/client/src/main/java/com/vaadin/client/ui/VAbstractCalendarPanel.java +++ b/client/src/main/java/com/vaadin/client/ui/VAbstractCalendarPanel.java @@ -939,6 +939,15 @@ public abstract class VAbstractCalendarPanel<R extends Enum<R>> } /** + * Returns the value of initialRenderDone + * + * @since + */ + public boolean isInitialRenderDone() { + return initialRenderDone; + } + + /** * For internal use only. May be removed or replaced in the future. * * Updates the calendar and text field with the selected dates. diff --git a/client/src/main/java/com/vaadin/client/ui/datefield/TextualDateConnector.java b/client/src/main/java/com/vaadin/client/ui/datefield/TextualDateConnector.java index f29a053c56..c254833d18 100644 --- a/client/src/main/java/com/vaadin/client/ui/datefield/TextualDateConnector.java +++ b/client/src/main/java/com/vaadin/client/ui/datefield/TextualDateConnector.java @@ -117,7 +117,7 @@ public abstract class TextualDateConnector<PANEL extends VAbstractCalendarPanel< @Override public void onStateChanged(StateChangeEvent stateChangeEvent) { String oldLocale = getWidget().getCurrentLocale(); - + boolean isReadOnly = getWidget().isReadonly(); getWidget().parsable = getState().parsable; super.onStateChanged(stateChangeEvent); @@ -159,6 +159,10 @@ public abstract class TextualDateConnector<PANEL extends VAbstractCalendarPanel< } else { getWidget().calendarToggle.removeStyleName( VAbstractPopupCalendar.CLASSNAME + "-button-readonly"); + if (getState().readOnly != isReadOnly + && getWidget().calendar.isInitialRenderDone()) { + getWidget().calendar.renderCalendar(); + } } getWidget().setDescriptionForAssistiveDevices( diff --git a/uitest/src/main/java/com/vaadin/tests/components/datefield/DateTimeFieldAfterReadOnly.java b/uitest/src/main/java/com/vaadin/tests/components/datefield/DateTimeFieldAfterReadOnly.java new file mode 100644 index 0000000000..25f3e608d5 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/components/datefield/DateTimeFieldAfterReadOnly.java @@ -0,0 +1,37 @@ +package com.vaadin.tests.components.datefield; + +import com.vaadin.annotations.Widgetset; +import com.vaadin.server.VaadinRequest; +import com.vaadin.shared.ui.datefield.DateTimeResolution; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.Button; +import com.vaadin.ui.DateTimeField; + +import java.time.LocalDateTime; +import java.util.Locale; + +@Widgetset("com.vaadin.DefaultWidgetSet") +public class DateTimeFieldAfterReadOnly extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + final DateTimeField timeField = new DateTimeField( + "A read-only datefield"); + timeField.setResolution(DateTimeResolution.MINUTE); + timeField.setLocale(new Locale("fi")); + timeField.setId("dF"); + // Set date so that testing always has same time + timeField.setValue(LocalDateTime.now()); + timeField.setReadOnly(true); + + addComponent(timeField); + + Button b = new Button("Switch read-only"); + b.addClickListener(event -> { + timeField.setReadOnly(!timeField.isReadOnly()); + }); + b.setId("readOnlySwitch"); + + addComponent(b); + } +} diff --git a/uitest/src/test/java/com/vaadin/tests/components/datefield/DateTimeFieldAfterReadOnlyTest.java b/uitest/src/test/java/com/vaadin/tests/components/datefield/DateTimeFieldAfterReadOnlyTest.java new file mode 100644 index 0000000000..6e2f748015 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/components/datefield/DateTimeFieldAfterReadOnlyTest.java @@ -0,0 +1,33 @@ +package com.vaadin.tests.components.datefield; + +import com.vaadin.testbench.By; +import com.vaadin.testbench.elements.AbstractDateFieldElement; +import com.vaadin.tests.tb3.MultiBrowserTest; +import org.junit.Test; + +import static junit.framework.TestCase.assertEquals; + +public class DateTimeFieldAfterReadOnlyTest extends MultiBrowserTest { + + @Test + public void readOnlyDateFieldPopupShouldNotOpen() { + openTestURL(); + toggleReadOnly(); + openPopup(); + assertEquals(2, numberOfSelectsField()); + } + + private void openPopup() { + $(AbstractDateFieldElement.class).first() + .findElement(By.tagName("button")).click(); + } + + private void toggleReadOnly() { + findElement(By.id("readOnlySwitch")).click(); + } + + private int numberOfSelectsField() { + return findElement(By.className("v-datefield-calendarpanel-time")) + .findElements(By.className("v-select")).size(); + } +} |