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:

HTML
<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:

JavaScript
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:

URLBehaviour
/sdk/v1/search.jsNewest 1.x version. Fixes arrive by themselves, breaking changes never do. Recommended.
/sdk/1.0.0/search.jsExactly 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

AttributeDefaultDescription
keyPublic key pk_…
base-urlhttps://api.findort.chAPI address. An empty value calls your own domain.
langpage languagede, fr, it or en. Without it, <html lang> applies.
countryall countriesch or ch,li
typesall typesfor example address,poi, see types
limit6Number of suggestions, 1 to 20
nearlat,lon, prefers nearby results
placeholderAdresse oder Ort suchenPlaceholder text. Set your own for English pages.
valueInitial value, such as a saved address
nameForm field name
min-length2Search starts at this many characters
debounce150Wait time in milliseconds after the last keystroke
disabledDisables 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

EventdetailWhen
findort-select{ place }Someone picked a suggestion. place is a Place.
changeRight 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>.

JavaScript
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

NameDescription
selectedThe picked Place, or null as soon as someone types again
valueText 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:

HTML
<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:

PropertyDefaultAffects
--findort-accent#ffc531Focus ring and highlighted suggestion
--findort-bg#fffBackground of field and list
--findort-fg#14161aText colour
--findort-muted#8a8a84Icons, second line, source notice
--findort-border#d6d6cfBorders
--findort-radius10pxCorner radius
--findort-fontinheritFont

For more control, these parts are available to ::part():

PartElement
inputthe input field
listthe suggestion list
optiona single suggestion
CSS
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

KeyAction
↓Open the list, next suggestion
↑Previous suggestion
EnterTake the highlighted suggestion
EscClose the list
TabLeave 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.