File tree Expand file tree Collapse file tree
apps/typegpu-docs/src/components/shaderhunt Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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 >
You can’t perform that action at this time.
0 commit comments