-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add static methods to set Popover global delays (#6566)
- Loading branch information
1 parent
83b3c7a
commit 081c7fd
Showing
4 changed files
with
238 additions
and
0 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
...tests/src/main/java/com/vaadin/flow/component/popover/tests/PopoverDelayDefaultsPage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright 2000-2024 Vaadin Ltd. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
* use this file except in compliance with the License. You may obtain a copy of | ||
* the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
package com.vaadin.flow.component.popover.tests; | ||
|
||
import com.vaadin.flow.component.html.Div; | ||
import com.vaadin.flow.component.html.NativeButton; | ||
import com.vaadin.flow.component.popover.Popover; | ||
import com.vaadin.flow.router.PreserveOnRefresh; | ||
import com.vaadin.flow.router.Route; | ||
|
||
@PreserveOnRefresh | ||
@Route("vaadin-popover/delay-defaults") | ||
public class PopoverDelayDefaultsPage extends Div { | ||
public PopoverDelayDefaultsPage() { | ||
Popover popover = new Popover(); | ||
|
||
NativeButton setDefaultDelaysTo2000Button = new NativeButton( | ||
"Set default delays to 2000", e -> { | ||
Popover.setDefaultFocusDelay(2000); | ||
Popover.setDefaultHoverDelay(2000); | ||
Popover.setDefaultHideDelay(2000); | ||
}); | ||
setDefaultDelaysTo2000Button.setId("set-default-delays-to-2000"); | ||
|
||
NativeButton setDefaultDelaysTo5000Button = new NativeButton( | ||
"Set default delays to 5000", e -> { | ||
Popover.setDefaultFocusDelay(5000); | ||
Popover.setDefaultHoverDelay(5000); | ||
Popover.setDefaultHideDelay(5000); | ||
}); | ||
setDefaultDelaysTo5000Button.setId("set-default-delays-to-5000"); | ||
|
||
add(popover, setDefaultDelaysTo2000Button, | ||
setDefaultDelaysTo5000Button); | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
...n-tests/src/test/java/com/vaadin/flow/component/popover/tests/PopoverDelayDefaultsIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* Copyright 2000-2024 Vaadin Ltd. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
* use this file except in compliance with the License. You may obtain a copy of | ||
* the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
package com.vaadin.flow.component.popover.tests; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import com.vaadin.flow.component.popover.testbench.PopoverElement; | ||
import com.vaadin.flow.testutil.TestPath; | ||
import com.vaadin.tests.AbstractComponentIT; | ||
|
||
@TestPath("vaadin-popover/delay-defaults") | ||
public class PopoverDelayDefaultsIT extends AbstractComponentIT { | ||
|
||
private PopoverElement popover; | ||
|
||
@Before | ||
public void init() { | ||
open(); | ||
popover = $(PopoverElement.class).first(); | ||
} | ||
|
||
@Test | ||
public void changeDefaults_checkPopoverConfig() { | ||
$("button").id("set-default-delays-to-2000").click(); | ||
Assert.assertEquals(2000, getActiveHideDelay(popover)); | ||
Assert.assertEquals(2000, getActiveFocusDelay(popover)); | ||
Assert.assertEquals(2000, getActiveHoverDelay(popover)); | ||
} | ||
|
||
@Test | ||
public void changeDefaults_refreshPage_checkPopoverConfig() { | ||
$("button").id("set-default-delays-to-5000").click(); | ||
getDriver().navigate().refresh(); | ||
popover = $(PopoverElement.class).first(); | ||
Assert.assertEquals(5000, getActiveHideDelay(popover)); | ||
Assert.assertEquals(5000, getActiveFocusDelay(popover)); | ||
Assert.assertEquals(5000, getActiveHoverDelay(popover)); | ||
} | ||
|
||
private int getActiveFocusDelay(PopoverElement popover) { | ||
return getOpenedStateControllerPropertyValue(popover, "__focusDelay"); | ||
} | ||
|
||
private int getActiveHoverDelay(PopoverElement popover) { | ||
return getOpenedStateControllerPropertyValue(popover, "__hoverDelay"); | ||
} | ||
|
||
private int getActiveHideDelay(PopoverElement popover) { | ||
return getOpenedStateControllerPropertyValue(popover, "__hideDelay"); | ||
} | ||
|
||
private int getOpenedStateControllerPropertyValue(PopoverElement popover, | ||
String propertyName) { | ||
var value = executeScript( | ||
"return arguments[0]._openedStateController[arguments[1]];", | ||
popover, propertyName); | ||
return ((Number) value).intValue(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
...din-popover-flow/src/main/resources/META-INF/resources/frontend/vaadin-popover/popover.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { Popover } from '@vaadin/popover/src/vaadin-popover.js'; | ||
|
||
const _window = window as any; | ||
_window.Vaadin ||= {}; | ||
_window.Vaadin.Flow ||= {}; | ||
_window.Vaadin.Flow.popover ||= {}; | ||
|
||
Object.assign(_window.Vaadin.Flow.popover, { | ||
setDefaultHideDelay: (hideDelay: number) => Popover.setDefaultHideDelay(hideDelay), | ||
setDefaultFocusDelay: (focusDelay: number) => Popover.setDefaultFocusDelay(focusDelay), | ||
setDefaultHoverDelay: (hoverDelay: number) => Popover.setDefaultHoverDelay(hoverDelay) | ||
}); | ||
|
||
const { defaultHideDelay, defaultFocusDelay, defaultHoverDelay } = _window.Vaadin.Flow.popover; | ||
|
||
if (defaultHideDelay) { | ||
Popover.setDefaultHideDelay(defaultHideDelay); | ||
} | ||
|
||
if (defaultFocusDelay) { | ||
Popover.setDefaultFocusDelay(defaultFocusDelay); | ||
} | ||
|
||
if (defaultHoverDelay) { | ||
Popover.setDefaultHoverDelay(defaultHoverDelay); | ||
} |