a11y: fix WCAG 2.2 AA and Uutilsynet audit findings
Tag autocomplete combobox pattern (WCAG 2.1.1, 4.1.2, 4.1.3): - Add role="combobox", aria-expanded, aria-haspopup to tag input - Implement arrow key navigation (up/down) through suggestions - Add Space key support alongside Enter for selecting tags - Manage aria-activedescendant to track highlighted option - Add Escape to close suggestions - Add aria-live="polite" status region announcing suggestion count - Add aria-selected state on options - Tag suggestions now have stable IDs for activedescendant Focus visibility (WCAG 2.4.7): - Remove outline:none on tag suggestions, replace with visible 2px solid outline on :focus-visible Contrast (WCAG 1.4.3): - Replace opacity:0.5 on disabled rows with muted text color and strikethrough on username (maintains 4.5:1 ratio) Structure and semantics (WCAG 1.3.1): - Fix heading hierarchy H1→H3 skip in import.html (now H2) - Replace <nav> misuse for fave actions with div[role="group"] - Add aria-label="Administrasjonsmeny" to admin dashboard nav - Wrap admin users table in responsive scrollable region - Remove redundant "Bilde for:" prefix from image alt text - Make error page H1 descriptive: "Feil 404: Ikke funnet" - Add .sr-only utility class for screen-reader-only content - Add hreflang="en" to English-language external link Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
3a3b526a95
commit
a9d84a4de8
14 changed files with 171 additions and 41 deletions
|
|
@ -1,5 +1,18 @@
|
||||||
/* Favoritter — custom styles on top of Pico CSS */
|
/* Favoritter — custom styles on top of Pico CSS */
|
||||||
|
|
||||||
|
/* Visually hidden, accessible to screen readers */
|
||||||
|
.sr-only {
|
||||||
|
position: absolute;
|
||||||
|
width: 1px;
|
||||||
|
height: 1px;
|
||||||
|
padding: 0;
|
||||||
|
margin: -1px;
|
||||||
|
overflow: hidden;
|
||||||
|
clip: rect(0, 0, 0, 0);
|
||||||
|
white-space: nowrap;
|
||||||
|
border: 0;
|
||||||
|
}
|
||||||
|
|
||||||
/* Skip navigation link for accessibility */
|
/* Skip navigation link for accessibility */
|
||||||
.skip-link {
|
.skip-link {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
|
|
@ -143,9 +156,14 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
.tag-suggestion:hover,
|
.tag-suggestion:hover,
|
||||||
.tag-suggestion:focus {
|
.tag-suggestion:focus-visible {
|
||||||
|
background: var(--pico-primary-focus);
|
||||||
|
outline: 2px solid var(--pico-primary);
|
||||||
|
outline-offset: -2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tag-suggestion[aria-selected="true"] {
|
||||||
background: var(--pico-primary-focus);
|
background: var(--pico-primary-focus);
|
||||||
outline: none;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Fave detail actions */
|
/* Fave detail actions */
|
||||||
|
|
@ -177,7 +195,11 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
.disabled-row {
|
.disabled-row {
|
||||||
opacity: 0.5;
|
color: var(--pico-muted-color);
|
||||||
|
}
|
||||||
|
|
||||||
|
.disabled-row td:first-child {
|
||||||
|
text-decoration: line-through;
|
||||||
}
|
}
|
||||||
|
|
||||||
.inline-input {
|
.inline-input {
|
||||||
|
|
@ -188,6 +210,11 @@
|
||||||
font-size: 0.875rem;
|
font-size: 0.875rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Responsive admin tables */
|
||||||
|
.table-responsive {
|
||||||
|
overflow-x: auto;
|
||||||
|
}
|
||||||
|
|
||||||
/* Respect reduced motion preference */
|
/* Respect reduced motion preference */
|
||||||
@media (prefers-reduced-motion: reduce) {
|
@media (prefers-reduced-motion: reduce) {
|
||||||
*, *::before, *::after {
|
*, *::before, *::after {
|
||||||
|
|
|
||||||
|
|
@ -22,18 +22,42 @@
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Focus management after HTMX content swaps for accessibility.
|
// Update aria-expanded and announce suggestion count after HTMX swaps.
|
||||||
document.body.addEventListener("htmx:afterSwap", function (event) {
|
document.body.addEventListener("htmx:afterSwap", function (event) {
|
||||||
var target = event.detail.target;
|
var target = event.detail.target;
|
||||||
if (target) {
|
if (!target) return;
|
||||||
var autoFocus = target.querySelector("[autofocus]");
|
|
||||||
if (autoFocus) {
|
// Focus management: if swapped content has autofocus, focus it.
|
||||||
autoFocus.focus();
|
var autoFocus = target.querySelector("[autofocus]");
|
||||||
|
if (autoFocus) {
|
||||||
|
autoFocus.focus();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Tag suggestions: update combobox state.
|
||||||
|
if (target.id === "tag-suggestions") {
|
||||||
|
var input = document.getElementById("tags");
|
||||||
|
var items = target.querySelectorAll("[role='option']");
|
||||||
|
var count = items.length;
|
||||||
|
|
||||||
|
if (input) {
|
||||||
|
input.setAttribute("aria-expanded", count > 0 ? "true" : "false");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Announce suggestion count to screen readers.
|
||||||
|
var status = document.getElementById("tag-status");
|
||||||
|
if (status) {
|
||||||
|
status.textContent = count > 0
|
||||||
|
? count + " forslag tilgjengelig"
|
||||||
|
: "";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reset active descendant tracking.
|
||||||
|
activeIndex = -1;
|
||||||
|
clearActiveDescendant();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// After a successful HTMX DELETE, redirect if the element has a data-redirect attribute.
|
// After a successful HTMX DELETE, redirect if the element has a data-redirect.
|
||||||
document.body.addEventListener("htmx:afterRequest", function (event) {
|
document.body.addEventListener("htmx:afterRequest", function (event) {
|
||||||
if (event.detail.successful && event.detail.verb === "delete") {
|
if (event.detail.successful && event.detail.verb === "delete") {
|
||||||
var redirect = event.detail.elt.getAttribute("data-redirect");
|
var redirect = event.detail.elt.getAttribute("data-redirect");
|
||||||
|
|
@ -43,25 +67,97 @@
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Tag autocomplete: add a selected tag to the tag input.
|
// --- Tag autocomplete combobox pattern ---
|
||||||
|
var activeIndex = -1;
|
||||||
|
|
||||||
|
// Handle keyboard navigation in the tag suggestions listbox.
|
||||||
|
document.addEventListener("keydown", function (event) {
|
||||||
|
var input = document.getElementById("tags");
|
||||||
|
if (!input || document.activeElement !== input) return;
|
||||||
|
|
||||||
|
var listbox = document.getElementById("tag-suggestions");
|
||||||
|
if (!listbox) return;
|
||||||
|
var items = listbox.querySelectorAll("[role='option']");
|
||||||
|
if (items.length === 0) return;
|
||||||
|
|
||||||
|
switch (event.key) {
|
||||||
|
case "ArrowDown":
|
||||||
|
event.preventDefault();
|
||||||
|
activeIndex = Math.min(activeIndex + 1, items.length - 1);
|
||||||
|
setActiveDescendant(items);
|
||||||
|
break;
|
||||||
|
case "ArrowUp":
|
||||||
|
event.preventDefault();
|
||||||
|
activeIndex = Math.max(activeIndex - 1, 0);
|
||||||
|
setActiveDescendant(items);
|
||||||
|
break;
|
||||||
|
case "Enter":
|
||||||
|
if (activeIndex >= 0 && activeIndex < items.length) {
|
||||||
|
event.preventDefault();
|
||||||
|
var tagName = items[activeIndex].textContent.trim();
|
||||||
|
addTag(null, tagName);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case " ":
|
||||||
|
if (activeIndex >= 0 && activeIndex < items.length) {
|
||||||
|
event.preventDefault();
|
||||||
|
var tagName2 = items[activeIndex].textContent.trim();
|
||||||
|
addTag(null, tagName2);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "Escape":
|
||||||
|
closeSuggestions();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
function setActiveDescendant(items) {
|
||||||
|
for (var i = 0; i < items.length; i++) {
|
||||||
|
items[i].setAttribute("aria-selected", i === activeIndex ? "true" : "false");
|
||||||
|
}
|
||||||
|
var input = document.getElementById("tags");
|
||||||
|
if (input && activeIndex >= 0) {
|
||||||
|
var activeItem = items[activeIndex];
|
||||||
|
if (!activeItem.id) {
|
||||||
|
activeItem.id = "tag-option-" + activeIndex;
|
||||||
|
}
|
||||||
|
input.setAttribute("aria-activedescendant", activeItem.id);
|
||||||
|
activeItem.scrollIntoView({ block: "nearest" });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function clearActiveDescendant() {
|
||||||
|
var input = document.getElementById("tags");
|
||||||
|
if (input) {
|
||||||
|
input.removeAttribute("aria-activedescendant");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function closeSuggestions() {
|
||||||
|
var listbox = document.getElementById("tag-suggestions");
|
||||||
|
if (listbox) {
|
||||||
|
while (listbox.firstChild) {
|
||||||
|
listbox.removeChild(listbox.firstChild);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var input = document.getElementById("tags");
|
||||||
|
if (input) {
|
||||||
|
input.setAttribute("aria-expanded", "false");
|
||||||
|
}
|
||||||
|
activeIndex = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add a selected tag to the tag input.
|
||||||
window.addTag = function (element, tagName) {
|
window.addTag = function (element, tagName) {
|
||||||
var input = document.getElementById("tags");
|
var input = document.getElementById("tags");
|
||||||
if (!input) return;
|
if (!input) return;
|
||||||
|
|
||||||
var parts = input.value.split(",").map(function (s) { return s.trim(); });
|
var parts = input.value.split(",").map(function (s) { return s.trim(); });
|
||||||
// Replace the last (incomplete) segment with the selected tag.
|
|
||||||
parts[parts.length - 1] = tagName;
|
parts[parts.length - 1] = tagName;
|
||||||
// Add a trailing separator so the user can keep typing.
|
|
||||||
input.value = parts.join(", ") + ", ";
|
input.value = parts.join(", ") + ", ";
|
||||||
input.focus();
|
input.focus();
|
||||||
|
|
||||||
// Clear suggestions by removing all child elements.
|
closeSuggestions();
|
||||||
var suggestions = document.getElementById("tag-suggestions");
|
|
||||||
if (suggestions) {
|
|
||||||
while (suggestions.firstChild) {
|
|
||||||
suggestions.removeChild(suggestions.firstChild);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
function getCookie(name) {
|
function getCookie(name) {
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,7 @@
|
||||||
<p>
|
<p>
|
||||||
<small>
|
<small>
|
||||||
Drevet av <a href="https://kode.naiv.no/olemd/favoritter" target="_blank" rel="noopener">Favoritter</a>
|
Drevet av <a href="https://kode.naiv.no/olemd/favoritter" target="_blank" rel="noopener">Favoritter</a>
|
||||||
— fri programvare under <a href="https://www.gnu.org/licenses/agpl-3.0.html" target="_blank" rel="noopener">AGPL-3.0</a>
|
— fri programvare under <a href="https://www.gnu.org/licenses/agpl-3.0.html" target="_blank" rel="noopener" hreflang="en">AGPL-3.0</a>
|
||||||
</small>
|
</small>
|
||||||
</p>
|
</p>
|
||||||
</footer>
|
</footer>
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@
|
||||||
</article>
|
</article>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<nav>
|
<nav aria-label="Administrasjonsmeny">
|
||||||
<ul>
|
<ul>
|
||||||
<li><a href="{{basePath}}/admin/users" role="button" class="outline">Brukere</a></li>
|
<li><a href="{{basePath}}/admin/users" role="button" class="outline">Brukere</a></li>
|
||||||
<li><a href="{{basePath}}/admin/tags" role="button" class="outline">Merkelapper</a></li>
|
<li><a href="{{basePath}}/admin/tags" role="button" class="outline">Merkelapper</a></li>
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,7 @@
|
||||||
</article>
|
</article>
|
||||||
|
|
||||||
{{with .Data}}
|
{{with .Data}}
|
||||||
|
<div class="table-responsive" role="region" aria-label="Brukertabell" tabindex="0">
|
||||||
<table role="grid">
|
<table role="grid">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
|
|
@ -68,5 +69,6 @@
|
||||||
{{end}}
|
{{end}}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
</div>
|
||||||
{{end}}
|
{{end}}
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,7 @@
|
||||||
{{with .Data}}
|
{{with .Data}}
|
||||||
<article>
|
<article>
|
||||||
<hgroup>
|
<hgroup>
|
||||||
<h1>{{.Code}}</h1>
|
<h1>Feil {{.Code}}: {{.Message}}</h1>
|
||||||
<p>{{.Message}}</p>
|
|
||||||
</hgroup>
|
</hgroup>
|
||||||
{{if eq .Code 404}}
|
{{if eq .Code 404}}
|
||||||
<p>Siden du leter etter finnes ikke. Den kan ha blitt flyttet eller slettet.</p>
|
<p>Siden du leter etter finnes ikke. Den kan ha blitt flyttet eller slettet.</p>
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@
|
||||||
{{with .Fave}}
|
{{with .Fave}}
|
||||||
{{if .ImagePath}}
|
{{if .ImagePath}}
|
||||||
<img src="{{basePath}}/uploads/{{.ImagePath}}"
|
<img src="{{basePath}}/uploads/{{.ImagePath}}"
|
||||||
alt="Bilde for: {{.Description}}">
|
alt="{{.Description}}">
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
<header>
|
<header>
|
||||||
|
|
@ -56,7 +56,7 @@
|
||||||
<footer>
|
<footer>
|
||||||
<small>Lagt til {{.CreatedAt.Format "02.01.2006"}}</small>
|
<small>Lagt til {{.CreatedAt.Format "02.01.2006"}}</small>
|
||||||
{{if $d.IsOwner}}
|
{{if $d.IsOwner}}
|
||||||
<nav class="fave-actions">
|
<div class="fave-actions" role="group" aria-label="Handlinger for favoritt">
|
||||||
<a href="{{basePath}}/faves/{{.ID}}/edit" role="button" class="outline">Rediger</a>
|
<a href="{{basePath}}/faves/{{.ID}}/edit" role="button" class="outline">Rediger</a>
|
||||||
<button
|
<button
|
||||||
hx-delete="{{basePath}}/faves/{{.ID}}"
|
hx-delete="{{basePath}}/faves/{{.ID}}"
|
||||||
|
|
@ -65,7 +65,7 @@
|
||||||
class="outline secondary"
|
class="outline secondary"
|
||||||
data-redirect="{{basePath}}/faves"
|
data-redirect="{{basePath}}/faves"
|
||||||
>Slett</button>
|
>Slett</button>
|
||||||
</nav>
|
</div>
|
||||||
{{end}}
|
{{end}}
|
||||||
</footer>
|
</footer>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
|
||||||
|
|
@ -55,17 +55,21 @@
|
||||||
value="{{.Tags}}"
|
value="{{.Tags}}"
|
||||||
placeholder="film, sci-fi, favoritt"
|
placeholder="film, sci-fi, favoritt"
|
||||||
autocomplete="off"
|
autocomplete="off"
|
||||||
|
role="combobox"
|
||||||
|
aria-expanded="false"
|
||||||
|
aria-haspopup="listbox"
|
||||||
|
aria-autocomplete="list"
|
||||||
|
aria-controls="tag-suggestions"
|
||||||
|
aria-describedby="tags-help"
|
||||||
hx-get="{{basePath}}/tags/search"
|
hx-get="{{basePath}}/tags/search"
|
||||||
hx-trigger="keyup changed delay:300ms"
|
hx-trigger="keyup changed delay:300ms"
|
||||||
hx-target="#tag-suggestions"
|
hx-target="#tag-suggestions"
|
||||||
hx-params="*"
|
hx-params="*"
|
||||||
hx-vals='{"q": ""}'
|
hx-vals='{"q": ""}'>
|
||||||
aria-describedby="tags-help"
|
<small id="tags-help">Skriv for å søke i eksisterende merkelapper. Maks {{maxTags}} stk. Bruk piltaster for å velge.</small>
|
||||||
aria-autocomplete="list"
|
|
||||||
aria-controls="tag-suggestions">
|
|
||||||
<small id="tags-help">Skriv for å søke i eksisterende merkelapper. Maks {{maxTags}} stk.</small>
|
|
||||||
</label>
|
</label>
|
||||||
<ul id="tag-suggestions" role="listbox" class="tag-suggestions" aria-label="Merkelappforslag"></ul>
|
<ul id="tag-suggestions" role="listbox" class="tag-suggestions" aria-label="Merkelappforslag"></ul>
|
||||||
|
<div id="tag-status" class="sr-only" aria-live="polite"></div>
|
||||||
|
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<legend>Synlighet</legend>
|
<legend>Synlighet</legend>
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@
|
||||||
<article class="fave-card" role="listitem">
|
<article class="fave-card" role="listitem">
|
||||||
{{if .ImagePath}}
|
{{if .ImagePath}}
|
||||||
<img src="{{basePath}}/uploads/{{.ImagePath}}"
|
<img src="{{basePath}}/uploads/{{.ImagePath}}"
|
||||||
alt="Bilde for: {{.Description}}"
|
alt="{{.Description}}"
|
||||||
loading="lazy">
|
loading="lazy">
|
||||||
{{end}}
|
{{end}}
|
||||||
<header>
|
<header>
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@
|
||||||
<article class="fave-card" role="listitem">
|
<article class="fave-card" role="listitem">
|
||||||
{{if .ImagePath}}
|
{{if .ImagePath}}
|
||||||
<img src="{{basePath}}/uploads/{{.ImagePath}}"
|
<img src="{{basePath}}/uploads/{{.ImagePath}}"
|
||||||
alt="Bilde for: {{.Description}}"
|
alt="{{.Description}}"
|
||||||
loading="lazy">
|
loading="lazy">
|
||||||
{{end}}
|
{{end}}
|
||||||
<header>
|
<header>
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@
|
||||||
|
|
||||||
<details>
|
<details>
|
||||||
<summary>Forventet format</summary>
|
<summary>Forventet format</summary>
|
||||||
<h3>JSON</h3>
|
<h2>JSON</h2>
|
||||||
<pre><code>[
|
<pre><code>[
|
||||||
{
|
{
|
||||||
"description": "Blade Runner 2049",
|
"description": "Blade Runner 2049",
|
||||||
|
|
@ -24,7 +24,7 @@
|
||||||
"tags": ["film", "sci-fi"]
|
"tags": ["film", "sci-fi"]
|
||||||
}
|
}
|
||||||
]</code></pre>
|
]</code></pre>
|
||||||
<h3>CSV</h3>
|
<h2>CSV</h2>
|
||||||
<pre><code>description,url,privacy,tags
|
<pre><code>description,url,privacy,tags
|
||||||
Blade Runner 2049,https://example.com,public,"film,sci-fi"</code></pre>
|
Blade Runner 2049,https://example.com,public,"film,sci-fi"</code></pre>
|
||||||
</details>
|
</details>
|
||||||
|
|
|
||||||
|
|
@ -57,7 +57,7 @@
|
||||||
<article class="fave-card" role="listitem">
|
<article class="fave-card" role="listitem">
|
||||||
{{if .ImagePath}}
|
{{if .ImagePath}}
|
||||||
<img src="{{basePath}}/uploads/{{.ImagePath}}"
|
<img src="{{basePath}}/uploads/{{.ImagePath}}"
|
||||||
alt="Bilde for: {{.Description}}"
|
alt="{{.Description}}"
|
||||||
loading="lazy">
|
loading="lazy">
|
||||||
{{end}}
|
{{end}}
|
||||||
<header>
|
<header>
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@
|
||||||
<article class="fave-card" role="listitem">
|
<article class="fave-card" role="listitem">
|
||||||
{{if .ImagePath}}
|
{{if .ImagePath}}
|
||||||
<img src="{{basePath}}/uploads/{{.ImagePath}}"
|
<img src="{{basePath}}/uploads/{{.ImagePath}}"
|
||||||
alt="Bilde for: {{.Description}}"
|
alt="{{.Description}}"
|
||||||
loading="lazy">
|
loading="lazy">
|
||||||
{{end}}
|
{{end}}
|
||||||
<header>
|
<header>
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
{{range .}}<li role="option"
|
{{range $i, $tag := .}}<li role="option"
|
||||||
|
id="tag-option-{{$i}}"
|
||||||
class="tag-suggestion"
|
class="tag-suggestion"
|
||||||
onclick="addTag(this, '{{.Name}}')"
|
aria-selected="false"
|
||||||
onkeydown="if(event.key==='Enter'){addTag(this, '{{.Name}}')}"
|
onclick="addTag(this, '{{$tag.Name}}')"
|
||||||
tabindex="0">{{.Name}}</li>
|
onkeydown="if(event.key==='Enter'||event.key===' '){event.preventDefault();addTag(this, '{{$tag.Name}}')}"
|
||||||
|
tabindex="-1">{{$tag.Name}}</li>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue