smeijer / leaflet-geosearch

A geocoding/address-lookup library supporting various api providers.
https://smeijer.github.io/leaflet-geosearch/
MIT License
1.02k stars 270 forks source link

feat: close search button when clicking `x` #335

Closed nsilvestri closed 1 year ago

nsilvestri commented 1 year ago

This PR adds behavior to the clear text "x" button while the geosearch is in button mode. If there is no text in the search input, the "x" button will additionally close the search input, exactly as if the primary search button itself was clicked. If there is text in in the search input, the button will behave as before, clearing the text but not closing the button.

As is, this PR does not make this behavior configurable. There are two reasons for this decision:

  1. There is no existing behavior being overwritten with this change, as clicking the "x" without any text is effective a no-op.
  2. There is little reason for a user to click the "x" if the text is already cleared. Therefore, it is reasonable to assume that a user clicking the "x" with an empty search input is not trying to clear text, but rather is attempting to close the search input, because clicking an "x" to close a window is an extremely common design pattern.

This change has no effect on the behavior of the bar variant.

This functionality was requested in #254.

smeijer commented 1 year ago

Thanks! This is really nice. Much appreciated.

smeijer commented 1 year ago

@all-contributors please add @nsilvestri for ideas, code

allcontributors[bot] commented 1 year ago

@smeijer

I've put up a pull request to add @nsilvestri! :tada:

smeijer commented 1 year ago

:tada: This PR is included in version 3.7.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket: