Skip to main content

Basic usage

A button that looks like a select opens a panel with a search box. options lists the choices as { value, text, description }; the description is a second line that is searched too. value sets the first choice. multiple allows several choices: each is a chip with its own remove button, a clear button empties the selection, and the form gets every value. The choice lives in a hidden native <select> that carries name, required, and disabled, so the form submits it as usual. With required, a submit without a choice focuses the button and shows the message. Reset returns every field to its first selection, and the form uses method="get", so after a valid submit the posted fields show in the address bar.

Shown on the product page and used in reports.

Sizes

The size attribute sets the height and text size of the control: small, medium (the default) or large. These are the same sizes as the input and select. A single select changes its trigger; a multiple select changes its field box.

Remote data

Give the component a url that follows the Starkit contract and it needs nothing else but map, which says what an item is. It sends GET url?page=&limit=&search=&filters[field]=&sorts[field]= with JSON headers (every parameter is optional; the first request has no page) and reads { data, links: { next } }. The first page loads when the panel opens, and the next page whenever the user scrolls near the end of the list. Typing restarts from page 1 after a short pause. sorts, filters and limit are fixed values of the field: these fields send sorts[name]=asc, and the server answers 10 categories per page. The categories come from a live endpoint, so the page needs a network connection.

Adapting to your server

The component is a client: it never assumes more than a contract, and it does not force one on your project. By default it speaks the Starkit contract (see Remote data). When your server differs, set only the option that differs: headers (token), params (query string), parse (items and nextPage, null when there is no next page), map (one item to value, text, label, description). A page is a number or a token: firstPage is null (not sent), and the nextPage you return is what params receives next; null means there is no next page, and the component never guesses it, so return it even for page numbers. What the template sends is what params returns: an empty string is sent empty, null and undefined are not sent. When nothing fits, request replaces everything. The fields below talk to a live Laravel paginator endpoint, with only params, parse and map set; the table compares it with the Starkit contract and with a cursor server.

What differs Starkit contract Laravel paginator A cursor server Change this option
Query names page, limit, search, filters[field], sorts[field] page, search, order_by query, limit, after params
How paging works page numbers page numbers a cursor taken from the previous answer params (the page argument) and parse (nextPage)
Where the items are response.data response.data response.results parse
Is there another page? the page of links.next the page of next_page_url next is not null parse (nextPage: null when there is none)
Item fields id, name, description id, name, description code, title, department map
Token, cookies, extra headers none none bearer token headers
Nothing fits – – – request replaces all of the above

States

disabled turns the button off and keeps the panel closed. error shows a message from the server at once; the button gets aria-invalid="true" and a red frame. The three rows below show what a remote list does while it waits, when it has nothing to show and when the request fails.

Options

Every option is optional. They go in x-data="searchableSelect({ … })".

Option Type Default Description
url string – The endpoint of a remote list. Without it the options come from <option> elements or options.
headers object or function { Accept, Content-Type } (JSON) Merged over the defaults. A function may return a Promise: put tokens here.
limit number not sent Items per page. Sent as limit; the server decides when it is missing.
filters object {} Fixed filters of this field, sent as filters[field]=value.
sorts object {} Fixed sorting of this field, sent as sorts[field]=asc|desc.
firstPage number or string null The page of the first request. null is not sent.
params function (term, page) page, limit, search, filters, sorts The query string of one request. Returns an object: an empty string is sent empty, null and undefined are not sent.
parse function (response) data and links.next Returns { items, nextPage }. nextPage: null means there is no next page.
map function (item) the item as it is Turns one item into { value, text, label?, description? }.
request async function (term, page, signal) – Replaces params, headers, fetch, parse and map. Returns { items, nextPage }; pass signal on to cancel a stale request.
minChars number 0 Characters to type before a remote search starts.
delay number (ms) 300 Pause after typing before the search restarts from page 1.
maxChips number 2 Multiple only: chips shown before the rest become “+N”. The box keeps the height of a single select.
options array – Inline JSON options { value, text, description? } rendered by your server.
value string or array – Initial value(s) of a local list.
selected array – Initial options of a remote list, so a saved value shows its text before the list loads.
multiple boolean from the select Allows several options.