@@ -122,6 +122,36 @@ function RemoteFunctions(config) {
122
122
) ;
123
123
}
124
124
125
+ // Checks if an element is actually visible to the user (not hidden, collapsed, or off-screen)
126
+ function isElementVisible ( element ) {
127
+ // Check if element has zero dimensions (indicates it's hidden or collapsed)
128
+ const rect = element . getBoundingClientRect ( ) ;
129
+ if ( rect . width === 0 && rect . height === 0 ) {
130
+ return false ;
131
+ }
132
+
133
+ // Check computed styles for visibility
134
+ const computedStyle = window . getComputedStyle ( element ) ;
135
+ if ( computedStyle . display === 'none' ||
136
+ computedStyle . visibility === 'hidden' ||
137
+ computedStyle . opacity === '0' ) {
138
+ return false ;
139
+ }
140
+
141
+ // Check if any parent element is hidden
142
+ let parent = element . parentElement ;
143
+ while ( parent && parent !== document . body ) {
144
+ const parentStyle = window . getComputedStyle ( parent ) ;
145
+ if ( parentStyle . display === 'none' ||
146
+ parentStyle . visibility === 'hidden' ) {
147
+ return false ;
148
+ }
149
+ parent = parent . parentElement ;
150
+ }
151
+
152
+ return true ;
153
+ }
154
+
125
155
// returns the distance from the top of the closest relatively positioned parent element
126
156
function getDocumentOffsetTop ( element ) {
127
157
return element . offsetTop + ( element . offsetParent ? getDocumentOffsetTop ( element . offsetParent ) : 0 ) ;
@@ -656,11 +686,11 @@ function RemoteFunctions(config) {
656
686
return ;
657
687
}
658
688
659
- // this check because when there is no element on the visible viewport , we don't want to show the box
689
+ // this check because when there is no element visible to the user , we don't want to show the box
660
690
// for ex: when user clicks on a 'x' button and the button is responsible to hide a panel
661
691
// then clicking on that button shouldn't show the more options box
662
- const elemBounds = this . element . getBoundingClientRect ( ) ;
663
- if ( elemBounds . height === 0 && elemBounds . width === 0 ) {
692
+ // also covers cases where elements are inside closed/collapsed menus
693
+ if ( ! isElementVisible ( this . element ) ) {
664
694
return ;
665
695
}
666
696
@@ -868,11 +898,11 @@ function RemoteFunctions(config) {
868
898
return ;
869
899
}
870
900
871
- // this check because when there is no element on the visible viewport , we don't want to show the box
901
+ // this check because when there is no element visible to the user , we don't want to show the box
872
902
// for ex: when user clicks on a 'x' button and the button is responsible to hide a panel
873
903
// then clicking on that button shouldn't show the more options box
874
- const elemBounds = this . element . getBoundingClientRect ( ) ;
875
- if ( elemBounds . height === 0 && elemBounds . width === 0 ) {
904
+ // also covers cases where elements are inside closed/collapsed menus
905
+ if ( ! isElementVisible ( this . element ) ) {
876
906
return ;
877
907
}
878
908
@@ -1356,13 +1386,25 @@ function RemoteFunctions(config) {
1356
1386
}
1357
1387
}
1358
1388
1359
- _nodeMoreOptionsBox = new NodeMoreOptionsBox ( element ) ;
1389
+ // make sure that the element is actually visible to the user
1390
+ if ( isElementVisible ( element ) ) {
1391
+ _nodeMoreOptionsBox = new NodeMoreOptionsBox ( element ) ;
1360
1392
1361
- // show the info box when a DOM element is selected
1362
- if ( _nodeInfoBox ) {
1363
- _nodeInfoBox . remove ( ) ;
1393
+ // show the info box when a DOM element is selected
1394
+ if ( _nodeInfoBox ) {
1395
+ _nodeInfoBox . remove ( ) ;
1396
+ }
1397
+ _nodeInfoBox = new NodeInfoBox ( element , true ) ; // true means that the element was selected
1398
+ } else {
1399
+ // Element is hidden, so don't show UI boxes but still apply visual styling
1400
+ _nodeMoreOptionsBox = null ;
1401
+
1402
+ // Remove any existing info box since the element is not visible
1403
+ if ( _nodeInfoBox ) {
1404
+ _nodeInfoBox . remove ( ) ;
1405
+ _nodeInfoBox = null ;
1406
+ }
1364
1407
}
1365
- _nodeInfoBox = new NodeInfoBox ( element , true ) ; // true means that the element was selected
1366
1408
1367
1409
element . _originalOutline = element . style . outline ;
1368
1410
element . style . outline = "1px solid #4285F4" ;
0 commit comments