Skip to content

Commit

Permalink
Change icon in search control
Browse files Browse the repository at this point in the history
Fixes #380

Add `resetButton` option to `GeoSearchControl` to allow changing the cross icon.

* Add `resetButton` option to `SearchControlProps` interface in `src/SearchControl.ts`.
* Update `defaultOptions` to include `resetButton` with default value '×' in `src/SearchControl.ts`.
* Update `resetButton` element creation to use `resetButton` option value in `src/SearchControl.ts`.
* Add documentation for `resetButton` option in the `GeoSearchControl` section in `docs/usage.mdx`.
  • Loading branch information
ramazansancar committed Jan 22, 2025
1 parent 19e575c commit fe53f39
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/usage.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import { GeoSearchControl, OpenStreetMapProvider } from 'leaflet-geosearch';
const searchControl = new GeoSearchControl({
provider: new OpenStreetMapProvider(),
style: 'bar',
resetButton: '🔍', // Example of using a magnifying glass icon
});

map.addControl(searchControl);
Expand Down
4 changes: 3 additions & 1 deletion src/SearchControl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ const defaultOptions: Omit<SearchControlProps, 'provider'> = {
autoClose: false,
keepResult: false,
updateMap: true,
resetButton: '×',
};

const UNINITIALIZED_ERR =
Expand Down Expand Up @@ -110,6 +111,7 @@ interface SearchControlProps {
autoClose: boolean;
keepResult: boolean;
updateMap: boolean;
resetButton: string;
}

export type SearchControlOptions = Partial<SearchControlProps> & {
Expand Down Expand Up @@ -202,7 +204,7 @@ const Control: SearchControl = {
this.classNames.resetButton,
this.searchElement.form,
{
text: '×',
text: this.options.resetButton,
'aria-label': this.options.clearSearchLabel,
onClick: () => {
if (this.searchElement.input.value === '') {
Expand Down

0 comments on commit fe53f39

Please sign in to comment.