<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Antonio Clarke on Medium]]></title>
        <description><![CDATA[Stories by Antonio Clarke on Medium]]></description>
        <link>https://medium.com/@antonioclarke?source=rss-4b8b90053fab------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*00jlFOWvfHsRCT2N</url>
            <title>Stories by Antonio Clarke on Medium</title>
            <link>https://medium.com/@antonioclarke?source=rss-4b8b90053fab------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 08:18:25 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@antonioclarke/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Building Accessible Web Experiences at Lyft]]></title>
            <link>https://eng.lyft.com/building-accessible-web-experiences-at-lyft-185ad9328c6f?source=rss-4b8b90053fab------2</link>
            <guid isPermaLink="false">https://medium.com/p/185ad9328c6f</guid>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[mobile-development]]></category>
            <category><![CDATA[accessibility]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Antonio Clarke]]></dc:creator>
            <pubDate>Wed, 02 Sep 2020 17:56:20 GMT</pubDate>
            <atom:updated>2020-09-02T17:56:20.372Z</atom:updated>
            <content:encoded><![CDATA[<p><em>tl;dr: Test your web apps with both keyboards and screen readers, learn to love the WAI-ARIA guidelines, and always use accessible HTML elements when possible.</em></p><p>At Lyft, we have a large and diverse group of riders and drivers, and it’s important for us to aim to build experiences that are accessible to as wide of an audience as possible. In this blog post, we’ll dive into how we build accessibility into our web apps through a case study of a new feature on our <a href="https://ride.lyft.com/">web platform for riders</a>.</p><h4>Feature Overview: Ride History — Send Report</h4><p>Lyft users have the ability to create email reports of their rides, for use-cases such as personal budgeting or business expensing. In our native app, this is done on the following screen:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TZr-nGZCe8l2_tGZHyikqg.png" /><figcaption>Sending a Report in the App</figcaption></figure><p>For the MVP of this feature on our web platform, we opted for a mobile-first approach that maintained an identical UI with our app for small screens and simply scaled the UI for larger screens.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*O8rWO7qteErLDg4G8Bzl6g.png" /><figcaption>Sending a Report on Web</figcaption></figure><p>At Lyft, we work with a modern front-end tech stack featuring React Hooks and TypeScript, so the implementations shown in this post will echo that. <em>Note: This post will focus primarily on the accessibility aspects of this component, and a basic understanding of both TypeScript and React Hooks will greatly help in understanding this post.</em></p><h3>Base Implementation: A Multi-Selectable List</h3><h4>Displaying the List of Rides</h4><p>This screen features a multi-selectable, infinitely scrollable list of all of the user’s past rides. Setting aside the infinite scroll implementation (which deserves a blog post in itself) we’ll start with the base for building the multi-selectable list for <strong>mouse users</strong>. Assuming we have a RideListEntry component that renders the details of a single ride, our list of rides could look something like this:</p><pre>type Props = {<br>  rides: Ride[]; <em>// Receive array of rides as a prop</em><br>};</pre><pre>const RideList = ({ rides }: Props) =&gt; {<br>  return (<br>    &lt;&gt;<br>      {rides.map((ride) =&gt; (<br>        &lt;RideListEntry <em>// Create a RideListEntry for each ride</em><br>          key={ride.ride_id} <em>// Assign each entry a unique key</em><br>          {...ride} <em>// Spread all of ride&#39;s properties</em><br>        /&gt;<br>      ))}<br>    &lt;/&gt;<br>  );<br>};</pre><h4>Showing Which Rides are Selected</h4><p>Next, we need to keep track of the currently selected rides, which we will store with <a href="https://reactjs.org/docs/state-and-lifecycle.html">React’s state</a>. Because this state is used not only for indicating which rides are currently selected, but also for showing a summary at the bottom of the screen with the number of rides selected and their total cost, we <a href="https://reactjs.org/docs/lifting-state-up.html">lift its state up</a> to their parent component and then pass it down with props. Our updated component ends up looking like:</p><pre>type Props = {<br>  rides: Ride[];<br><strong>  selectedRides: Ride[];<br></strong>};</pre><pre>const RideList = ({ rides, <strong>selectedRides</strong> }: Props) =&gt; {<br>  <strong>const selectedRideIDs = new Set(selectedRides.map((ride) =&gt; ride.ride_id)); </strong><em>// For O(1) existence</em></pre><pre>return (<br>    &lt;&gt;<br>      {rides.map((ride) =&gt; (<br>        &lt;RideListEntry <br>          key={ride.ride_id} <br>          {...ride}                    <br><strong>          areRidesSelected={selectedRideIDs.size &gt; 0} </strong><em>// Shifts all rides&#39; prices if any are selected </em><strong><br>          isSelected={selectedRideIDs.has(ride.ride_id)} </strong><em>// Shows purple checkmark beside selected rides</em><strong><br></strong>        /&gt;<br>      ))}<br>    &lt;/&gt;<br>  );<br>};</pre><h4>Selecting Rides</h4><p>Finally, to make rides selectable, we receive an additional prop — a function that takes a Ride as input and updates the list of selected rides accordingly. Because all of the styling is already handled in the RideListEntry component, and &lt;button&gt; elements tend to come with unwanted, unaesthetic styles, we may be tempted to add a simple wrapper &lt;div&gt; around each of them and call it a day:</p><pre>type Props = {<br>  rides: Ride[];<br>  selectedRides: Ride[];<br><strong>  onRideSelect: (selectedRide: Ride) =&gt; void;<br></strong>};</pre><pre>const RideList = ({ rides, selectedRides, onRideSelect }: Props) =&gt; {<br>  const selectedRideIDs = new Set(selectedRides.map((ride) =&gt; ride.ride_id));</pre><pre>return (<br>    &lt;&gt;<br>      {rides.map((ride) =&gt; (<br><strong>        &lt;div onClick={() =&gt; onRideSelect(ride)} key={ride.ride_id}&gt;<br></strong>          &lt;RideListEntry /&gt; <em>// Props omitted for brevity</em><br><strong>        &lt;/div&gt;<br></strong>      ))}<br>    &lt;/&gt;<br>  );<br>};</pre><p>With the click handler added, our code works! <em>Kind of.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*sOMQMTv5W-iSUUc3MgjxGA.gif" /></figure><h3>Aiming for Accessibility</h3><p>Although we can now select rides to generate a report, none of them are able to be navigated to or selected by the keyboard, making this feature <strong>impossible to use with the keyboard</strong>. The first step in improving our experience is doing this type of testing and recognizing when you have a problem.</p><blockquote><strong>Key Takeaway #1: Test your web apps with both keyboards and screen readers.</strong></blockquote><p>We’ll focus on keyboards for now and get to screen readers later.</p><p>The problem lies in using a &lt;div&gt; element for our wrapper click-handler element. By using a &lt;div&gt; to simplify our styling, we miss out on a variety of accessibility features that a &lt;button&gt; gives us for free, most significantly in this case, keyboard navigation. For many common of interactive interfaces, such as dropdown selectors, forms, and buttons, the browser’s default elements do a lot of heavy lifting behind the scenes, so take advantage of them whenever possible. Use them whenever possible.</p><blockquote><strong>Key Takeaway #2: Always use accessible HTML elements when possible</strong></blockquote><p>With that in mind, let’s try to correct our earlier faux-pas and use a &lt;button&gt; with a bit of CSS to improve its appearance. At Lyft, we use <a href="https://styled-components.com/">styled-components</a>, and a simple implementation might look something like this:</p><pre><strong>const ButtonWrapper = styled.button`<br>  display: block;<br>  width: 100%;<br>  background: transparent;<br>  margin: 0;<br>  padding: 0;<br>  border: none;<br>`</strong></pre><pre>...</pre><pre>return (<br>    &lt;&gt;<br>      {rides.map((ride) =&gt; (<br><strong>        &lt;ButtonWrapper onClick={() =&gt; onRideSelect(ride)}&gt; </strong><em>// Key omitted for brevity</em><strong><br></strong>          &lt;RideListEntry /&gt;<br><strong>        &lt;/ButtonWrapper&gt;<br></strong>      ))}<br>    &lt;/&gt;<br>  );<br>};</pre><p>With just a few lines of CSS, we now have all of the benefits of a &lt;button&gt; with the styling we want! Score!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hXmqg4Qu5NolP1EXzfEZQA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9FgKpSLHmWArKYQyu8Mx-A.png" /><figcaption>A little CSS goes a long way!</figcaption></figure><h4>Testing Our Updated List</h4><p>Now that we’re using a &lt;button&gt; we can navigate through the list of rides using the Tab key and can select and de-select them using the Enter key, great! We can call it a day, now right?</p><p>Not exactly.</p><p>Because this list uses infinite scroll for all of the user’s rides, we’d have to Tab through <em>every ride we’ve ever taken </em>to get to the “Send report” button. Yikes!</p><p>Alternatively, we can use Shift + Tab to navigate backwards through the entire page until we reach the Send button, but that also isn’t a great user experience.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*IBrxBe_x5HBRHgOiPYJx4w.gif" /><figcaption>Still not-so keyboard friendly :(</figcaption></figure><p>It looks like maybe the &lt;button&gt; element won’t work for us after all. Well, at least we tried.</p><p>At this point, we might wonder how the keyboard interaction should work for this module in general. Clearly navigating through the entire list with Tab isn’t the way to go, but how do we decide what is?</p><h3>Identifying the Ideal</h3><p>When building an interactive user interface and unsure how to handle keyboard interaction, look no further than the <a href="https://www.w3.org/TR/wai-aria-practices/">WAI-ARIA authoring practices</a>. This document features rich and detailed explanations for building web applications accessible to both keyboards and screen readers. What we’re interested in specifically is the section on <a href="https://www.w3.org/TR/wai-aria-practices/#aria_ex">design patterns and widgets</a>. The third key takeaway from this guide is to:</p><blockquote><strong>Key Takeaway #3: Learn to love the WAI-ARIA guidelines</strong></blockquote><p>The first time reading this document, you might be overwhelmed. Which of their listed design patterns should I be following? Sometimes the answer is obvious — for example, “Button” and “Radio Group” are fairly self-explanatory, however others like “Spinbutton” and “Treegrid” might not be.</p><p>To get started on the right track, we can let Google do some heavy lifting for us. We know that we’re working on a multi-selectable list of items, so let’s see what shows up with a search for that.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_b3uKTnSHCTnHMspSdG84A.png" /><figcaption>Google to the rescue!</figcaption></figure><p>Since the “Listbox” design pattern showed up, let’s take a look at it. It is described in the WAI-ARIA document as follows:</p><blockquote>A <a href="https://www.w3.org/TR/wai-aria-1.1/#listbox">listbox</a> widget presents a list of options and allows a user to select one or more of them. A listbox that allows a single option to be chosen is a single-select listbox; one that allows multiple options to be selected is a multi-select listbox.</blockquote><p>A multi-select listbox sounds like just what we need! Now we can read the <a href="https://www.w3.org/TR/wai-aria-practices/#listbox_kbd_interaction">keyboard interaction</a> sub-section of the Listbox section and identify the ideal case for keyboard interaction:</p><ul><li>When a multi-select listbox receives focus:</li><li>If none of the options are selected before the listbox receives focus, focus is set on the first option and there is no automatic change in the selection state.</li><li>If one or more options are selected before the listbox receives focus, focus is set on the first option in the list that is selected.</li><li>Down Arrow: Moves focus to the next option.</li><li>Up Arrow: Moves focus to the previous option.</li><li>Space: changes the selection state of the focused option.</li></ul><h3>Adding Keyboard Support</h3><p>Based on the WAI-ARIA document, there’s a lot of keyboard interaction we have to build, and these are just its base recommendations — there are <em>many </em>more key combinations it suggests supporting! As mentioned earlier, default HTML inputs should be used whenever possible, and this added complexity highlights the first pain point of building your own custom inputs:</p><blockquote><strong>Pain Point #1 of Custom Inputs — Keyboard Support</strong></blockquote><h4>Managing Focus</h4><p>Focus is an indicator of the element that is currently able to be interacted with by the keyboard and is typically moved by pressing the Tab key, as we saw with &lt;button&gt; elements earlier. However, based on our learnings from the WAI-ARIA document, we don’t want all of our elements to be focusable at once, so our first step is going to be sacrificing our &lt;button&gt; and going back to a &lt;div&gt;</p><pre>...</pre><pre>return (<br>    &lt;&gt;<br>      {rides.map((ride) =&gt; (<br><strong>        &lt;div onClick={() =&gt; onRideSelect(ride)}&gt;<br></strong>          &lt;RideListEntry /&gt;<br><strong>        &lt;/div&gt;<br></strong>      ))}<br>    &lt;/&gt;<br>  );<br>};</pre><p>Now we’re back where we started and <em>none </em>of our rides are reachable with the keyboard. Enter tabindex</p><h4>Introduction to tabindex</h4><p><a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/tabindex">tabindex</a> ( or tabIndex in React) is an HTML attribute used to determine an element’s position in the order of focusable elements. It accepts a numerical value, but generally <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/tabindex">only values of 0 or -1 should ever be used</a>. The simplest way of using tabIndex is with a value of 0, which simply adds the element to the page’s natural tab order, whereas a tabIndex of -1 makes an element <a href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLOrForeignElement/focus">programmatically focusable</a>, but not part of the page’s tab order.</p><pre>...</pre><pre>return (<br>    &lt;&gt;<br>      {rides.map((ride) =&gt; (<br>        &lt;div onClick={() =&gt; onRideSelect(ride)} <strong>tabIndex={0}</strong>&gt;<strong><br></strong>          &lt;RideListEntry /&gt;<br>        &lt;/div&gt;<strong><br></strong>      ))}<br>    &lt;/&gt;<br>  );<br>};</pre><p>And with that, all of our rides are tab-able… trapping us inside the infinite scrollable list and re-introducing the same problem we had with our &lt;button&gt;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*DXWHRM_P0V6dMf2JpRsQWw.gif" /><figcaption>Infinite Scroll Strikes Again</figcaption></figure><h4>Setting tabIndex</h4><p>As outlined by the WAI-ARIA document, rather than each ride being tab-able, only <em>one</em> ride should be tab-able and the rest should be reachable using the Up and Down arrow keys. Let’s start with only making a single ride tab-able and keeping track of the tab-able ride with the <a href="https://reactjs.org/docs/hooks-state.html">State hook</a>.</p><pre>import React, <strong>{useState}</strong> from &#39;react&#39;;</pre><pre>...</pre><pre><strong>const [focusedIdx, setFocusedIdx] = useState(0);</strong></pre><pre>return (<br>    &lt;&gt;<br>      {rides.map((ride) =&gt; (<br>        &lt;div <br>          onClick={() =&gt; onRideSelect(ride)}<strong><br>          tabIndex={idx === focusedIdx ? 0 : -1}<br></strong>        &gt;<strong><br></strong>          &lt;RideListEntry /&gt;<br>        &lt;/div&gt;<strong><br></strong>      ))}<br>    &lt;/&gt;<br>  );<br>};</pre><p>Next, we listen for the Up and Down arrow keys and update the state of the currently tab-able ride, making sure not to ignore the Down key if we’re at the end of the list and the Up key if we’re at the start of the list.</p><p><em>Note: We store all of the key codes in a constants file for easy re-use throughout our web app. If you don’t have something similar within your codebase, you can find the key code on </em><a href="https://keycode.info/"><em>this list</em></a><em>.</em></p><pre><strong>import { KEY_CODES } from &#39;constants&#39;; </strong><em>// Saved in a shared constants file</em></pre><pre>...</pre><pre><strong>const onKeyDown = (event: React.KeyboardEvent): void =&gt; {<br>  switch (event.keyCode) {<br>    case KEY_CODES.ArrowDown:<br>      if (focusedIdx &lt; rides.length - 1) {                      <br>        setFocusedIdx((prevIdx) =&gt; prevIdx + 1);<br>      }<br>      break;<br>    case KEY_CODES.ArrowUp:<br>      if (focusedIdx &gt; 0) {<br></strong>        <strong>setFocusedIdx((prevIdx) =&gt; prevIdx - 1);<br>      }<br>      break;<br>    default:<br>      break;<br>    }<br>};</strong></pre><pre>return (<br>    &lt;&gt;<br>      {rides.map((ride) =&gt; (<br>        &lt;div <br>          onClick={() =&gt; onRideSelect(ride)}<br><strong>          onKeyDown={onKeyDown}<br></strong>          tabIndex={idx === focusedIdx ? 0 : -1}<strong><br></strong>        &gt;<strong><br></strong>          &lt;RideListEntry /&gt;<br>        &lt;/div&gt;<strong><br></strong>      ))}<br>    &lt;/&gt;<br>  );<br>};</pre><p>One “gotcha” here is that although we’ve updated the tabIndex, changing the ride which is tab-able, <em>we haven’t actually moved focus from the current ride.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*RAbafT8ZfRRkULmcxIs6jg.gif" /><figcaption>tabIndex changes, the focused element does not</figcaption></figure><h4>Programmatically Updating Focus</h4><p>To actually update the currently focused element, we’ll need to call the .focus() method of its underlying DOM node directly.</p><p>In React, DOM elements are typically accessed <a href="https://reactjs.org/docs/refs-and-the-dom.html">using refs</a>. Because we need to be able to programmatically focus on <em>any</em> of the rides, we create a ref for each ride and call its .focus() method in our onKeyDown handler.</p><pre>import React, {<strong>createRef</strong>, <strong>RefObject, </strong>useState} from &#39;react&#39;;</pre><pre>...</pre><pre><strong>const containerRefs: RefObject&lt;HTMLDivElement&gt;[] = rides.map(() =&gt; createRef());</strong></pre><pre>const onKeyDown = (event: React.KeyboardEvent): void =&gt; {<br>  switch (event.keyCode) {<br>    case KEY_CODES.ArrowDown:<br>      if (focusedIdx &lt; rides.length - 1) {    <br><strong>        containerRefs[focusedIdx + 1]?.current?.focus();<br></strong>        setFocusedIdx((prevIdx) =&gt; prevIdx + 1);<br>      }<br>      break;<br>    case KEY_CODES.ArrowUp:<br>      if (focusedIdx &gt; 0) {<br><strong>        containerRefs[focusedIdx -1]?.current?.focus();<br></strong>        setFocusedIdx((prevIdx) =&gt; prevIdx - 1);<br>      }<br>      break;<br>    default:<br>      break;<br>    }<br>};</pre><pre>...</pre><pre>return (<br>    &lt;&gt;<br>      {rides.map((ride) =&gt; (<br>        &lt;div <br>          onClick={() =&gt; onRideSelect(ride)}<br>          onKeyDown={onKeyDown}<strong><br></strong>          tabIndex={idx === focusedIdx ? 0 : -1}                        <br><strong>          ref={containerRefs[idx]}<br></strong>        &gt;<strong><br></strong>          &lt;RideListEntry /&gt;<br>        &lt;/div&gt;<strong><br></strong>      ))}<br>    &lt;/&gt;<br>  );<br>};</pre><p>Now we can press Tab to enter the list of rides, navigate amongst them with the Up and Down arrow keys, Shift + Tab out of them, and then Tab back to the previously focused ride.</p><p><em>Note: this implementation deviates slightly from the WAI-ARIA document, which recommends setting focus on the first selected element when tabbing back into a listbox.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*1l6cpX1VIz5v_Ir_ZOvkDQ.gif" /></figure><p>Lastly, let’s add the ability to select rides with the Space key per the WAI-ARIA document. It’s as simple as adding an extra case to our onKeyDown handler and passing the currently focused ride into our onRideSelect handler.</p><pre>const onKeyDown = (event: React.KeyboardEvent): void =&gt; {<br>  switch (event.keyCode) {<br>    ...<br>    case KEY_CODES.Space:<br><strong>      onRideSelect(rides[focusedIdx])<br>   </strong>   break;<br>    default:<br>      break;<br>    }<br>};</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*0TOjL0Q9NYtrdIF4-EkNLw.gif" /><figcaption>Fully Supports Keyboard</figcaption></figure><h3>Adding Screen Reader Support</h3><p>With keyboard support working well, let’s give our component a run-through with a screen reader and see how it performs. For the purposes of this post, we’ll be using VoiceOver (VO), which is included in macOS by default. Some basic VO commands:</p><p>Command + F5 — Starts VO</p><p>Ctrl + Option + Left Arrow / Right Arrow — Navigates through content</p><p>Apologies to all non-Mac users, but you should be able to follow along with a Windows-supported screen reader.</p><p>Navigating through the page with VO, this is what we observe:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*HU1BFQK2RU92flz5ox0JWQ.gif" /><figcaption>Infinite Scroll Strikes Again!</figcaption></figure><p>Oh no! Does that behavior look familiar? Just like when we started with every ride being included in the page’s tab order, we have to walk through <em>every ride</em> with the screen reader to get to the “Send” button. This walkthrough highlights the second major pain point with building your own custom inputs.</p><blockquote><strong>Pain Point #2 of Custom Inputs — Screen Reader Support</strong></blockquote><p>Thankfully, with a little effort we can make a big improvement in our screen reader experience using ARIA roles and attributes.</p><h4>ARIA Roles, States and Properties</h4><p>How many developers have seen an aria-* attribute in a codebase before but not really understood what it did? Or perhaps have tangled with a linter warning telling you to add a role to your interactive &lt;div&gt;? I confess, both of those statements applied to me before my work on accessibility at Lyft.</p><p>If you feel overwhelmed, don’t worry! Once again, the WAI-ARIA document comes to the rescue with its sub-section on <a href="https://www.w3.org/TR/wai-aria-practices/#listbox_roles_states_props">WAI-ARIA roles, states and properties</a> for the listbox design pattern we’ve been following. The basics are listed below:</p><blockquote>1. An element that contains or owns all the listbox options has role <a href="https://www.w3.org/TR/wai-aria-1.1/#listbox">listbox</a>.</blockquote><blockquote>2. Each option in the listbox has role <a href="https://www.w3.org/TR/wai-aria-1.1/#option">option</a> and is a DOM descendant of the element with role listbox or is referenced by an <a href="https://www.w3.org/TR/wai-aria-1.1/#aria-owns">aria-owns</a> property on the listbox element.</blockquote><blockquote>3. If the listbox is not part of another widget, then it has a visible label referenced by <a href="https://www.w3.org/TR/wai-aria-1.1/#aria-labelledby">aria-labelledby</a> on the element with role listbox.</blockquote><blockquote>4. The element with role listbox has <a href="https://www.w3.org/TR/wai-aria-1.1/#aria-multiselectable">aria-multiselectable</a> set to true.</blockquote><blockquote>5. All selected options have <a href="https://www.w3.org/TR/wai-aria-1.1/#aria-selected">aria-selected</a> set to true.</blockquote><blockquote>6. All options that are not selected have <a href="https://www.w3.org/TR/wai-aria-1.1/#aria-selected">aria-selected</a> set to false.</blockquote><p>This might seem like a lot at first, but with just a few lines of code in this file, we can handle all of this! The code</p><pre>...</pre><pre>return (<br><strong>    &lt;div <br>      role=&quot;listbox&quot; <br>      aria-labelledby=&quot;send-report-header&quot;<br>      aria-multiselectable=&quot;true&quot;<br>    &gt;<br></strong>      {rides.map((ride) =&gt; (<br>        &lt;div<br><strong>          role=&quot;option&quot;</strong><br><strong>          aria-selected={selectedRideIDs.has(ride.ride_id)}<br></strong>          onClick={() =&gt; onRideSelect(ride)}<br>          onKeyDown={onKeyDown}<strong><br></strong>          tabIndex={idx === focusedIdx ? 0 : -1}                        <br>          ref={containerRefs[idx]}<strong><br>        </strong>&gt;<strong><br></strong>          &lt;RideListEntry /&gt;<br>        &lt;/div&gt;<strong><br></strong>      ))}<br><strong>    &lt;/div&gt;<br> </strong> );<br>};</pre><p>All that’s left is making sure the ID referenced by the aria-labbeledby attribute matches ID used by the listbox’s label — in this case, the page’s header. Our header lives in a separate component, and we update its ID below:</p><pre><em>Header.tsx</em></pre><pre><em>...</em></pre><pre>return &lt;h1 <strong>id=&quot;send-report-header&quot;</strong>&gt;Select rides&lt;/h1&gt;;</pre><p>With the ARIA attributes added, let’s try walking through this component with VO again.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*6yWdlqLPuJntFE2gsR8ohg.gif" /><figcaption>Much better!</figcaption></figure><p>With all of these changes:</p><ul><li>The entire list of rides is its own widget in the screen reader that we can enter / exit</li><li>Each ride in the list announces its position and the list and whether or not it is selected</li><li>The list itself announces how many rides are selected followed by the details of those rides</li></ul><p>Is it perfect? No. Is it significantly better than what we started with? Yes!</p><h3>Adding Mouse Support</h3><p>With keyboard and screen reader support handled, let’s go back to the most common use-case: interactions with a mouse. Looking back to our GIFs of click interactions, there’s something out of place:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*qdztPKg32EjERHIZEGoNhQ.gif" /><figcaption>Something’s not right here…</figcaption></figure><p>Can you see it? There’s no hover state to indicate that these rides are selectable! When we hover over the buttons, the cursor changes to indicate they are clickable, but nothing similar happens for the rides. This brings up the last, but easiest to solve, pain point of building custom inputs:</p><blockquote><strong>Pain Point #3 of Custom Inputs — Mouse Support</strong></blockquote><p>Going back to our styled-components implementation from earlier, we add the cursor’s hover state to our selectable &lt;div&gt;</p><pre><strong>import styled from &#39;styled-components&#39;;</strong></pre><pre><strong>const RideContainer = styled.div`<br>  cursor: pointer;<br>`;</strong></pre><pre>...</pre><pre>return (<br><strong>    &lt;</strong>div<strong>&gt; </strong><em>// attributes hidden for brevity</em><strong><br></strong>      {rides.map((ride) =&gt; (<br><strong>        &lt;RideContainer&gt; </strong><em>// attributes hidden for brevity</em><strong><br></strong>          &lt;RideListEntry /&gt;<br><strong>        &lt;/RideContainer&gt;<br></strong>      ))}<br>    &lt;/div&gt;<br><strong> </strong> );<br>};</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*LA_GPwQnf1y3w5Vj0RUmJA.gif" /><figcaption>There we go!</figcaption></figure><h3>Conclusion</h3><p>Whew, that was a lot. After all of our effort, we have successfully:</p><ul><li>Built our feature for the base-case of mouse support</li><li>Supported keyboard users</li><li>Supported screen reader users</li></ul><p>We built a much more accessible feature than we started with! We learned some key takeaways along the way, and they’re worth reiterating:</p><blockquote><strong>Key Takeaway #1: Test your web apps with both keyboards and screen readers.</strong></blockquote><blockquote><strong>Key Takeaway #2: Always use accessible HTML elements when possible</strong></blockquote><blockquote><strong>Key Takeaway #3: Learn to love the WAI-ARIA guidelines</strong></blockquote><p>The caveat to #2 is that sometimes (like in this case) there is no accessible HTML element that does exactly what you want it to do, and when that happens, be wary of the pain points of building custom inputs:</p><blockquote><strong>Pain Point #1 of Custom Inputs — Keyboard Support</strong></blockquote><blockquote><strong>Pain Point #2 of Custom Inputs — Screen Reader Support</strong></blockquote><blockquote><strong>Pain Point #3 of Custom Inputs — Mouse Support</strong></blockquote><p>There were a lot of steps in this blog, so let’s recap the <strong>process</strong> we followed today:</p><ol><li>Built the feature itself</li><li>Tested it with a mouse, success!</li><li>Tested it with a keyboard and realized it wasn’t usable</li><li>Tried using a native HTML element, but&lt;button&gt; also didn’t fit the use case</li><li>Identified the ideal state for keyboard interaction from the WAI-ARIA authoring docs</li><li>Implemented key interaction for focus management and key handlers</li><li>Re-tested it with a keyboard</li><li>Tested it with a screen reader and realized it wasn’t usable</li><li>Identified the recommended ARIA roles, states, and properties from the WAI-ARIA authoring docs</li><li>Implemented the ARIA roles, states, and properties</li><li>Re-tested it with a screen reader, success!</li><li>Re-tested it with a mouse … something’s not right.</li><li>Added hover states</li><li>Re-tested it with a mouse, and we’re good to go!</li></ol><p>I’ve found that when making interactive widgets accessible in web apps, my process often ends up looking quite similar to this. Give it a try on your next web app and see how it goes!</p><p><em>Thanks to </em><a href="https://ca.linkedin.com/in/joanne-deng-2a395547"><em>Joanne Deng</em></a><em> for proof-reading this post and to </em><a href="https://www.linkedin.com/in/ericbidelman"><em>Eric Bidelman</em></a><em> for reviewing the PRs related to this post.</em></p><p><em>If you are interested in an internship with Lyft and making more accessible products for all, check out our </em><a href="https://www.lyft.com/careers"><em>careers page</em></a><em>!</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=185ad9328c6f" width="1" height="1" alt=""><hr><p><a href="https://eng.lyft.com/building-accessible-web-experiences-at-lyft-185ad9328c6f">Building Accessible Web Experiences at Lyft</a> was originally published in <a href="https://eng.lyft.com/">Lyft Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>