Skip to content

Commit 2bc0067

Browse files
authored
docs: Fix challenges popup (again) (#2143)
1 parent d2eec05 commit 2bc0067

1 file changed

Lines changed: 29 additions & 3 deletions

File tree

apps/typegpu-docs/src/components/shaderhunt/ChallengesSignupPopover.astro

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,38 @@
9898

9999
const dialogBoxes = Array.from(popovers).map((popover) => new DialogBox(popover));
100100

101+
function isElementVisible(element: Element): boolean {
102+
// Check if the element or any of its ancestors have display: none
103+
let current: Element | null = element;
104+
while (current) {
105+
const style = window.getComputedStyle(current);
106+
if (style.display === 'none') {
107+
return false;
108+
}
109+
current = current.parentElement;
110+
}
111+
return true;
112+
}
113+
114+
function getVisibleDialogBox(): DialogBox | undefined {
115+
// Find a dialog box whose link element is actually visible
116+
for (let i = 0; i < dialogBoxes.length; i++) {
117+
const popover = popovers[i];
118+
const linkElement = popover?.querySelector('a');
119+
if (linkElement && isElementVisible(linkElement)) {
120+
return dialogBoxes[i];
121+
}
122+
}
123+
// Fallback to first dialog box if none are visibly rendered
124+
return dialogBoxes[0];
125+
}
126+
101127
// Check if URL hash indicates popover should be open
102128
if (window.location.hash === '#challenges-signup') {
103-
const firstDialogBox = dialogBoxes[0]
104-
if (!firstDialogBox) {
129+
const visibleDialogBox = getVisibleDialogBox();
130+
if (!visibleDialogBox) {
105131
throw new Error('Expected at least one dialog box');
106132
}
107-
firstDialogBox.dialogElement.showModal();
133+
visibleDialogBox.dialogElement.showModal();
108134
}
109135
</script>

0 commit comments

Comments
 (0)