Skip to content

Commit 8e206cd

Browse files
authored
HParams: Change strategy for positioning context menus (#6470)
## Motivation for features / changes We have been creating context menus using our custom modal component. The custom modal component had the height of the header hard coded as a vertical offset, however, the header is not the same height in internal tensorboard so the offset needs to be set programatically. ## Screenshots of UI changes (or N/A) In OSS ![image](https://github.com/tensorflow/tensorboard/assets/78179109/f52aad36-30bc-453f-88c8-7630d00e1495) In Internal ![image](https://github.com/tensorflow/tensorboard/assets/78179109/30ac0f78-99bb-4dbb-9484-5fbcdf839b32)
1 parent a27fb1d commit 8e206cd

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

tensorboard/webapp/widgets/custom_modal/custom_modal_component.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
ElementRef,
2121
HostListener,
2222
OnInit,
23+
ViewContainerRef,
2324
} from '@angular/core';
2425
import {BehaviorSubject} from 'rxjs';
2526

@@ -40,7 +41,6 @@ export interface ModalContent {
4041
`
4142
:host {
4243
position: fixed;
43-
top: -64px; /* The height of the top bar */
4444
left: 0;
4545
z-index: 9001;
4646
}
@@ -62,6 +62,8 @@ export class CustomModalComponent implements OnInit {
6262

6363
private clickListener: () => void = this.close.bind(this);
6464

65+
constructor(private readonly viewRef: ViewContainerRef) {}
66+
6567
ngOnInit() {
6668
this.visible$.subscribe((visible) => {
6769
// Wait until after the next browser frame.
@@ -76,6 +78,12 @@ export class CustomModalComponent implements OnInit {
7678
}
7779

7880
public openAtPosition(position: {x: number; y: number}) {
81+
const root = this.viewRef.element.nativeElement;
82+
const top = root.getBoundingClientRect().top;
83+
if (top !== 0) {
84+
root.style.top = top * -1 + root.offsetTop + 'px';
85+
}
86+
7987
this.content.nativeElement.style.left = position.x + 'px';
8088
this.content.nativeElement.style.top = position.y + 'px';
8189
this.visible$.next(true);

0 commit comments

Comments
 (0)