Web Component
<findort-search> is a ready-made address field with suggestions. No framework, no build step, usable with keyboard and screen readers.
Adding it
With a script tag straight from Findort:
<script type="module" src="https://api.findort.ch/sdk/v1/search.js"></script>
<findort-search key="pk_…" country="ch" lang="en" name="address"></findort-search>Or from the npm package, for example with Vite or Webpack:
import 'findort/search';The element works in React, Vue, Svelte, Angular and plain HTML. It needs a public key with your domain.
Versions
The URL contains the version, so you get improvements without anything changing under your feet:
| URL | Behaviour |
|---|---|
/sdk/v1/search.js | Newest 1.x version. Fixes arrive by themselves, breaking changes never do. Recommended. |
/sdk/1.0.0/search.js | Exactly this version, never changes. Good if you want to review everything yourself or pin it with integrity. |
A new major version (v2) gets a new URL. /sdk/v1/ stays.
Attributes
| Attribute | Default | Description |
|---|---|---|
key | Public key pk_… | |
base-url | https://api.findort.ch | API address. An empty value calls your own domain. |
lang | page language | de, fr, it or en. Without it, <html lang> applies. |
country | all countries | ch or ch,li |
types | all types | for example address,poi, see types |
limit | 6 | Number of suggestions, 1 to 20 |
near | lat,lon, prefers nearby results | |
placeholder | Adresse oder Ort suchen | Placeholder text. Set your own for English pages. |
value | Initial value, such as a saved address | |
name | Form field name | |
min-length | 2 | Search starts at this many characters |
debounce | 150 | Wait time in milliseconds after the last keystroke |
disabled | Disables the field |
types, limit, near and min-length take effect immediately, even when changed later. key, base-url, lang, country and debounce are read when the element is inserted into the page. To change them afterwards, set the attribute and insert the element again. placeholder, value and disabled can change at any time.
Events
| Event | detail | When |
|---|---|---|
findort-select | { place } | Someone picked a suggestion. place is a Place. |
change | Right after findort-select, like a normal field | |
findort-error | { error } | A request failed, see errors |
The events bubble and leave the shadow DOM, so you can also listen on the <form>.
const field = document.querySelector('findort-search');
field.addEventListener('findort-select', (e) => {
const { label, address, location } = e.detail.place;
console.log(label, address.postcode, location.lat, location.lon);
});Properties and methods
| Name | Description |
|---|---|
selected | The picked Place, or null as soon as someone types again |
value | Text in the field. Setting it replaces the text and clears selected. |
clear() | Clears the field and the suggestions |
focus() | Moves focus into the input |
In a form
With name the element becomes a form field. On submit it sends the text in the field, which after a pick is the label. If you need coordinates or single address parts, fill hidden inputs in the findort-select event:
<form method="post" action="/order">
<label for="address">Delivery address</label>
<findort-search id="address" key="pk_…" name="address" country="ch" types="address,poi" placeholder="Search an address"></findort-search>
<input type="hidden" name="postcode">
<input type="hidden" name="lat">
<input type="hidden" name="lon">
<button>Order</button>
</form>
<script>
const form = document.querySelector('form');
form.querySelector('findort-search').addEventListener('findort-select', (e) => {
const p = e.detail.place;
form.postcode.value = p.address.postcode ?? '';
form.lat.value = p.location.lat;
form.lon.value = p.location.lon;
});
</script>Styling
The element inherits the page's font and colour. Everything else is controlled by CSS custom properties:
| Property | Default | Affects |
|---|---|---|
--findort-accent | #ffc531 | Focus ring and highlighted suggestion |
--findort-bg | #fff | Background of field and list |
--findort-fg | #14161a | Text colour |
--findort-muted | #8a8a84 | Icons, second line, source notice |
--findort-border | #d6d6cf | Borders |
--findort-radius | 10px | Corner radius |
--findort-font | inherit | Font |
For more control, these parts are available to ::part():
| Part | Element |
|---|---|
input | the input field |
list | the suggestion list |
option | a single suggestion |
findort-search {
--findort-accent: #1f6f4a;
--findort-radius: 4px;
font-size: 1.1rem;
}
findort-search::part(input) {
padding-block: 14px;
}
findort-search::part(option) {
border-bottom: 1px solid #eee;
}Keyboard and accessibility
| Key | Action |
|---|---|
| ↓ | Open the list, next suggestion |
| ↑ | Previous suggestion |
| Enter | Take the highlighted suggestion |
| Esc | Close the list |
| Tab | Leave the field, the list closes |
The field follows the WAI-ARIA combobox pattern: screen readers announce the highlighted suggestion. A <label for="…"> gives the field its name. The first suggestion is highlighted after every search, so Enter takes it right away.
Source notice
Below the suggestions it says "© OpenStreetMap". The notice is required by the ODbL. Do not hide it.