From 15fbf20a786a807348f330282e7d67b11e7d83d6 Mon Sep 17 00:00:00 2001 From: Yashi Date: Thu, 24 Sep 2026 22:26:32 +0530 Subject: [PATCH] fix: make image modal keyboard accessible and manage focus - Wrap Markdown images in native button triggers (.md__image-trigger) with aria-label - Initialize triggers with disabled attribute to keep linked images out of initial tab order - Enable standalone triggers on DOMContentLoaded and unwrap triggers inside anchor links - Add focus trap and Escape key listener within modal dialog - Move focus to close button when modal opens and restore focus to trigger on close - Add fallback focus restoration for raw content images - Add focus-visible indicator styling for trigger and close buttons Fixes #1258 Signed-off-by: Yashi --- assets/scss/_image-modal_project.scss | 31 ++- layouts/_default/_markup/render-image.html | 20 +- layouts/partials/image-modal.html | 281 ++++++++++++++++----- 3 files changed, 262 insertions(+), 70 deletions(-) diff --git a/assets/scss/_image-modal_project.scss b/assets/scss/_image-modal_project.scss index 0c8f72ffd51c..f08b918b49cc 100644 --- a/assets/scss/_image-modal_project.scss +++ b/assets/scss/_image-modal_project.scss @@ -3,6 +3,30 @@ cursor: pointer; } +/* Native button used as the keyboard-accessible image trigger */ +.md__image-trigger { + display: block; + width: 100%; + margin: 0; + padding: 0; + border: 0; + background: transparent; + color: inherit; + font: inherit; + text-align: inherit; + cursor: pointer; + border-radius: 4px; + + &:disabled { + cursor: default; + } + + &:focus-visible { + outline: 2px solid #00b39f; + outline-offset: 4px; + } +} + /* The Modal (background) */ .modal { display: none; @@ -48,6 +72,11 @@ overflow: hidden; border: 0; z-index: 99; + + &:focus-visible { + outline: 2px solid #00b39f; + outline-offset: 2px; + } } .modal-close::after { @@ -56,7 +85,7 @@ top: 0.2em; left: 0.1em; text-indent: 0; - content: "\00D7" + content: "\00D7"; } .modal-close:hover, diff --git a/layouts/_default/_markup/render-image.html b/layouts/_default/_markup/render-image.html index 34af92caad01..c7f62b511a47 100644 --- a/layouts/_default/_markup/render-image.html +++ b/layouts/_default/_markup/render-image.html @@ -31,14 +31,18 @@
{{- with $img }} {{- $webp := .Process "webp q85" }} - - - {{ $alt }} - + {{- else }} - {{ $alt }} + {{- end }}
diff --git a/layouts/partials/image-modal.html b/layouts/partials/image-modal.html index 72650e62a27f..0c539924fb21 100644 --- a/layouts/partials/image-modal.html +++ b/layouts/partials/image-modal.html @@ -1,61 +1,220 @@ - - - \ No newline at end of file + + + + \ No newline at end of file