Single logo
  • Courses
  • Blog
  • About
Join on SkoolJoin on Skool

In this topic

React
  • One Request, Two Answers: the Same Post as an HTML Page and as JSON
  • A Blog Design from a Prompt: Downloading Figma Make Code and Reading App.tsx and BlogCard.tsx
  • How a Web Page Works: HTML Tags, Elements and Attributes
  • Semantic HTML: header, nav, main, aside and footer as Page Landmarks
  • HTML Forms: Labels, Names, Input Types and Where the Data Goes (GET vs POST)
  • CSS Basics: Selectors, Which Rule Wins, and the Box Model
  • CSS Flexbox vs Grid: A Nav Bar, a Card Row and a Dashboard
  • Responsive CSS: Viewport, Mobile-First Media Queries, clamp() and Dark Mode with Tokens
  • JavaScript for People Who Already Code: Syntax, Modules and Five Surprises
  • JavaScript Arrays the Functional Way: map, filter, reduce, find, sort and Object.entries
  • Async JavaScript: Promises, async/await, fetch and Promise.all
  • JavaScript in the Page: the DOM, querySelector and Events
  • npm, package.json and Vite: What npm install Fetches and How Vite Serves and Builds Your Page
  • TypeScript Essentials: Types Checked, Then Erased (Interfaces, Unions, Generics)
  • Why React, JSX and Components: The Page as a Function of Data
  • React Props and Composition: Data Down, Calls Up, Children in the Slot
  • Routing With React Router: One Page, Many Addresses
  • React Component Tests With Vitest and Testing Library: Test What the User Sees
  • End-to-End Tests for a React App With Playwright: A Full Dress Rehearsal
  • Why AI-Built Websites All Look the Same, and Four Levels That Fix It
  • Visual Hierarchy, Spacing and the 8-Point Grid: Tell the Eye What to Read First
  • Colour, Contrast and Dark Palettes: 60-30-10, Semantic Tokens and Ratios You Can Compute
  • Typography That Sells: Type Scale, Line Length and Free Font Pairings
  • The UI Element Catalogue: Buttons to Toasts, Their Jobs, States and shadcn/ui Names
  • Design Tokens: Primitive and Semantic Tokens, from Figma to CSS to Tailwind
  • Tailwind CSS 4 in React: Utility Classes, Responsive Prefixes, Hover and Dark Mode
  • shadcn/ui in React: Components You Own, Edit and Commit
  • Design Tokens to a Tailwind Theme: Light and Dark Mode with @theme inline
  • Motion in React: Entrance, Hover, Exit and Layout Animations
  • A React Dashboard: Stat Cards, a Recharts Line Chart and a Sortable Table
  • Accessibility in Practice: Dialogs, Menus and the Keyboard in React
  • Reference-Driven Design: Extract a DESIGN.md From a Site You Admire and Build From It
  • Components, Variants and Variables: One Design System in Figma and in CSS
  • Figma MCP Server: Build a React Component From a Frame, Then Write It Back
  • Claude Design: From a Brief to a Clickable Prototype, Then Hand It Off to Claude Code
  • Critiquing AI-Generated UI: Six Checks for Every Screen
  • The AI Design Landscape: Prompt to UI, Prompt to App, and Design to Code
  • Your Brand Rules Folder: One Folder Every AI-Built Page Follows
  • The Best-Practice UI Prompt: Plain Sentences That Beat the Average AI Page
  • UI Ideas From Figma Make, Google Stitch and ChatGPT: One Prompt, Three Designs
  • Google Stitch From a Sketch or Screenshot: Show the Layout, Say What to Keep
  • Stitch to Figma to Code: Turn a Stitch Screen Into Code That Uses Your Tokens
  • Figma Make: Prompt to Prototype With a Four-Part Prompt
  • Upgrade a Dated UI From One Screenshot (or a Reference Image)
  • States and Feedback: Make Every Click Get an Answer
  • A Design-Loop Skill: Claude Screenshots, Scores and Fixes Its Own UI
  • Copy Without the AI Tells: A Copy Pass on a Landing Page
  • React State, Events, Lists and Conditional Rendering: Follow One Click
  • React useEffect: When It Runs, What Cleanup Is For, and When You Don't Need One
  • Lifting State Up, Refs and React DevTools: Put State Where It Is Needed
  • Forms and Actions in React 19: Controlled Inputs, Form Actions, useActionState and useFormStatus
  • React Context and Custom Hooks: Share One Value, Reuse the Logic
  • Server State With TanStack Query: One Key, One Request, One Cache
  • Mutations and Optimistic Updates in TanStack Query: Change Data, Then Tell the Cache
  • Generate TypeScript Types, Query Hooks and Zod From an OpenAPI Spec With Orval
  • A Mock Backend in the Browser With Mock Service Worker, Generated From the Spec
  • A React Client for a FastAPI API: The CORS Wall, CORSMiddleware and the Vite Proxy
  • Forms With React Hook Form and Zod: The API's Rules in the Browser, the Server's Errors Under the Field
  • JWT Auth in a React Client With a FastAPI Backend: Log In, Carry the Token, Let the Server Decide
  1. Blog
  2. /
  3. React
  4. /
  5. Fundamentals

