While a lot of customers tell us they use Instacart to add valuable time back into their day, a community of users with mobility issues or visual impairments tell us they rely on our app as a dependable way to get the groceries they need. The Customer Engineering Team at Instacart is tasked with building a seamless in-app experience for every customer — so we take in-app accessibility for these customers really seriously.
One of the largest accessibility challenges we face is building an elegant (and usable) web modal. For standard situations, we use React-Modal which provides accessibility support right out of the box. Problem solved. Unfortunately, it’s not that simple. Some design and functional situations call for custom modals. This custom work requires that we tackle accessibility issues head-on. Following these best-practices helps us ensure that our modals provide the high-level of accessibility customers need and deserve:
Ensure there is a close button available early in the modal DOM
Maintain a focus trap and close when ESC is pressed
Return focus to original element on close
Apply correct roles and labels
Include appropriate headings
Test using a screen reader
Ensure that a close button is available early in the modal DOM
Leaving a standard modal can be very difficult and frustrating for keyboard users when there is no obvious exit mechanism. The modal should provide a close button for exiting easily. The button should be early in the content so the user does not need to tab through numerous elements to exit.
To optimize the keyboard user experience, it is preferable to focus on the close button when opening the modal.
In some cases, adding a close button within the modal or at the beginning of the content conflicts with ideal product design. One useful alternative is to create a hidden button that appears on focus.
The button appears when tabbed into
The button is not shown when focus leaves
We build an invisible button by setting the position off-screen and moving it back on-screen when it receives the focus. This provides keyboard users with a simple way to exit when they reach the element. The core design objectives are preserved while we simultaneously provide an excellent accessibility experience!
CloseButton.propTypes= {
hideRetailerChooser:PropTypes.func.isRequired,
}
functionCloseButton({ hideRetailerChooser }) {
return (
<buttonaria-label=“close store chooser“onClick={hideRetailerChooser}style={styles.button}>
<SVGIconname=“x“ />
</button>
)
}
constbuttonStyles= {
top:-9999,
left:-9999,
border:0,
background:‘none‘,
position:‘absolute‘,
Maintain a focus trap and close when “ESC” is pressed
The focus trap is another key accessibility feature for modals. The trap ensures that focus cannot leave the modal until it is explicitly closed. Tabbing with the modal open will cycle through all interactive elements in the modal and finally back to the first element once the end is reached.
In the words of Admiral Ackbar “it’s a trap”, which ensures the user stays within the relevant content.
To achieve this, focus must be explicitly moved back to the first element in the modal if the user tabs past the last element. Similarly, focus must move to the last element when back-tabbing past the first element. In React this can be achieved by handling the onKeyDown event.
Logan Murdock
Author
Logan Murdock is a member of the Instacart team. To read more of Logan Murdock's posts, you can browse the company blog or search by keyword using the search bar at the top of the page.
Author: Ben Bader The universe of the current Large Language Models (LLMs) engineering is electrifying, to say the least. The industry has been on fire with change since the launch of ChatGPT in November of…...
Authors: Han Li, Sahil Khanna, Jocelyn De La Rosa, Moping Dou, Sharad Gupta, Chenyang Yu and Rajpal Paryani Background About a year ago, we introduced the first version of Griffin, Instacart’s first ML Platform, detailing its development and support for end-to-end ML in…...