Accessibility
Goal: a screen reader and a keyboard user learn what a client navigation or an update inside a page did. A navigation does not reload the document, so nothing moves focus or speaks unless the app says so.
- Keep the defaults. After a client navigation Hamur moves focus, without scrolling, to the
#hashtarget, an[autofocus]element, or the firsth1, and announces the page's title in a live region. Both are keys of the config, andfalseor"none"turns them off:
import { defineConfig } from "hamur"
export default defineConfig({
framework: "react",
app: {
navigation: { focus: "heading" },
routeAnnouncer: { politeness: "polite" },
},
})
- Give every page one
h1and a title: the announcement and the focus read them. - Announce changes inside a page yourself.
useAnnouncer()writes into two live regions that never change theiraria-live:polite(message)for a saved form,assertive(message)for an error. Use<Announcer />once to place the regions:
import { useAnnouncer } from "@hamur/adapter-react"
import { useState } from "react"
export default function Settings() {
const { polite, assertive } = useAnnouncer()
const [name, setName] = useState("")
const save = async () => {
const response = await fetch("/api/profile", {
method: "POST",
body: JSON.stringify({ name }),
headers: { "content-type": "application/json" },
})
if (response.ok) polite("Profile saved")
else assertive("Profile not saved")
}
return (
<form onSubmit={(event) => (event.preventDefault(), void save())}>
<label htmlFor="name">Name</label>
<input id="name" value={name} onChange={(event) => setName(event.target.value)} autoComplete="name" />
<button type="submit">Save</button>
</form>
)
}
- Check what you built. The Audit tab of the devtools lists findings on the current page, such as a missing
lang, an image withoutalt, a button without a name, a duplicateidor a skipped heading level, and highlights each element. It does not replace trying the page with a keyboard and a screen reader.
See also: Navigation, Configuration, Adapters.