Skip to content

Commit

Permalink
feat(SearchBar): call onSelect when it's provided
Browse files Browse the repository at this point in the history
This handled cozy notes open when Drive needs to provide URL
  • Loading branch information
trollepierre committed Aug 10, 2022
1 parent 2c440e6 commit 615944c
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/components/SearchBar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -229,11 +229,13 @@ class SearchBar extends Component {
this.setState({ query: null, searching: false })
}

onSuggestionSelected = (event, { suggestion }) => {
onSuggestionSelected = async (event, { suggestion }) => {
const { onSelect } = suggestion
// `onSelect` is a string that describes what should happen when the suggestion is selected. Currently, the only format we're supporting is `open:http://example.com` to change the url of the current page.

if (/^open:/.test(onSelect)) {
if (typeof onSelect === 'function') {
await onSelect()
} else if (/^open:/.test(onSelect)) {
const url = onSelect.substr(5)
window.location.href = url
} else {
Expand Down

0 comments on commit 615944c

Please sign in to comment.