Code Explainers
Code explainers tagged #accessibility
javascript
const form = document.querySelector('#signup-form'); const password = form.querySelector('#password'); const confirm = form.querySelector('#confirm-password'); const submit = form.querySelector('button[type="submit"]');
Live password-match validation in the DOM
form-validation
dom-events
accessibility
Intermediate
6 steps
javascript
import { NavLink, useLocation } from 'react-router-dom'; const NAV_ITEMS = [ { to: '/', label: 'Dashboard', end: true },
Building an accessible Sidebar in React
routing
accessibility
declarative-ui
Intermediate
6 steps
javascript
import { forwardRef, useImperativeHandle, useRef, useState } from 'react'; const TextField = forwardRef(function TextField( { label, error, onChange, ...props },
Exposing an imperative handle in React
forwardref
useimperativehandle
refs
Advanced
8 steps
javascript
import { createContext, useContext, useState, useId } from "react"; const AccordionContext = createContext(null); const ItemContext = createContext(null);
Building a compound Accordion in React
context
compound-components
state-management
Intermediate
8 steps
javascript
import { useState, useRef, useEffect, useCallback } from 'react'; export function CopyButton({ text, label = 'Copy' }) { const [copied, setCopied] = useState(false);
A copy-to-clipboard button in React
clipboard-api
hooks
cleanup
Intermediate
7 steps
javascript
import { useState } from "react"; const EMAIL_RE = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
Building a validated signup form in React
form-validation
controlled-components
state-management
Intermediate
10 steps
javascript
import { useCallback, useEffect, useRef } from 'react'; import { createPortal } from 'react-dom'; const FOCUSABLE = 'a[href], button:not([disabled]), textarea, input, select, [tabindex]:not([tabindex="-1"])';
Building an accessible modal in React
focus-trap
accessibility
portals
Advanced
9 steps
javascript
import { useSearchParams } from "react-router-dom"; const TABS = [ { id: "overview", label: "Overview" },
URL-driven tabs with React Router
url-state
query-params
accessibility
Intermediate
8 steps
typescript
import { Directive, ElementRef, HostListener, Input, OnDestroy, OnInit } from '@angular/core'; @Directive({ selector: '[appTrapFocus]',
Building a focus-trap directive in Angular
accessibility
focus-management
dom
Intermediate
9 steps
javascript
import { useEffect, useRef, useState } from "react"; export function Dropdown({ label, children }) { const [open, setOpen] = useState(false);
Closing a dropdown on outside click in React
outside-click
event-listeners
cleanup
Intermediate
8 steps