@@ -7,7 +7,7 @@ import { memoize } from 'proxy-memoize'
77import { useSearchParams } from "react-router-dom" ;
88
99// Internal imports
10- import { getRoutes , shortenToOneDecimal } from '../data/routes' ;
10+ import { compareRoutes , getRoutes , shortenToOneDecimal } from '../data/routes' ;
1111import {
1212 clearSearchedRoutes ,
1313 clearSelectedRoute ,
@@ -189,6 +189,12 @@ const RouteSearch = forwardRef((props, ref) => {
189189 dispatch ( updateSearchLocationTo ( [ ] ) ) ;
190190 }
191191
192+ const selectRouteOption = ( route ) => {
193+ if ( ! compareRoutes ( route , selectedRoute ) ) {
194+ dispatch ( updateSelectedRoute ( route ) ) ;
195+ }
196+ }
197+
192198 // Rendering
193199 return (
194200 < div ref = { ref } className = 'routing routing-outer-container' >
@@ -246,6 +252,31 @@ const RouteSearch = forwardRef((props, ref) => {
246252 ) : (
247253 hasLocation &&
248254 < div className = "route-search-actions-container" >
255+ { searchedRoutes && searchedRoutes . length > 0 &&
256+ < div className = "route-alt-options" >
257+ { searchedRoutes . map ( ( route , index ) => {
258+ const isSelected = compareRoutes ( route , selectedRoute ) ;
259+ const routeLabel = route . criteria === 'fastest' ? 'A' : 'B' ;
260+ const roundedDistance = Math . round ( route . distance ) ;
261+
262+ return (
263+ < button
264+ key = { index }
265+ type = "button"
266+ className = { `route-alt-option${ isSelected ? ' selected' : '' } ` }
267+ onClick = { ( ) => selectRouteOption ( route ) }
268+ aria-label = { `Route ${ routeLabel } , ${ roundedDistance } kilometers` }
269+ aria-pressed = { isSelected } >
270+ { searchedRoutes . length > 1 &&
271+ < span className = "route-alt-option__label" > { routeLabel } </ span >
272+ }
273+ < span className = "route-alt-option__distance" > { roundedDistance } km</ span >
274+ </ button >
275+ ) ;
276+ } ) }
277+ </ div >
278+ }
279+
249280 < div className = "route-search-actions" >
250281 { validSearch &&
251282 < button type = "button" className = "route-search-link" onClick = { ( ) => swapHandler ( ) } >
0 commit comments