File tree Expand file tree Collapse file tree 3 files changed +22
-3
lines changed Expand file tree Collapse file tree 3 files changed +22
-3
lines changed Original file line number Diff line number Diff line change @@ -10,8 +10,9 @@ import "./clipboard.css";
10
10
* Setup trigger element to toggle showing / hiding clipboard element
11
11
* @param {Element } trigger
12
12
* @param {Element } clipboard
13
+ * @param {Array[Element] } closers array of elements that should close the clipboard if clicked
13
14
*/
14
- export function setupClipboard ( trigger , clipboard ) {
15
+ export function setupClipboard ( trigger , clipboard , closers ) {
15
16
const arrowElement = clipboard . querySelector ( ".arrow" ) ;
16
17
function updatePosition ( ) {
17
18
computePosition ( trigger , clipboard , {
@@ -53,5 +54,20 @@ export function setupClipboard(trigger, clipboard) {
53
54
trigger . classList . toggle ( "active" ) ;
54
55
updatePosition ( ) ;
55
56
e . preventDefault ( ) ;
57
+ e . stopPropagation ( ) ;
58
+ } ) ;
59
+
60
+ // If the clipboard is clicked this should not be passed to the desktop
61
+ clipboard . addEventListener ( "click" , ( e ) => {
62
+ e . stopPropagation ( ) ;
63
+ } ) ;
64
+ // Close the popup if we click outside it
65
+ closers . forEach ( ( el ) => {
66
+ el . addEventListener ( "click" , ( ) => {
67
+ if ( trigger . classList . contains ( "active" ) ) {
68
+ clipboard . classList . toggle ( "hidden" ) ;
69
+ trigger . classList . toggle ( "active" ) ;
70
+ }
71
+ } ) ;
56
72
} ) ;
57
73
}
Original file line number Diff line number Diff line change @@ -85,6 +85,7 @@ function connect() {
85
85
setupClipboard (
86
86
document . getElementById ( "clipboard-button" ) ,
87
87
document . getElementById ( "clipboard-container" ) ,
88
+ [ document . body , document . getElementsByTagName ( "canvas" ) [ 0 ] ] ,
88
89
) ;
89
90
}
90
91
Original file line number Diff line number Diff line change @@ -58,10 +58,12 @@ def test_desktop(browser):
58
58
# Open clipboard, enter random text, close clipboard
59
59
clipboard_text = str (uuid4 ())
60
60
page1 .get_by_role ("link" , name = "Remote Clipboard" ).click ()
61
- page1 .wait_for_selector ("#clipboard-text" )
61
+ expect ( page1 .locator ("#clipboard-text" )). to_be_visible ( )
62
62
page1 .locator ("#clipboard-text" ).click ()
63
63
page1 .locator ("#clipboard-text" ).fill (clipboard_text )
64
- page1 .get_by_role ("link" , name = "Remote Clipboard" ).click ()
64
+ # Click outside clipboard, it should be closed
65
+ page1 .locator ("canvas" ).click (position = {"x" : 969 , "y" : 273 })
66
+ expect (page1 .locator ("#clipboard-text" )).not_to_be_visible ()
65
67
66
68
# Exec into container to check clipboard contents
67
69
for engine in ["docker" , "podman" ]:
You can’t perform that action at this time.
0 commit comments