Accessible disclosure and status updates
Quick answer
A disclosure has a control and content that can be shown or hidden. Prefer native details and summary when suitable. For a custom disclosure, use a named button, maintain aria-expanded in sync with visibility, and identify the controlled region with aria-controls when appropriate. A separate status region with role="status" can communicate nonurgent changes without moving focus. DOM attributes alone do not prove screen-reader behavior.
Browser examples
Run each snippet in a fresh browser document. These are static code blocks; ByteMind browser execution is not verified. Storage examples require a test origin.
const b=document.createElement("button"),p=document.createElement("section");b.textContent="Details";p.id="details-panel";p.hidden=true;b.setAttribute("aria-controls",p.id);b.setAttribute("aria-expanded","false");b.addEventListener("click",()=>{p.hidden=!p.hidden;b.setAttribute("aria-expanded",String(!p.hidden));});b.click();console.log(b.getAttribute("aria-expanded"),p.hidden);Expected console output:
true falseThe handler updates both the semantic state and visibility.
const status=document.createElement("p");status.setAttribute("role","status");document.body.append(status);status.textContent="2 items saved";console.log(status.getAttribute("role"),status.textContent);Expected console output:
status 2 items savedThe fixture checks DOM semantics and content, not spoken output.
Common mistake
Changing aria-expanded alone does not hide content. Never leave hidden interactive content reachable by keyboard. Test actual keyboard access and assistive technology independently.
Practice
Build a disclosure with a native button. Test opening and closing using keyboard and pointer, and confirm the visible content and expanded state agree.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Accessible disclosure and status updates — Knowledge Check
Apply the concept and predict the browser example behavior.
What should aria-expanded match on a disclosure button?
Does changing aria-expanded alone hide the controlled section?
Which role can expose a nonurgent result message without moving focus?
What is the exact console output in Accessible disclosure and status updates example 1?
const b=document.createElement("button"),p=document.createElement("section");b.textContent="Details";p.id="details-panel";p.hidden=true;b.setAttribute("aria-controls",p.id);b.setAttribute("aria-expanded","false");b.addEventListener("click",()=>{p.hidden=!p.hidden;b.setAttribute("aria-expanded",String(!p.hidden));});b.click();console.log(b.getAttribute("aria-expanded"),p.hidden);What is the exact console output in Accessible disclosure and status updates example 2?
const status=document.createElement("p");status.setAttribute("role","status");document.body.append(status);status.textContent="2 items saved";console.log(status.getAttribute("role"),status.textContent);