Accessibility in Practice: Dialogs, Menus and the Keyboard in React

What shadcn/ui and Radix give you for free and what you still check yourself: a dialog that traps focus and gives it back, a menu driven by arrow keys, the ARIA attributes in the real DOM, and a div-button that Tab skips.

Chaand Sheikh

·27 November 2026·Updated 28 November 2026Fundamentals

What you will learn

  • Follow the focus through a Radix dialog: trap, Escape and return
  • Use a dropdown menu that handles the arrow keys for you
  • Read the ARIA attributes Radix writes into the DOM
  • Find and fix a div-button the keyboard cannot reach, and run a six-point check

Before you start

  • shadcn/ui: Components You Own
  • React components and props

Picture a small task page and a person who cannot use a mouse. Maybe their hand hurts, maybe they use a screen reader. They only have the keyboard. Without a mouse, focus is the only pointer they have.

In this article we test a dialog and a menu with the keyboard only. The question is simple: what does shadcn/ui (built on Radix) give you for free, and what do you still have to check yourself?

A dialog is a meeting room

Think of a dialog as a meeting room.

  1. You walk in. Press Enter on Delete, and the focus moves inside, onto Cancel.
  2. The door locks. Tab goes round and round inside the room and never leaks out to the page.
  3. You leave. Escape closes the room, and the focus goes back to the seat you came from, the Delete button.
The focus trap in a dialog Page:Delete button Dialog (focus trapped) Cancel Delete task Enter Tab Tab (wraps) Esc: back
Enter walks in, Tab stays inside, Escape walks out to where you started.

The library moves the focus for you. Here is how.

The delete dialog

import {
  Dialog, DialogClose, DialogContent,
  DialogDescription, DialogTitle, DialogTrigger,
} from "@/components/ui/dialog"

export default function DeleteDialog() {
  return (
    <Dialog>
      <DialogTrigger className="btn red">Delete</DialogTrigger>
      <DialogContent>
        <DialogTitle>Delete this task?</DialogTitle>
        <DialogDescription>
          Write report will be removed for everyone.
        </DialogDescription>
        <div className="mt-5 flex justify-end gap-2">
          <DialogClose className="btn">Cancel</DialogClose>
          <DialogClose className="btn red">Delete task</DialogClose>
        </div>
      </DialogContent>
    </Dialog>
  )
}
  • Line 9, the trigger. A real button, so Tab reaches it and Enter opens the dialog.
  • Line 10, the content. This is the room, and Radix traps the focus inside it.
  • Line 11, the title, with the description after it. They give the dialog a name, and a screen reader reads them aloud.
  • Line 16, the close buttons. Real buttons again, so Enter works, and Escape closes the dialog too.

The Dialog parts come from a small file in src/components/ui/dialog.tsx that wraps Radix, the same way shadcn/ui does. If you have not seen that pattern yet, read shadcn/ui: components you own.

Frame by frame

These are the keys pressed in the running app, and where the focus landed each time:

Tab, Tab    button "Delete"
Enter       button "Cancel"
Tab         button "Delete task"
Tab again   button "Cancel"
Escape      button "Delete"
The Delete this task? dialog open over a dimmed Team tasks page, with the text Write report will be removed for everyone, and a blue focus ring around the Cancel button next to a red Delete task button.
After Enter: the dialog is open and the focus ring is on Cancel.

