Skip to content

Commit

Permalink
feat: accessibility, reenable selection using keyboard
Browse files Browse the repository at this point in the history
  • Loading branch information
ob6160 committed Feb 12, 2022
1 parent 29282bb commit c883c2e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
27 changes: 21 additions & 6 deletions src/components/LooMap/LooMap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import AccessibilityList from './AccessibilityList';
import VisuallyHidden from '../VisuallyHidden';
import { Loo } from '../../api-client/graphql';
import { CompressedLooObject } from '../../lib/loo';
import React from 'react';
import router from 'next/router';

const MapTracker = () => {
const [, setMapState] = useMapState();
Expand Down Expand Up @@ -60,11 +62,24 @@ const LooMap: React.FC<LooMapProps> = ({
const [hydratedToilets, setHydratedToilets] = useState<CompressedLooObject[]>(
[]
);
const [announcement, setAnnouncement] = React.useState(null);
const [intersectingToilets, setIntersectingToilets] = useState([]);
const [renderAccessibilityOverlays, setRenderAccessibilityOverlays] =
useState(false);

console.log(intersectingToilets);
const keyboardSelectionHandler = React.useCallback(
(selectionIndex: string | number) => {
const toilet = intersectingToilets[selectionIndex];

if (!toilet) {
return;
}

setAnnouncement(`${toilet.name || 'Unnamed toilet'} selected`);
router.push(`/loos/${toilet.id}`);
},
[intersectingToilets]
);

useEffect(() => {
const loadedLooValues = Array.from(loadedToilets.values()).flatMap(
Expand Down Expand Up @@ -249,17 +264,17 @@ const LooMap: React.FC<LooMapProps> = ({
className="accessibility-box"
toilets={hydratedToilets}
onIntersection={setIntersectingToilets}
onSelection={() => undefined}
onSelection={keyboardSelectionHandler}
center={center}
/>

{/* <AccessibilityList
<AccessibilityList
toilets={intersectingToilets.map(
(toilet: { name: any }) => toilet.name
)}
/> */}
/>

{/* <VisuallyHidden>
<VisuallyHidden>
<div
role="status"
aria-atomic="true"
Expand All @@ -268,7 +283,7 @@ const LooMap: React.FC<LooMapProps> = ({
>
{announcement}
</div>
</VisuallyHidden> */}
</VisuallyHidden>
</>
)}
</MapContainer>
Expand Down
2 changes: 0 additions & 2 deletions src/components/LooMap/Markers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ const Markers: React.FC<{
const surroundingTiles = neighbours.flatMap((n) => ngeohash.neighbors(n));
const neighbourSet = new Set([...surroundingTiles]);

const [mapState] = useMapState();

useEffect(() => {
setLoadedToilets(neighbourSet);
// eslint-disable-next-line react-hooks/exhaustive-deps
Expand Down

0 comments on commit c883c2e

Please sign in to comment.