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";
1010 * Setup trigger element to toggle showing / hiding clipboard element
1111 * @param {Element } trigger
1212 * @param {Element } clipboard
13+ * @param {Array[Element] } closers array of elements that should close the clipboard if clicked
1314 */
14- export function setupClipboard ( trigger , clipboard ) {
15+ export function setupClipboard ( trigger , clipboard , closers ) {
1516 const arrowElement = clipboard . querySelector ( ".arrow" ) ;
1617 function updatePosition ( ) {
1718 computePosition ( trigger , clipboard , {
@@ -53,5 +54,20 @@ export function setupClipboard(trigger, clipboard) {
5354 trigger . classList . toggle ( "active" ) ;
5455 updatePosition ( ) ;
5556 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+ } ) ;
5672 } ) ;
5773}
Original file line number Diff line number Diff line change @@ -85,6 +85,7 @@ function connect() {
8585 setupClipboard (
8686 document . getElementById ( "clipboard-button" ) ,
8787 document . getElementById ( "clipboard-container" ) ,
88+ [ document . body , document . getElementsByTagName ( "canvas" ) [ 0 ] ] ,
8889 ) ;
8990}
9091
Original file line number Diff line number Diff line change @@ -58,10 +58,12 @@ def test_desktop(browser):
5858 # Open clipboard, enter random text, close clipboard
5959 clipboard_text = str (uuid4 ())
6060 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 ( )
6262 page1 .locator ("#clipboard-text" ).click ()
6363 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 ()
6567
6668 # Exec into container to check clipboard contents
6769 for engine in ["docker" , "podman" ]:
You can’t perform that action at this time.
0 commit comments