[{"data":1,"prerenderedAt":702},["ShallowReactive",2],{"blog-\u002Fblog\u002F2026\u002Fscreenshot-gallery-on-dialog":3,"blog-project-\u002Fblog\u002F2026\u002Fscreenshot-gallery-on-dialog":686,"i-lucide:link":698},{"id":4,"title":5,"art":6,"body":7,"date":682,"description":683,"draft":684,"extension":685,"image":686,"kind":687,"meta":688,"navigation":118,"ogImage":689,"path":690,"project":686,"seo":691,"slug":686,"stem":692,"tags":693,"translationKey":696,"updated":686,"__hash__":697},"blog_en\u002Fblog\u002F2026\u002Fscreenshot-gallery-on-dialog.md","A screenshot gallery on \u003Cdialog> instead of my own modal","\u002Fart\u002Fblog\u002Fgaleria-na-dialog.svg",{"type":8,"value":9,"toc":676},"minimark",[10,23,28,37,61,64,332,336,343,353,363,372,517,572,586,590,598,648,652,672],[11,12,13,14,18,19,22],"p",{},"The project pages in this portfolio have a screenshot gallery. A click on a screenshot opens a full-screen preview with arrows and a counter. Before, I always wrote windows like this myself: popups, modals, a dark background and code that listens for the Esc key. This time I wanted to try the native ",[15,16,17],"code",{},"\u003Cdialog>"," element. Semantics were important to me too – a window with content should be a window for the browser and the screen reader as well, not a plain ",[15,20,21],{},"\u003Cdiv>",".",[24,25,27],"h2",{"id":26},"what-the-browser-does-by-itself","What the browser does by itself",[11,29,30,32,33,36],{},[15,31,17],{}," has worked in all major browsers since March 2022. When you open it with ",[15,34,35],{},"showModal()",", the browser by itself:",[38,39,40,48,51,54],"ul",{},[41,42,43,44,47],"li",{},"shows the window above the whole page (in a separate layer, no fighting with ",[15,45,46],{},"z-index","),",[41,49,50],{},"blocks the rest of the page – you can't click or tab to the elements underneath,",[41,52,53],{},"closes the window with the Esc key,",[41,55,56,57,60],{},"adds a ",[15,58,59],{},"::backdrop"," that darkens the page by default.",[11,62,63],{},"That's everything I used to write myself in every project. A simplified skeleton looks like this:",[65,66,71],"pre",{"className":67,"code":68,"language":69,"meta":70,"style":70},"language-html shiki shiki-themes github-light github-dark","\u003Cbutton type=\"button\" id=\"open\">Enlarge screenshot\u003C\u002Fbutton>\n\n\u003Cdialog id=\"preview\" aria-label=\"Screenshot preview\">\n  \u003Cbutton type=\"button\" id=\"close\">Close\u003C\u002Fbutton>\n  \u003Cimg src=\"screenshot.webp\" alt=\"Project home page\">\n\u003C\u002Fdialog>\n\n\u003Cscript>\n  const preview = document.getElementById('preview')\n  document.getElementById('open').addEventListener('click', () => preview.showModal())\n  document.getElementById('close').addEventListener('click', () => preview.close())\n\u003C\u002Fscript>\n","html","",[15,72,73,113,120,145,173,199,209,214,224,253,292,323],{"__ignoreMap":70},[74,75,78,82,86,90,93,97,100,102,105,108,110],"span",{"class":76,"line":77},"line",1,[74,79,81],{"class":80},"sVt8B","\u003C",[74,83,85],{"class":84},"s9eBZ","button",[74,87,89],{"class":88},"sScJk"," type",[74,91,92],{"class":80},"=",[74,94,96],{"class":95},"sZZnC","\"button\"",[74,98,99],{"class":88}," id",[74,101,92],{"class":80},[74,103,104],{"class":95},"\"open\"",[74,106,107],{"class":80},">Enlarge screenshot\u003C\u002F",[74,109,85],{"class":84},[74,111,112],{"class":80},">\n",[74,114,116],{"class":76,"line":115},2,[74,117,119],{"emptyLinePlaceholder":118},true,"\n",[74,121,123,125,128,130,132,135,138,140,143],{"class":76,"line":122},3,[74,124,81],{"class":80},[74,126,127],{"class":84},"dialog",[74,129,99],{"class":88},[74,131,92],{"class":80},[74,133,134],{"class":95},"\"preview\"",[74,136,137],{"class":88}," aria-label",[74,139,92],{"class":80},[74,141,142],{"class":95},"\"Screenshot preview\"",[74,144,112],{"class":80},[74,146,148,151,153,155,157,159,161,163,166,169,171],{"class":76,"line":147},4,[74,149,150],{"class":80},"  \u003C",[74,152,85],{"class":84},[74,154,89],{"class":88},[74,156,92],{"class":80},[74,158,96],{"class":95},[74,160,99],{"class":88},[74,162,92],{"class":80},[74,164,165],{"class":95},"\"close\"",[74,167,168],{"class":80},">Close\u003C\u002F",[74,170,85],{"class":84},[74,172,112],{"class":80},[74,174,176,178,181,184,186,189,192,194,197],{"class":76,"line":175},5,[74,177,150],{"class":80},[74,179,180],{"class":84},"img",[74,182,183],{"class":88}," src",[74,185,92],{"class":80},[74,187,188],{"class":95},"\"screenshot.webp\"",[74,190,191],{"class":88}," alt",[74,193,92],{"class":80},[74,195,196],{"class":95},"\"Project home page\"",[74,198,112],{"class":80},[74,200,202,205,207],{"class":76,"line":201},6,[74,203,204],{"class":80},"\u003C\u002F",[74,206,127],{"class":84},[74,208,112],{"class":80},[74,210,212],{"class":76,"line":211},7,[74,213,119],{"emptyLinePlaceholder":118},[74,215,217,219,222],{"class":76,"line":216},8,[74,218,81],{"class":80},[74,220,221],{"class":84},"script",[74,223,112],{"class":80},[74,225,227,231,235,238,241,244,247,250],{"class":76,"line":226},9,[74,228,230],{"class":229},"szBVR","  const",[74,232,234],{"class":233},"sj4cs"," preview",[74,236,237],{"class":229}," =",[74,239,240],{"class":80}," document.",[74,242,243],{"class":88},"getElementById",[74,245,246],{"class":80},"(",[74,248,249],{"class":95},"'preview'",[74,251,252],{"class":80},")\n",[74,254,256,259,261,263,266,269,272,274,277,280,283,286,289],{"class":76,"line":255},10,[74,257,258],{"class":80},"  document.",[74,260,243],{"class":88},[74,262,246],{"class":80},[74,264,265],{"class":95},"'open'",[74,267,268],{"class":80},").",[74,270,271],{"class":88},"addEventListener",[74,273,246],{"class":80},[74,275,276],{"class":95},"'click'",[74,278,279],{"class":80},", () ",[74,281,282],{"class":229},"=>",[74,284,285],{"class":80}," preview.",[74,287,288],{"class":88},"showModal",[74,290,291],{"class":80},"())\n",[74,293,295,297,299,301,304,306,308,310,312,314,316,318,321],{"class":76,"line":294},11,[74,296,258],{"class":80},[74,298,243],{"class":88},[74,300,246],{"class":80},[74,302,303],{"class":95},"'close'",[74,305,268],{"class":80},[74,307,271],{"class":88},[74,309,246],{"class":80},[74,311,276],{"class":95},[74,313,279],{"class":80},[74,315,282],{"class":229},[74,317,285],{"class":80},[74,319,320],{"class":88},"close",[74,322,291],{"class":80},[74,324,326,328,330],{"class":76,"line":325},12,[74,327,204],{"class":80},[74,329,221],{"class":84},[74,331,112],{"class":80},[24,333,335],{"id":334},"what-i-had-to-add","What I had to add",[11,337,338,339,342],{},"In Vue the gallery is one component. The dialog has a ",[15,340,341],{},"ref",", and functions open and close it. The code below is a simplified version of that component. Still, the browser leaves a few things to the developer.",[11,344,345,349,350,22],{},[346,347,348],"strong",{},"Scrolling the page underneath."," An open dialog doesn't block page scrolling, so with the preview open, the mouse wheel moved the page in the background. I added a scroll lock while the preview is open. You can do the same in CSS alone: ",[15,351,352],{},"html:has(dialog[open]) { overflow: hidden; }",[11,354,355,358,359,362],{},[346,356,357],{},"A click on the background."," Esc closes the window, but a click next to the image doesn't. In Vue the ",[15,360,361],{},".self"," modifier was enough: I close the window only when the click was on the dialog itself, not on the image or a button inside.",[11,364,365,368,369,371],{},[346,366,367],{},"Returning focus."," After closing, focus should go back to the screenshot that opened the preview. Then a keyboard user is still in the same place on the page. Closing with the button, the Esc key and a click on the background all fire the same ",[15,370,320],{}," event, so I clean up in one place:",[65,373,377],{"className":374,"code":375,"language":376,"meta":70,"style":70},"language-js shiki shiki-themes github-light github-dark","const dialog = ref(null)\nconst opener = ref(null)\n\nfunction open(event) {\n  opener.value = event.currentTarget\n  dialog.value.showModal()\n  document.documentElement.style.overflow = 'hidden'\n}\n\n\u002F\u002F button, Esc and a click on the background – always the same close event\nfunction onClose() {\n  document.documentElement.style.overflow = ''\n  opener.value?.focus()\n}\n","js",[15,378,379,399,416,420,437,447,457,467,472,476,482,492,501,512],{"__ignoreMap":70},[74,380,381,384,387,389,392,394,397],{"class":76,"line":77},[74,382,383],{"class":229},"const",[74,385,386],{"class":233}," dialog",[74,388,237],{"class":229},[74,390,391],{"class":88}," ref",[74,393,246],{"class":80},[74,395,396],{"class":233},"null",[74,398,252],{"class":80},[74,400,401,403,406,408,410,412,414],{"class":76,"line":115},[74,402,383],{"class":229},[74,404,405],{"class":233}," opener",[74,407,237],{"class":229},[74,409,391],{"class":88},[74,411,246],{"class":80},[74,413,396],{"class":233},[74,415,252],{"class":80},[74,417,418],{"class":76,"line":122},[74,419,119],{"emptyLinePlaceholder":118},[74,421,422,425,428,430,434],{"class":76,"line":147},[74,423,424],{"class":229},"function",[74,426,427],{"class":88}," open",[74,429,246],{"class":80},[74,431,433],{"class":432},"siNPP","event",[74,435,436],{"class":80},") {\n",[74,438,439,442,444],{"class":76,"line":175},[74,440,441],{"class":80},"  opener.value ",[74,443,92],{"class":229},[74,445,446],{"class":80}," event.currentTarget\n",[74,448,449,452,454],{"class":76,"line":201},[74,450,451],{"class":80},"  dialog.value.",[74,453,288],{"class":88},[74,455,456],{"class":80},"()\n",[74,458,459,462,464],{"class":76,"line":211},[74,460,461],{"class":80},"  document.documentElement.style.overflow ",[74,463,92],{"class":229},[74,465,466],{"class":95}," 'hidden'\n",[74,468,469],{"class":76,"line":216},[74,470,471],{"class":80},"}\n",[74,473,474],{"class":76,"line":226},[74,475,119],{"emptyLinePlaceholder":118},[74,477,478],{"class":76,"line":255},[74,479,481],{"class":480},"sqY6-","\u002F\u002F button, Esc and a click on the background – always the same close event\n",[74,483,484,486,489],{"class":76,"line":294},[74,485,424],{"class":229},[74,487,488],{"class":88}," onClose",[74,490,491],{"class":80},"() {\n",[74,493,494,496,498],{"class":76,"line":325},[74,495,461],{"class":80},[74,497,92],{"class":229},[74,499,500],{"class":95}," ''\n",[74,502,504,507,510],{"class":76,"line":503},13,[74,505,506],{"class":80},"  opener.value?.",[74,508,509],{"class":88},"focus",[74,511,456],{"class":80},[74,513,515],{"class":76,"line":514},14,[74,516,471],{"class":80},[65,518,520],{"className":67,"code":519,"language":69,"meta":70,"style":70},"\u003Cdialog ref=\"dialog\" aria-label=\"Screenshot preview\" @close=\"onClose\" @click.self=\"dialog.close()\">\n  …\n\u003C\u002Fdialog>\n",[15,521,522,559,564],{"__ignoreMap":70},[74,523,524,526,528,530,532,535,537,539,541,544,546,549,552,554,557],{"class":76,"line":77},[74,525,81],{"class":80},[74,527,127],{"class":84},[74,529,391],{"class":88},[74,531,92],{"class":80},[74,533,534],{"class":95},"\"dialog\"",[74,536,137],{"class":88},[74,538,92],{"class":80},[74,540,142],{"class":95},[74,542,543],{"class":88}," @close",[74,545,92],{"class":80},[74,547,548],{"class":95},"\"onClose\"",[74,550,551],{"class":88}," @click.self",[74,553,92],{"class":80},[74,555,556],{"class":95},"\"dialog.close()\"",[74,558,112],{"class":80},[74,560,561],{"class":76,"line":115},[74,562,563],{"class":80},"  …\n",[74,565,566,568,570],{"class":76,"line":122},[74,567,204],{"class":80},[74,569,127],{"class":84},[74,571,112],{"class":80},[11,573,574,577,578,581,582,585],{},[346,575,576],{},"Arrows."," I handle the ← and → keys myself, with a ",[15,579,580],{},"keydown"," event on the dialog. The \"2 \u002F 5\" counter has ",[15,583,584],{},"aria-live=\"polite\"",", so a screen reader reads it after the image changes.",[24,587,589],{"id":588},"the-background-you-cant-see-here","The background you can't see here",[11,591,592,594,595,597],{},[15,593,59],{}," was my favourite part, because it darkens the page without an extra element. In this gallery, though, the preview covers the whole screen and has its own dark background, so I made ",[15,596,59],{}," transparent. In a smaller window, for example with a form, one rule is enough:",[65,599,603],{"className":600,"code":601,"language":602,"meta":70,"style":70},"language-css shiki shiki-themes github-light github-dark","dialog::backdrop {\n  background: rgb(0 0 0 \u002F 0.6);\n}\n","css",[15,604,605,614,644],{"__ignoreMap":70},[74,606,607,609,611],{"class":76,"line":77},[74,608,127],{"class":84},[74,610,59],{"class":88},[74,612,613],{"class":80}," {\n",[74,615,616,619,622,625,627,630,633,635,638,641],{"class":76,"line":115},[74,617,618],{"class":233},"  background",[74,620,621],{"class":80},": ",[74,623,624],{"class":233},"rgb",[74,626,246],{"class":80},[74,628,629],{"class":233},"0",[74,631,632],{"class":233}," 0",[74,634,632],{"class":233},[74,636,637],{"class":80}," \u002F ",[74,639,640],{"class":233},"0.6",[74,642,643],{"class":80},");\n",[74,645,646],{"class":76,"line":122},[74,647,471],{"class":80},[24,649,651],{"id":650},"what-came-out-of-it","What came out of it",[38,653,654,660,663,669],{},[41,655,656,657,659],{},"The native ",[15,658,17],{}," gives you a layer above the page, a blocked page underneath, Esc and a background for free – things I used to write myself.",[41,661,662],{},"Scrolling the page underneath, a click on the background and returning focus are up to you.",[41,664,665,666,668],{},"The ",[15,667,320],{}," event is one place to clean up, no matter how the window was closed.",[41,670,671],{},"The preview code is shorter than in my old modals, and the semantics are right from the start.",[673,674,675],"style",{},"html pre.shiki code .sVt8B, html code.shiki .sVt8B{--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .s9eBZ, html code.shiki .s9eBZ{--shiki-default:#22863A;--shiki-dark:#85E89D}html pre.shiki code .sScJk, html code.shiki .sScJk{--shiki-default:#6F42C1;--shiki-dark:#B392F0}html pre.shiki code .sZZnC, html code.shiki .sZZnC{--shiki-default:#032F62;--shiki-dark:#9ECBFF}html pre.shiki code .szBVR, html code.shiki .szBVR{--shiki-default:#D73A49;--shiki-dark:#F97583}html pre.shiki code .sj4cs, html code.shiki .sj4cs{--shiki-default:#005CC5;--shiki-dark:#79B8FF}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .siNPP, html code.shiki .siNPP{--shiki-default:#CA3500;--shiki-dark:#FFAB70}html pre.shiki code .sqY6-, html code.shiki .sqY6-{--shiki-default:#6A737D;--shiki-dark:#90A1B9}",{"title":70,"searchDepth":115,"depth":115,"links":677},[678,679,680,681],{"id":26,"depth":115,"text":27},{"id":334,"depth":115,"text":335},{"id":588,"depth":115,"text":589},{"id":650,"depth":115,"text":651},"2026-11-17","How I built a full-screen screenshot preview on the native \u003Cdialog> element – what the browser does by itself and what I had to add.",false,"md",null,"post",{},"\u002Fog\u002Fblog\u002Fgaleria-na-dialog-en.jpg","\u002Fblog\u002F2026\u002Fscreenshot-gallery-on-dialog",{"title":5,"description":683},"blog\u002F2026\u002Fscreenshot-gallery-on-dialog",[69,694,695],"vue","accessibility","galeria-na-dialog","TxX_Lwo9-rARqIzP0hK7QGS3F8TlMyTcRW0-I6WD4tQ",{"left":699,"top":699,"width":700,"height":700,"rotate":699,"vFlip":684,"hFlip":684,"body":701},0,24,"\u003Cg fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\">\u003Cpath d=\"M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71\"\u002F>\u003Cpath d=\"M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71\"\u002F>\u003C\u002Fg>",1794913591673]