Avoid non-native interactive elements. If using native HTML is not possible, add an appropriate role and support for tabbing, mouse, keyboard, and touch inputs to an interactive content element
208 </div>
209 <div className="colleges">
210 {filteredColleges.map((college, index) => (
211 <div212 className={`college ${activeIndex === index ? 'active' : ''}`}213 key={college.id}214 onClick={() => handleCollegeClick(college)}215 onTouchStart={() => handleTouchStart(index)}216 onTouchEnd={handleTouchEnd}217 >218 <div className="college-content">
219 <div className="up">
220 <img className="college-image" src={college.imageURL} alt="College Logo" />
Avoid non-native interactive elements. If using native HTML is not possible, add an appropriate role and support for tabbing, mouse, keyboard, and touch inputs to an interactive content element
174 </li>
175 </ul>
176 </div>
177 <div className="hamburger" onClick={toggleMenu}>178 <div className={`bar ${menuOpen ? 'open' : ''}`} />
179 <div className={`bar ${menuOpen ? 'open' : ''}`} />
180 <div className={`bar ${menuOpen ? 'open' : ''}`} />
Description
Static HTML elements do not have semantic meaning. This is clear in the case of <div>
and <span>
. It is less so clear in the case of elements that seem semantic, but that do not have a semantic mapping in the accessibility layer. For example <a>
, <big>
, <blockquote>
, <footer>
, <picture>
, <strike>
and <time>
-- to name a few -- have no semantic layer mapping. They are as void of meaning as <div>
.
The WAI-ARIA role
attribute confers a semantic mapping to an element. The semantic value can then be expressed to a user via assistive technology.
In order to add interactivity such as a mouse or key event listener to a static element, that element must be given a role value as well.
Bad Practice
<div onClick={() => {}} />
Recommended
<button onClick={() => {}} className="foo" />
<div className="foo" onClick={() => {}} role="button" />
<input type="text" onClick={() => {}} />