Skip to content

Commit 475b533

Browse files
committed
fixup! feat(aria/menu): add examples for aria menu
1 parent 803ffd6 commit 475b533

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

src/components-examples/aria/menu/menu-example.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121
border: 1px solid color-mix(in srgb, var(--mat-sys-outline) 40%, transparent);
2222
}
2323

24+
.example-menu[popover] {
25+
position: absolute;
26+
}
27+
2428
.example-menu-bar {
2529
display: flex;
2630
cursor: pointer;

src/components-examples/aria/menu/simple-menu.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,21 @@ export class SimpleMenu {
2929
const parentEl = parent.element;
3030
const parentRect = parentEl.getBoundingClientRect();
3131

32+
const scrollX = window.scrollX;
33+
const scrollY = window.scrollY;
34+
35+
const top = parentRect.y + scrollY - 5;
36+
const bottom = parentRect.y + scrollY + parentRect.height + 6;
37+
3238
if (parent.parent instanceof MenuBar) {
33-
this.menu.element.style.left = `${parentRect.left}px`;
34-
this.menu.element.style.top = `${parentRect.bottom + 6}px`;
39+
this.menu.element.style.left = `${parentRect.left + scrollX}px`;
40+
this.menu.element.style.top = `${bottom}px`;
3541
} else if (parent instanceof MenuTrigger) {
36-
this.menu.element.style.left = `${parentRect.left}px`;
37-
this.menu.element.style.top = `${parentRect.bottom + 2}px`;
42+
this.menu.element.style.left = `${parentRect.left + scrollX}px`;
43+
this.menu.element.style.top = `${parentRect.bottom + scrollY + 2}px`;
3844
} else {
39-
this.menu.element.style.left = `${parentRect.right + 6}px`;
40-
this.menu.element.style.top = `${parentRect.top - 5}px`;
45+
this.menu.element.style.left = `${parentRect.right + scrollX + 6}px`;
46+
this.menu.element.style.top = `${top}px`;
4147
}
4248
}
4349
}

0 commit comments

Comments
 (0)