Skip to content

Commit

Permalink
Merge pull request #116 from granttchart/feature/94-modal-a11y
Browse files Browse the repository at this point in the history
feat(94): focus() modal close button on open
  • Loading branch information
lauriemerrell authored Nov 29, 2023
2 parents 60d1098 + ca05a30 commit 799b957
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/components/Modal.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import React from "react";
import React, { useEffect, useRef } from "react";
import BusRouteDetails from "./BusRouteDetails";
import { Link } from "react-router-dom";

export default function Modal({ selectedRoute, closeModal, }) {
const modalCloseRef = useRef(null);


useEffect(() => {
const modalCloseBtn = modalCloseRef.current;
if (modalCloseBtn) modalCloseBtn.focus();
}, [modalCloseRef]);

// take all the ratios from the data and average out each line's mean bus reliablility

Expand Down Expand Up @@ -86,7 +90,7 @@ export default function Modal({ selectedRoute, closeModal, }) {
return (
<div className="modal" onClick={closeModal}>
<div className="modal-container" onClick={(e) => e.stopPropagation()}>
<button onClick={closeModal} className="close-btn">
<button onClick={closeModal} ref={modalCloseRef} className="close-btn" aria-label="Close">
x
</button>
<BusRouteDetails
Expand Down
2 changes: 2 additions & 0 deletions src/scss/_modal.scss
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
cursor: pointer;
border-radius: 50%;
padding: 1em;
height: 3.25em;
width: 3.25em;
@include transitionHover;

&:hover {
Expand Down

0 comments on commit 799b957

Please sign in to comment.