Skip to content

Commit

Permalink
[Search] Customizable placeholder (#378)
Browse files Browse the repository at this point in the history
  • Loading branch information
m-elseberg authored Dec 2, 2024
1 parent 216c1d2 commit 22a0e34
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/quiet-kangaroos-live.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@open-pioneer/search": patch
---

Add placeholder prop to Search component
6 changes: 6 additions & 0 deletions src/packages/search/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ The default value is 5.
<Search mapId={MAP_ID} sources={searchsources} maxResultsPerGroup={10} />
```

To change the placeholder text of the search field, use the optional property `placeholder`:

```tsx
<Search sources={searchsources} placeholder="Search for cities" />
```

### Listening to events

To listen to the events `onSelect` and `onClear`, provide optional callback functions to the component.
Expand Down
8 changes: 7 additions & 1 deletion src/packages/search/Search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ export interface SearchProps extends CommonComponentProps, MapModelProps {
*/
maxResultsPerGroup?: number;

/**
* The placeholder text shown in the search input field when it is empty.
* Defaults to a generic (and localized) hint.
*/
placeholder?: string;

/**
* This event handler will be called when the user selects a search result.
*/
Expand Down Expand Up @@ -172,7 +178,7 @@ export const Search: FC<SearchProps> = (props) => {
selectedOptionColorScheme="trails"
chakraStyles={chakraStyles}
isClearable={true}
placeholder={intl.formatMessage({ id: "searchPlaceholder" })}
placeholder={props.placeholder ?? intl.formatMessage({ id: "searchPlaceholder" })}
closeMenuOnSelect={true}
isLoading={search.kind === "loading"}
options={search.kind === "ready" ? search.results : undefined}
Expand Down

0 comments on commit 22a0e34

Please sign in to comment.