@@ -77,7 +77,6 @@ export class ServerManagerView {
7777 $reloadTooltip : HTMLElement ;
7878 $loadingTooltip : HTMLElement ;
7979 $settingsTooltip : HTMLElement ;
80- $serverIconTooltip : HTMLCollectionOf < HTMLElement > ;
8180 $backTooltip : HTMLElement ;
8281 $dndTooltip : HTMLElement ;
8382 $sidebar : Element ;
@@ -106,15 +105,6 @@ export class ServerManagerView {
106105 this . $loadingTooltip = $actionsContainer . querySelector ( "#loading-tooltip" ) ! ;
107106 this . $settingsTooltip =
108107 $actionsContainer . querySelector ( "#setting-tooltip" ) ! ;
109-
110- // TODO: This should have been querySelector but the problem is that
111- // querySelector doesn't return elements not present in dom whereas somehow
112- // getElementsByClassName does. To fix this we need to call this after this.initTabs
113- // is called in this.init.
114- // eslint-disable-next-line unicorn/prefer-query-selector
115- this . $serverIconTooltip = document . getElementsByClassName (
116- "server-tooltip" ,
117- ) as HTMLCollectionOf < HTMLElement > ;
118108 this . $backTooltip = $actionsContainer . querySelector ( "#back-tooltip" ) ! ;
119109 this . $dndTooltip = $actionsContainer . querySelector ( "#dnd-tooltip" ) ! ;
120110
@@ -393,8 +383,8 @@ export class ServerManagerView {
393383 index,
394384 tabId,
395385 serverId : server . id ,
396- onHover : this . onHover . bind ( this , index ) ,
397- onHoverOut : this . onHoverOut . bind ( this , index ) ,
386+ onHover : this . onHover . bind ( this , tabId ) ,
387+ onHoverOut : this . onHoverOut . bind ( this , tabId ) ,
398388 webview : WebView . create ( {
399389 $root : this . $webviewsContainer ,
400390 rootWebContents,
@@ -546,20 +536,18 @@ export class ServerManagerView {
546536 } ) ;
547537 }
548538
549- onHover ( index : number ) : void {
550- // `this.$serverIconTooltip[index].textContent` already has realm name, so we are just
551- // removing the style.
552- this . $serverIconTooltip [ index ] . removeAttribute ( "style" ) ;
539+ onHover ( tabId : string ) : void {
540+ const tooltip = this . getServerTooltip ( tabId ) ! ;
541+ tooltip . removeAttribute ( "style" ) ;
553542 // To handle position of servers' tooltip due to scrolling of list of organizations
554543 // This could not be handled using CSS, hence the top of the tooltip is made same
555544 // as that of its parent element.
556- const { top} =
557- this . $serverIconTooltip [ index ] . parentElement ! . getBoundingClientRect ( ) ;
558- this . $serverIconTooltip [ index ] . style . top = `${ top } px` ;
545+ const { top} = tooltip . parentElement ! . getBoundingClientRect ( ) ;
546+ tooltip . style . top = `${ top } px` ;
559547 }
560548
561- onHoverOut ( index : number ) : void {
562- this . $serverIconTooltip [ index ] . style . display = "none" ;
549+ onHoverOut ( tabId : string ) : void {
550+ this . getServerTooltip ( tabId ) ! . style . display = "none" ;
563551 }
564552
565553 async openFunctionalTab ( tabProperties : {
@@ -835,6 +823,13 @@ export class ServerManagerView {
835823 return this . tabs . find ( ( tab ) => tab . properties . tabId === tabId ) ;
836824 }
837825
826+ getServerTooltip ( tabId : string ) : HTMLElement | undefined {
827+ const tooltipElement = this . $tabsContainer . querySelector (
828+ `.tab[data-tab-id="${ CSS . escape ( tabId ) } "] .server-tooltip` ,
829+ ) ;
830+ return tooltipElement instanceof HTMLElement ? tooltipElement : undefined ;
831+ }
832+
838833 addContextMenu ( $serverImg : HTMLElement ) : void {
839834 $serverImg . addEventListener ( "contextmenu" , async ( event ) => {
840835 event . preventDefault ( ) ;
0 commit comments