Anchor Design System

Typeahead2.0

Typeahead description

WORK IN PROGRESS: This component has not gone through final testing and a11y validation. It may see breaking changes in the near future based on the feedback from testing.

Installation

npm i @tryg/vue-ui-library

Usage

Install the component library as a Vue plugin. This globally registers all Anchor components.

main.js
import { createApp } from 'vue';
import { ComponentLibrary } from '@tryg/vue-ui-library';
import App from './App.vue';

const app = createApp(App);
app.use(ComponentLibrary);
app.mount('#app');
YourComponent.vue
<template>
  <anchor-typeahead label="Hello"></anchor-typeahead>
</template>

Import only the components you need for optimal bundle size.

YourComponent.vue
<script setup>
import { AnchorTypeahead } from '@tryg/vue-ui-library';
</script>
<template>
  <anchor-typeahead label="Hello"></anchor-typeahead>
</template>

Disabled

YourComponent.vue
<template>
  <anchor-typeahead disabled label="Hello"></anchor-typeahead>
</template>

Read Only

YourComponent.vue
<template>
  <anchor-typeahead readonly label="Hello"></anchor-typeahead>
</template>

Required

If you pass the required property to the input, the input will be required.

YourComponent.vue
<template>
  <anchor-typeahead required label="Hello"></anchor-typeahead>
</template>

Help text

You can add a helpful text to the input by passing the help-text property.

YourComponent.vue
<template>
  <anchor-typeahead help-text="This is a help text" label="Hello"></anchor-typeahead>
</template>

With Error Message

You can combine the error-prop properties to show an invalid input.

YourComponent.vue
<template>
  <anchor-typeahead error-prop="This is an error message" label="Hello"></anchor-typeahead>
</template>

Accessibility

  • Uses role="combobox" with aria-autocomplete="list" to communicate the autocomplete behavior to assistive technology.
  • The dropdown list uses role="listbox" with individual options marked as role="option", following the ARIA combobox pattern.
  • Arrow key navigation moves focus through the available options, with aria-activedescendant tracking the currently focused option.
  • Pressing Enter selects the focused option, collapsing the dropdown and updating the input value.
  • The aria-expanded attribute reflects whether the dropdown is open or closed, and aria-controls links the input to its listbox.

API

anchor-typeahead

WORK IN PROGRESS: This component has not gone through final testing and a11y validation. It may see breaking changes in the near future based on the feedback from testing.

How to use the typeahead component

Basic typeahead

<anchor-typeahead options='["foo","bar","foobar"]' language="NO" texts='{"noResult":"The search yeilded no results"}'></anchor-typeahead>

Properties

PropertyAttributeDescriptionTypeDefault
disableddisabledValue indicating whether or not this typeahead should be disabledbooleanundefined
errorProperror-propShow an error messagestring''
filterfilterThe type of filter to use"contains" | "containsWords" | "custom" | "startsWith"'containsWords'
inputIdinput-idThe id of the input fieldstring`anchor-typeahead-${uuidv4()}`
labellabelLabel for the input fieldstringundefined
languagelanguageThe display language for the component."DK" | "NO"'NO'
limitNumberOfVisibleOptionslimit-number-of-visible-optionsWhen this is true, the component will have a maximum number of options to show, determined by the numberOfOptionsToDisplay prop. Default value is false.booleanfalse
messagePlacementmessage-placementThis prop decides if the messages should render between the label of an input and the input field, or below the input field."below" | "inside"undefined
numberOfOptionsToDisplaynumber-of-options-to-displayThe maximum number of options to display when limitNumberOfVisibleOptions is true. Default value is 100.number100
optionsoptionsArray of options to choose from, a JSON serialized string or an array of OptionValueOptionValue[] | stringundefined
placeholderplaceholderPlaceholder for the input fieldstringundefined
readonlyreadonlySet the field to be read onlybooleanfalse
requiredrequiredMark the field as requiredbooleanfalse
showAllOptionsshow-all-optionsThis prop decides if the component should show all available options before the user has typed a search phrase.booleantrue
textstextsOverride some, or all, texts used internally in the componentstringJSON.stringify({})
uuiduuidThe id of the input fieldstringuuidv4()
validityMissingValueTextvalidity-missing-value-textText to be displayed if when value is missing an native form validation is usedstringundefined
valuevalueThe value of the input fieldstring''
whitespaceCharacters--Array of strings which should be treated as whitespace to make it easier to match resultsstring[]undefined

Events

EventDescriptionType
collapseEvent emitted when the dropdown select collapsesCustomEvent<any>
expandEvent emitted when the dropdown select expandsCustomEvent<any>
inputChange[DEPRECATED] this event has been replaced by the selected event. inputChange is emitted by the underlying anchor-input. Will be removed 20.12.2023

CustomEvent<any>
selectedEvent emitted when a valid option has been selectedCustomEvent<any>

CSS Custom Properties

NameDescription
--typeahead-border-colorSet the border color of the
--typeahead-border-color-disabledSet the disabled border color of the
--typeahead-border-color-errorSet the error border color of the
--typeahead-border-color-focusSet the focus border color of the
--typeahead-border-color-hoverSet the hover border color of the
--typeahead-border-color-readonlySet the readonly border color of the
--typeahead-border-color-warningSet the warning border color of the
--typeahead-border-radiusSet the border radius of the
--typeahead-border-widthSet the border width of the
--typeahead-font-weight-labelSet the font weight of the label
--typeahead-icon-colorSet the icon color of the icon
--typeahead-icon-color-disabledSet the icon color of the icon when disabled
--typeahead-max-widthSet the max width of the
--typeahead-outlineSet the outline of the
--typeahead-widthSet the width of the
--typeahead-z-indexSet the z index of the

Dependencies

Depends on

Graph

graph TD;
  anchor-typeahead --> anchor-input
  anchor-typeahead --> anchor-option
  anchor-input --> anchor-form-field
  anchor-input --> anchor-icon
  anchor-input --> anchor-tooltip
  anchor-form-field --> anchor-icon
  anchor-option --> anchor-icon
  style anchor-typeahead fill:#f9f,stroke:#333,stroke-width:4px

Built with StencilJS

On this page