Input autocomplete

A text field that suggests matches from a list as you type, and can also take free text.

Refined portVue source: WildInputAutoComplete.vueReact component: WInputAutocomplete

Try it

Type “pu” and press Enter, then try “ohau”, the arrow keys and Escape.

16 on this account
Choose where this alarm watches.
v-model""@select—
Size
Min characters
Row icons
Sub-lines
Free text
Error
Disabled
<WildInputAutoComplete
  v-model="query"
  :options="sites"
  label="Site or logger"
  hint="16 on this account"
  placeholder="Search sites and loggers"
  help="Choose where this alarm watches."
  size="sm"
  :max-results="6"
  clearable
  @select="watch"
>
  <template #leading>
    <MagnifyingGlassIcon />
  </template>
</WildInputAutoComplete>

When to use

  • Use it to pick one site, logger or person from a long list.
  • Turn on allow-custom when the answer may be outside the list.
  • Turn on clear-on-select to add several in a row.
Don’t use it

Anatomy

The text input’s frame, with a list 4px below. Rows hold a name, optional icon and sub-line, and a tick on the choice.

16 on this account
Pump Shed GatewayGateway · 14 loggers
Pukekohe PackhouseCool store · air temperature
North PumpEmu Park · pressure and flow
South PumpEmu Park · pressure
The typed part is bold, so each row shows why it matched.

Matching

Case, extra spaces and macrons are ignored. Start-of-name matches rank first, then start-of-word, then anywhere.

ranked by where it matches
Hokio Beach BoreHorowhenua · groundwater level
Tank 1 — HomesteadLevel · 22,000 L
Pukekohe PackhouseCool store · air temperature
macrons folded
Ōhau Channel IntakeConsent PW-2231 · flow
“ho” ranks Hokio Beach Bore first and Pukekohe Packhouse last.

Rows

Add an avatar and sub-line when names alone could be confused.

label only · 34px
Kiwifruit — Gold
Kiwifruit — Green
Kiwifruit — Red
Kiwiberry
avatar and sub-line · 44px
Ana Tupouana@emupark.co.nz
Ben HartleyReseller · Hartley Irrigation
Grace Liugrace@emupark.co.nz
Hemi ParataOn call this week · SMS
Showing 4 of 6. Keep typing to narrow.

Free text

With allow-custom, the typed text is the last row. Enter still takes the first match.

matches, then your text
Grace Liugrace@emupark.co.nz
Add “gr”
only your text
Add “sam@emupark.co.nz”

States

rest
hover
focus
error
error, focused
disabled
Focus adds a blue inner edge and halo. Error adds a red edge.
nothing matches
No matches for “bore 99”
reopened on a choice
Bore 12Emu Park · groundwater level
Bore 4River Flat · groundwater level
Bore 9Decommissioned in March
North PumpEmu Park · pressure and flow
South PumpEmu Park · pressure
Hokio Beach BoreHorowhenua · groundwater level
Pump Shed GatewayGateway · 14 loggers
Pukekohe PackhouseCool store · air temperature
Tank 1 — HomesteadLevel · 22,000 L
Tank 3 — Top PaddockLevel · 30,000 L
Soil Probe AKiwifruit Block 2 · soil moisture
Soil Probe BKiwifruit Block 3 · soil moisture
Weather Station 4Emu Park · rain, wind, temperature
Frost Sensor 2Avocado Block 1 · air temperature
Ōhau Channel IntakeConsent PW-2231 · flow
Effluent PondDairy shed · level

In context

Alarm recipients
Soil moisture below 18% · North Pump
People or email addresses
HHemi ParataAAna Tupouops@emupark.co.nz
Message
WildEye: soil moisture at North Pump is 16.2% (below 18%) as of 05:40.
3 recipients.
Each pick empties the field and keeps focus.

Content

  • Label it with what it holds: Site or logger, Recipients.
  • Write the placeholder as what to search: Search sites and loggers.
  • Make custom-label a verb: Use, Add.

Accessibility

Focus stays in the field. Screen readers hear the highlighted row and count.

KeyWhat it does
TypingFilters and highlights the first match.
↓ / ↑Opens the list, or moves the highlight and skips unavailable rows.
SpaceTypes a space. It never picks a row.
EnterTakes the highlighted row, or typed text with allow-custom.
EscapeCloses the list, then clears a clearable field.
TabLeaves without choosing.

Props

PropTypeDefaultDescription
v-modelstring—The query text.
options{ key, value, sub?, leading?, disabled? }[]—Suggestions; disabled ones show but are skipped.
@select(item: KeyValue | string)—The chosen suggestion, or typed text.
labelstring—Visible name.
aria-labelstring—Name when there is no visible label.
hintstring—Context beside the label.
helpstring—Guidance under the field.
errorboolean | stringfalseA string shows as the message.
placeholderstring'Search…'Empty-field text.
min-charsnumber1Characters before the list opens.
max-resultsnumber8Rows before the “keep typing” line.
allow-custombooleanfalseOffer the typed text as a choice.
custom-labelstring'Use'Verb on the free-text row.
clear-on-selectbooleanfalseEmpty the field after each pick.
auto-highlightbooleantrueHighlight the first match.
no-match-textstring'No matches'Said when nothing matches.
clearablebooleanfalseClear button once there is text.
size'sm' | 'lg''sm'36px or 44px.
requiredbooleanfalseMarks the label, sets aria-required.
disabledbooleanfalseFlat grey, takes no input.
v-model:openboolean—Controlled open state.
#leadingslot—Icon ahead of the text.

Tokens

TokenValueWhere it lands
--global-neutral-grey-600#DCDCDEResting border, 1px.
--global-blue-1000#1877F2Focus edge, halo, tick, add mark.
--color-error#E12121Error edge and message.
--global-neutral-grey-500#E6E6E6List edge, disabled border.
--global-neutral-grey-300#F1F1F1Highlighted row.
--global-neutral-grey-200#F5F5F5Disabled ground.
--global-neutral-grey-1000#4F4D55Placeholder and secondary lines.
--shadow-dropdown0 4px 12px rgba(0,0,0,.08), 0 2px 4px rgba(0,0,0,.04)The list surface.
--radius-lg8pxFrame and list corners.
--font-weight-bold600The matched part.