Skip to content

Commit da680b6

Browse files
committed
fix(location): suppress nearby locations for mobile if current location already set
fixes #97
1 parent 3664c22 commit da680b6

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

lib/components/form/location-field.js

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ class LocationField extends Component {
239239
label,
240240
showClearButton,
241241
static: isStatic,
242+
suppressNearby,
242243
type,
243244
nearbyStops
244245
} = this.props
@@ -275,10 +276,12 @@ class LocationField extends Component {
275276
// Add to the selection handler lookup (for use in _onKeyDown)
276277
this.locationSelectedLookup[itemIndex] = locationSelected
277278

278-
// Create and add the option item to the menu items array
279-
const currentLocationOption = createOption(optionIcon, optionTitle, locationSelected, itemIndex === activeIndex)
280-
menuItems.push(currentLocationOption)
281-
itemIndex++
279+
if (!suppressNearby) {
280+
// Create and add the option item to the menu items array
281+
const currentLocationOption = createOption(optionIcon, optionTitle, locationSelected, itemIndex === activeIndex)
282+
menuItems.push(currentLocationOption)
283+
itemIndex++
284+
}
282285

283286
/* 2) Process geocode search result option(s) */
284287
if (geocodedFeatures.length > 0) {
@@ -309,7 +312,7 @@ class LocationField extends Component {
309312
}
310313

311314
/* 3) Process nearby transit stop options */
312-
if (nearbyStops.length > 0) {
315+
if (nearbyStops.length > 0 && !suppressNearby) {
313316
// Add the menu sub-heading (not a selectable item)
314317
menuItems.push(<MenuItem header key='ns-header'>Nearby Stops</MenuItem>)
315318

@@ -380,6 +383,8 @@ class LocationField extends Component {
380383
</InputGroup.Addon>
381384

382385
if (isStatic) { // 'static' mode (menu is displayed alongside input)
386+
if (isStatic) {
387+
// 'static' mode (menu is displayed alongside input, e.g., for mobile view)
383388
return (
384389
<div className='location-field static'>
385390
<form>
@@ -393,12 +398,18 @@ class LocationField extends Component {
393398
</InputGroup>
394399
</FormGroup>
395400
</form>
396-
<ul className='dropdown-menu'>
397-
{menuItems}
401+
<ul className='dropdown-menu' style={{ width: '100%' }}>
402+
{menuItems.length > 0 // Show typing prompt to avoid empty screen
403+
? menuItems
404+
: <MenuItem header className={'text-center'}>
405+
Begin typing to search for locations
406+
</MenuItem>
407+
}
398408
</ul>
399409
</div>
400410
)
401-
} else { // default display mode with dropdown menu
411+
} else {
412+
// default display mode with dropdown menu
402413
return (
403414
<form>
404415
<FormGroup className='location-field'>

0 commit comments

Comments
 (0)