diff --git a/zkdoc/release-note b/zkdoc/release-note index ecadaed85a..7f0ba284fc 100644 --- a/zkdoc/release-note +++ b/zkdoc/release-note @@ -3,6 +3,7 @@ ZK 10.0.0 ZK-5221: Show websocket close reason ZK-5018: Enhance simplified MVVM syntax ZK-5516: change the current month with a keyboard + ZK-5517: change the current year with a keyboard * Bugs ZK-5393: Update ZK jars to jakarta-friendly uploads diff --git a/zktest/src/main/webapp/test2/F100-ZK-5517.zul b/zktest/src/main/webapp/test2/F100-ZK-5517.zul new file mode 100644 index 0000000000..e87bcba0c1 --- /dev/null +++ b/zktest/src/main/webapp/test2/F100-ZK-5517.zul @@ -0,0 +1,21 @@ + + + + + + \ No newline at end of file diff --git a/zktest/src/main/webapp/test2/config.properties b/zktest/src/main/webapp/test2/config.properties index b6cea38741..6984de004d 100644 --- a/zktest/src/main/webapp/test2/config.properties +++ b/zktest/src/main/webapp/test2/config.properties @@ -3796,6 +3796,7 @@ F86-ZK-4235.zul=A,E,datefmt,library-property ##zats##F100-ZK-5018-command.zul=A,E,MVVM,Syntax,simplified ##zats##F100-ZK-5018-syntax-exception.zul=A,E,MVVM,Syntax,simplified ##zats##F100-ZK-5516.zul=A,E,calendar,month,keyboard +##zats##F100-ZK-5517.zul=A,E,calendar,year,keyboard # Complex Test Case # diff --git a/zktest/src/test/java/org/zkoss/zktest/zats/test2/F100_ZK_5517Test.java b/zktest/src/test/java/org/zkoss/zktest/zats/test2/F100_ZK_5517Test.java new file mode 100644 index 0000000000..20f5543d66 --- /dev/null +++ b/zktest/src/test/java/org/zkoss/zktest/zats/test2/F100_ZK_5517Test.java @@ -0,0 +1,78 @@ +/* F100_ZK_5517Test.java + + Purpose: + + Description: + + History: + Fri Dec 08 18:44:37 CST 2023, Created by jamson + +Copyright (C) 2023 Potix Corporation. All Rights Reserved. +*/ +package org.zkoss.zktest.zats.test2; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.junit.jupiter.api.Test; +import org.openqa.selenium.Keys; +import org.openqa.selenium.interactions.Actions; + +import org.zkoss.test.webdriver.WebDriverTestCase; +import org.zkoss.test.webdriver.ztl.Widget; + +public class F100_ZK_5517Test extends WebDriverTestCase { + @Test + public void test() { + connect(); + + Actions actions = getActions(); + Widget cld = jq("@calendar").toWidget(); + String month = getMonth(cld); + int year = getYear(cld), + date = getDate(); + + click(jq(".z-calendar-selected")); + waitResponse(); + + if ("Feb".equals(month) && date == 29) { + date = 28; + actions.keyDown(Keys.ARROW_LEFT).perform(); + } + + actions.keyDown(Keys.SHIFT).keyDown(Keys.PAGE_UP).perform(); + waitResponse(); + + assertEquals(year, getYear(cld) + 1); + assertEquals(month, getMonth(cld)); + assertEquals(date, getDate()); + + actions.keyDown(Keys.SHIFT).keyDown(Keys.PAGE_DOWN).perform(); + waitResponse(); + + actions.keyDown(Keys.SHIFT).keyDown(Keys.PAGE_DOWN).perform(); + waitResponse(); + + assertEquals(year, getYear(cld) - 1); + assertEquals(month, getMonth(cld)); + assertEquals(date, getDate()); + + actions.keyDown(Keys.SHIFT).keyDown(Keys.PAGE_UP).perform(); + waitResponse(); + + assertEquals(year, getYear(cld)); + assertEquals(month, getMonth(cld)); + assertEquals(date, getDate()); + } + + public int getYear(Widget calendar) { + return Integer.parseInt(calendar.$n("ty").get("innerHTML")); + } + + public String getMonth(Widget calendar) { + return calendar.$n("tm").get("innerHTML"); + } + + public int getDate() { + return Integer.parseInt(jq(".z-calendar-selected").toElement().get("innerHTML")); + } +} diff --git a/zul/src/main/resources/web/js/zul/db/Calendar.ts b/zul/src/main/resources/web/js/zul/db/Calendar.ts index 1c7e74bbce..25e0f2fd76 100644 --- a/zul/src/main/resources/web/js/zul/db/Calendar.ts +++ b/zul/src/main/resources/web/js/zul/db/Calendar.ts @@ -683,6 +683,14 @@ export class Calendar extends zul.Widget { } else if (evt.key === 'PageDown') { // PageDown: next month this._setView('month'); this._shift(1); + } else if (evt.shiftKey) { + if (evt.key === 'PageUp') { // Shift + PageUp: prev year + this._setView('year'); + this._shift(-1); + } else if (evt.key === 'PageDown') { // Shift + PageDown: next year + this._setView('year'); + this._shift(1); + } } this._setView(currentView);