-
Notifications
You must be signed in to change notification settings - Fork 161
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: fix shortcuts when listenOn is a dialog (#10264)
This makes it possible for a component to specify a client side only element that should be used for listening keydown events on when the component is setup as the listenOn target for a Shortcut. This is needed for components like Vaadin Dialog which transport the dialog contents inside an overlay that only exists on the client side and thus breaks shortcut event handling. Related to #7799, vaadin/vaadin-dialog#229
- Loading branch information
Showing
9 changed files
with
637 additions
and
4 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -27,3 +27,4 @@ | |
public class NativeButtonElement extends TestBenchElement { | ||
|
||
} | ||
|
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
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
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
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
45 changes: 45 additions & 0 deletions
45
.../test-root-context/src/main/java/com/vaadin/flow/uitest/ui/ComplexDialogShortcutView.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,45 @@ | ||
package com.vaadin.flow.uitest.ui; | ||
|
||
import com.vaadin.flow.component.Shortcuts; | ||
import com.vaadin.flow.component.html.Div; | ||
import com.vaadin.flow.router.PreserveOnRefresh; | ||
import com.vaadin.flow.router.Route; | ||
|
||
@PreserveOnRefresh | ||
@Route(value = "com.vaadin.flow.uitest.ui.ComplexDialogShortcutView") | ||
public class ComplexDialogShortcutView extends DialogShortcutView { | ||
|
||
public static final String OVERLAY_ID = "overlay"; | ||
private Div fakeOverlayElement; | ||
|
||
public ComplexDialogShortcutView() { | ||
} | ||
|
||
@Override | ||
public void open(Dialog dialog) { | ||
super.open(dialog); | ||
// the shortcut listener is not added yet, add the element locator data | ||
final String overlayId = OVERLAY_ID + dialog.index; | ||
final String overlayFetchJS = "document.getElementById('" + overlayId | ||
+ "')"; | ||
Shortcuts.setShortcutListenOnElement(overlayFetchJS, | ||
dialog); | ||
// simulate a fake overlay element | ||
fakeOverlayElement = new Div(); | ||
fakeOverlayElement.setId(overlayId); | ||
getUI().ifPresent(ui -> ui.add(fakeOverlayElement)); | ||
// transport the dialog contents to overlay element | ||
dialog.getElement().executeJs( | ||
overlayFetchJS + ".appendChild(this.firstElementChild);"); | ||
dialog.content.getStyle().set("position", "fixed").set("inset", | ||
"calc(50% + " + (dialog.index * 100) + "px)"); | ||
} | ||
|
||
@Override | ||
public void close(Dialog dialog) { | ||
super.close(dialog); | ||
|
||
fakeOverlayElement.getUI() | ||
.ifPresent(ui -> ui.remove(fakeOverlayElement)); | ||
} | ||
} |
Oops, something went wrong.