Skip to content
Source
Sign inSign up
TanStack/devtools
Open History to see the last commit

App.tsx

167 lines5.1 KB

1import { useState } from 'react'
2​
3/**
4 * Example app with intentional accessibility issues for testing the A11y devtools plugin
5 */
6export default function App() {
7 const [showModal, setShowModal] = useState(false)
8​
9 return (
10 <div style={{ padding: '20px', fontFamily: 'system-ui, sans-serif' }}>
11 <h1>A11y Devtools Demo</h1>
12 <p>
13 This page contains intentional accessibility issues to demonstrate the
14 A11y devtools plugin. Open the devtools panel and click "Run Audit" to
15 see the issues.
16 </p>
17​
18 <section style={{ marginTop: '24px' }}>
19 <h2>Accessibility Issues Demo</h2>
20​
21 {/* Issue: Image without alt text */}
22 <div style={{ marginBottom: '16px' }}>
23 <h3>1. Image without alt text</h3>
24 <img
25 src="https://via.placeholder.com/150"
26 width={150}
27 height={150}
28 style={{ border: '1px solid #ccc' }}
29 />
30 </div>
31​
32 {/* Issue: Button without accessible name */}
33 <div style={{ marginBottom: '16px' }}>
34 <h3>2. Button without accessible name</h3>
35 <button style={{ width: '40px', height: '40px', fontSize: '20px' }}>
36 <span aria-hidden="true">Γ—</span>
37 </button>
38 </div>
39​
40 {/* Issue: Form input without label */}
41 <div style={{ marginBottom: '16px' }}>
42 <h3>3. Form input without label</h3>
43 <input
44 type="text"
45 placeholder="Enter your name"
46 style={{ padding: '8px' }}
47 />
48 </div>
49​
50 {/* Issue: Low color contrast */}
51 <div style={{ marginBottom: '16px' }}>
52 <h3>4. Low color contrast</h3>
53 <p style={{ color: '#aaa', backgroundColor: '#fff' }}>
54 This text has poor color contrast and may be hard to read.
55 </p>
56 </div>
57​
58 {/* Issue: Link without discernible text */}
59 <div style={{ marginBottom: '16px' }}>
60 <h3>5. Link without discernible text</h3>
61 <a href="https://example.com" style={{ display: 'inline-block' }}>
62 <img src="https://via.placeholder.com/24" width={24} height={24} />
63 </a>
64 </div>
65​
66 {/* Issue: Missing main landmark */}
67 <div style={{ marginBottom: '16px' }}>
68 <h3>6. Click handler on non-interactive element</h3>
69 <div
70 onClick={() => setShowModal(true)}
71 style={{
72 padding: '12px 24px',
73 backgroundColor: '#0ea5e9',
74 color: 'white',
75 borderRadius: '4px',
76 display: 'inline-block',
77 cursor: 'pointer',
78 }}
79 >
80 Click me (not a button!)
81 </div>
82 </div>
83​
84 {/* Issue: Empty heading */}
85 <div style={{ marginBottom: '16px' }}>
86 <h3>7. Empty heading</h3>
87 <h4></h4>
88 </div>
89​
90 {/* Issue: Missing form labels */}
91 <div style={{ marginBottom: '16px' }}>
92 <h3>8. Select without label</h3>
93 <select style={{ padding: '8px' }}>
94 <option>Option 1</option>
95 <option>Option 2</option>
96 <option>Option 3</option>
97 </select>
98 </div>
99 </section>
100​
101 <section
102 style={{
103 marginTop: '32px',
104 padding: '16px',
105 backgroundColor: '#f5f5f5',
106 borderRadius: '8px',
107 }}
108 >
109 <h2>Accessible Content (for comparison)</h2>
110​
111 <div style={{ marginBottom: '16px' }}>
112 <h3>Proper image with alt text</h3>
113 <img
114 src="https://via.placeholder.com/150"
115 alt="Placeholder image for demonstration"
116 width={150}
117 height={150}
118 style={{ border: '1px solid #ccc' }}
119 />
120 </div>
121​
122 <div style={{ marginBottom: '16px' }}>
123 <h3>Proper button with label</h3>
124 <button
125 aria-label="Close dialog"
126 style={{ width: '40px', height: '40px', fontSize: '20px' }}
127 >
128 <span aria-hidden="true">Γ—</span>
129 </button>
130 </div>
131​
132 <div style={{ marginBottom: '16px' }}>
133 <h3>Proper input with label</h3>
134 <label
135 htmlFor="name-input"
136 style={{ display: 'block', marginBottom: '4px' }}
137 >
138 Your Name
139 </label>
140 <input id="name-input" type="text" style={{ padding: '8px' }} />
141 </div>
142 </section>
143​
144 {showModal && (
145 <div
146 role="dialog"
147 aria-labelledby="modal-title"
148 style={{
149 position: 'fixed',
150 top: '50%',
151 left: '50%',
152 transform: 'translate(-50%, -50%)',
153 backgroundColor: 'white',
154 padding: '24px',
155 borderRadius: '8px',
156 boxShadow: '0 4px 20px rgba(0,0,0,0.2)',
157 zIndex: 1000,
158 }}
159 >
160 <h2 id="modal-title">Modal Dialog</h2>
161 <p>This is a modal that was triggered by a non-button element.</p>
162 <button onClick={() => setShowModal(false)}>Close</button>
163 </div>
164 )}
165 </div>
166 )