Look at the fourth line. After Delete task, Tab goes back to Cancel. It wrapped around and did not escape to the page behind. That is the focus trap. Then Escape closes the dialog and the focus is back on Delete.

Menu: arrow keys

import {
  DropdownMenu, DropdownMenuContent,
  DropdownMenuItem, DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu"

export default function ActionsMenu() {
  return (
    <DropdownMenu>
      <DropdownMenuTrigger className="btn">
        Actions
      </DropdownMenuTrigger>
      <DropdownMenuContent>
        <DropdownMenuItem>Edit</DropdownMenuItem>
        <DropdownMenuItem>Duplicate</DropdownMenuItem>
        <DropdownMenuItem>Archive</DropdownMenuItem>
      </DropdownMenuContent>
    </DropdownMenu>
  )
}

Line 9 is the trigger, another real button: Enter or Space opens the menu. Line 12 is the menu content. Radix gives it the role menu and handles the keys. The items, Edit, Duplicate and Archive, are reached with the arrow keys.

Tab         button "Actions"
Enter       div "Edit" role=menuitem
ArrowDown   div "Duplicate" role=menuitem
Escape      button "Actions"
The Actions menu open under the Actions button, with Edit, Duplicate and Archive. Duplicate is highlighted in blue.
After Arrow Down: the highlight moved from Edit to Duplicate.

You wrote no key handling at all. It all comes from the library.

The attributes in the real DOM

What does the page tell a screen reader? Here is the DOM with the dialog open, copied from the running app:

<button aria-haspopup="dialog" aria-expanded="true" aria-controls="radix-_r_2_" data-state="open">
<div role="dialog" id="radix-_r_2_" aria-labelledby="radix-_r_3_" aria-describedby="radix-_r_4_" data-state="open" tabindex="-1">
<h2 id="radix-_r_3_">
<p id="radix-_r_4_">
<div id="root" aria-hidden="true" data-aria-hidden="true">

The trigger says aria-haspopup="dialog" and aria-expanded="true". The dialog has role="dialog", with aria-labelledby pointing at the title and aria-describedby pointing at the description. And the page behind, #root, is aria-hidden, so it is skipped.

And with the menu open:

<div role="menu" id="radix-_r_1_" aria-orientation="vertical" aria-labelledby="radix-_r_0_" data-state="open">
<div role="menuitem" tabindex="0" data-highlighted="" data-orientation="vertical">
<div role="menuitem" tabindex="-1" data-orientation="vertical">

The role is menu and the items are menuitem. Only the highlighted item has tabindex="0", so the arrow keys pass it along. Radix writes all of this for you. But you still supply the words: the title, the labels, the text. You do not need to memorise these attributes. You need to know what to look for.

Break it: a div-button the keyboard cannot reach

Imagine someone builds the Save button like this:

const save = () => alert("Saved")
const look = "btn blue"

// A div that looks like a button. The mouse works, the keyboard cannot reach it.
export default function BrokenToolbar() {
  return (
    <div className="flex gap-2">
      <div className={look} onClick={save}>Save</div>
      <button className="btn">Cancel</button>
    </div>
  )
}

A div with a click handler. It looks like a button and the mouse works perfectly. Now press Tab from the top:

Tab 1   button "Actions"
Tab 2   button "Delete"
Tab 3   button "Cancel"
Tab 4   body "Team tasksWrite repo"

Save is skipped completely, and the fourth Tab leaves the page. A keyboard user can never press Save. The fix is small, a real button:

const save = () => alert("Saved")
const look = "btn blue"

// The fix: a real button. Tab reaches it, Enter and Space press it.
export default function GoodToolbar() {
  return (
    <div className="flex gap-2">
      <button className={look} onClick={save}>Save</button>
      <button className="btn">Cancel</button>
    </div>
  )
}
Tab 1   button "Actions"
Tab 2   button "Delete"
Tab 3   button "Save"
Tab 4   button "Cancel"
The Team tasks page twice. Left, with the div Save: the focus ring is on Cancel because Save was skipped. Right, with a real button: the focus ring is on Save.
Left: with the div, the focus jumps from Delete straight to Cancel. Right: with a real button, Save gets the focus.

A div has no keyboard behaviour at all. A real button gives you Tab, Enter and Space for free. The project also keeps the focus ring visible on every button with one rule in index.css:

/* A visible focus ring on every button, for keyboard users. */
button:focus-visible { outline: 2px solid #2563eb; outline-offset: 2px; }

The six-point checklist

  1. Real elements. Anything clickable is a button or a link, never a div.
  2. Visible focus. You can always see where the focus is. Keep the focus ring.
  3. Names. An icon button gets an aria-label, and every input gets a label.
  4. Tab order. It follows the page: top to bottom, left to right.
  5. Contrast. Text stands out from its background in every theme. The numbers are in colour, contrast and dark palettes.
  6. The keyboard-only test. Unplug the mouse, open every dialog and menu, and press Escape.

Two minutes before every release. That is the habit.

Recap

Radix gives youYou check
Focus trap and focus return in dialogsNames: titles, labels, aria-label on icon buttons
Arrow keys and Escape in menusContrast and a visible focus ring
Roles and ARIA attributesReal buttons, and a keyboard-only test

We covered the foundations: real buttons, a visible focus ring, and a dialog and a menu that handle the keys. AI can generate the rest, and you check it with the keyboard.

Keep going in React · 31 of 59

Previous
A React Dashboard: Stat Cards, a Recharts Line Chart and a Sortable Table
Next post
Reference-Driven Design: Extract a DESIGN.md From a Site You Admire and Build From It
Community · Free to join
Single logo

StudyEasy AI Community

Hosted onSkool

Learn AI engineering, share what you build, and connect with other learners.

  • Free resources: lesson files, notebooks and code

  • Ask questions and join engineering discussions

  • Meet real people learning and building with AI

Join free on Skool

Related course on Udemy

The Python Architect Masterclass: Full Stack to AI Engineer

Python, Django, FastAPI, React, Docker, AWS, LLMs, RAG, agents and MCP, from first steps to AI engineer.View on Udemy ↗: The Python Architect Masterclass: Full Stack to AI Engineer (paid course, opens in a new tab)

Related posts

One Request, Two Answers: the Same Post as an HTML Page and as JSON

Ask a Django blog for the same post twice: once as a 12,731-byte HTML page built by a template, once as 2,976 bytes of JSON built by a serializer. Compare the headers, see who builds the page, and why the server still owns every write.

A Blog Design from a Prompt: Downloading Figma Make Code and Reading App.tsx and BlogCard.tsx

Make a blog design from a prompt in Figma Make, download src.zip, unzip it with Python's zipfile module, and read the two files that matter: App.tsx with its selectedPost state and BlogCard.tsx with its props.

How a Web Page Works: HTML Tags, Elements and Attributes

A web page is a text file full of labelled pieces. Learn tags, attributes and nesting with three tiny pages, and see what breaks when an attribute or a closing tag is wrong.

Semantic HTML: header, nav, main, aside and footer as Page Landmarks

The same page written as div soup and with semantic tags looks identical, but only one gives screen readers and search engines landmarks and an outline. Plus tables, div, span and the one-main rule.

On this page

  • A dialog is a meeting room
  • The delete dialog
  • Frame by frame
  • Menu: arrow keys
  • The attributes in the real DOM
  • Break it: a div-button the keyboard cannot reach
  • The six-point checklist
  • Recap
Community · Free to join
Single logo

StudyEasy AI Community

Hosted onSkool

Learn AI engineering, share what you build, and connect with other learners.

  • Free resources: lesson files, notebooks and code

  • Ask questions and join engineering discussions

  • Meet real people learning and building with AI

Join free on Skool

Related course on Udemy

The Python Architect Masterclass: Full Stack to AI Engineer

Python, Django, FastAPI, React, Docker, AWS, LLMs, RAG, agents and MCP, from first steps to AI engineer.View on Udemy ↗: The Python Architect Masterclass: Full Stack to AI Engineer (paid course, opens in a new tab)

Single logo

Empowering Education, One Course at a Time

About
About usContact us
Legal
Terms of UsePrivacy Policy

© 2026 StudyEasy Organization. All rights reserved.