@@ -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
@@ -387,8 +377,8 @@ export class ServerManagerView {
387377 onClick : this . activateLastTab . bind ( this , tabId ) ,
388378 index,
389379 tabId,
390- onHover : this . onHover . bind ( this , index ) ,
391- onHoverOut : this . onHoverOut . bind ( this , index ) ,
380+ onHover : this . onHover . bind ( this , tabId ) ,
381+ onHoverOut : this . onHoverOut . bind ( this , tabId ) ,
392382 webview : WebView . create ( {
393383 $root : this . $webviewsContainer ,
394384 rootWebContents,
@@ -540,20 +530,18 @@ export class ServerManagerView {
540530 } ) ;
541531 }
542532
543- onHover ( index : number ) : void {
544- // `this.$serverIconTooltip[index].textContent` already has realm name, so we are just
545- // removing the style.
546- this . $serverIconTooltip [ index ] . removeAttribute ( "style" ) ;
533+ onHover ( tabId : string ) : void {
534+ const tooltip = this . getServerTooltip ( tabId ) ! ;
535+ tooltip . removeAttribute ( "style" ) ;
547536 // To handle position of servers' tooltip due to scrolling of list of organizations
548537 // This could not be handled using CSS, hence the top of the tooltip is made same
549538 // as that of its parent element.
550- const { top} =
551- this . $serverIconTooltip [ index ] . parentElement ! . getBoundingClientRect ( ) ;
552- this . $serverIconTooltip [ index ] . style . top = `${ top } px` ;
539+ const { top} = tooltip . parentElement ! . getBoundingClientRect ( ) ;
540+ tooltip . style . top = `${ top } px` ;
553541 }
554542
555- onHoverOut ( index : number ) : void {
556- this . $serverIconTooltip [ index ] . style . display = "none" ;
543+ onHoverOut ( tabId : string ) : void {
544+ this . getServerTooltip ( tabId ) ! . style . display = "none" ;
557545 }
558546
559547 async openFunctionalTab ( tabProperties : {
@@ -821,6 +809,13 @@ export class ServerManagerView {
821809 return this . tabs . find ( ( tab ) => tab . properties . tabId === tabId ) ;
822810 }
823811
812+ getServerTooltip ( tabId : string ) : HTMLElement | undefined {
813+ const tooltipElement = this . $tabsContainer . querySelector (
814+ `.tab[data-tab-id="${ CSS . escape ( tabId ) } "] .server-tooltip` ,
815+ ) ;
816+ return tooltipElement instanceof HTMLElement ? tooltipElement : undefined ;
817+ }
818+
824819 addContextMenu ( $serverImg : HTMLElement ) : void {
825820 $serverImg . addEventListener ( "contextmenu" , async ( event ) => {
826821 event . preventDefault ( ) ;
0 commit comments