Anchor Design System

Select3.0

AnchorSelect is a DropDown component that allows the consumer to pass in an array of values, and have the user select a value that will be emitted back to the consumer.

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-select options='["Option 1", "Option 2", "Option 3", "Option 4" ]' label="Select"></anchor-select>
</template>

Import only the components you need for optimal bundle size.

YourComponent.vue
<script setup>
import { AnchorSelect } from '@tryg/vue-ui-library';
</script>
<template>
  <anchor-select options='["Option 1", "Option 2", "Option 3", "Option 4" ]' label="Select"></anchor-select>
</template>

Option formatting

YourComponent.vue
<template>
  <anchor-select options='["Option 1", "Option 2", "Option 3", "Option 4" ]' label="Select"></anchor-select>
</template>

Disabled

YourComponent.vue
<template>
  <anchor-select options='[]' disabled label="Select"></anchor-select>
</template>

Selected item

YourComponent.vue
<template>
  <anchor-select options='["Option 1", "Option 2", "Option 3", "Option 4" ]' selected-index="2" label="Select"></anchor-select>
</template>

CSS variables

The following CSS custom properties are exposed:

VariableDescription
--select-background-colorSet the background color of the <anchor-select>
--select-background-color-listSet the background color of the <anchor-select>'s dropdown list, defaults to the same as the select
--select-border-colorSet the border color of the <anchor-select>
--select-border-color-disabledSet the disabled border color of the <anchor-select>
--select-border-color-errorSet the error border color of the <anchor-select>
--select-border-color-focusSet the focus border color of the <anchor-select>
--select-border-color-hoverSet the hover border color of the <anchor-select>
--select-border-color-readonlySet the readonly border color of the <anchor-select>
--select-border-color-warningSet the warning border color of the <anchor-select>
--select-border-radiusSet the border radius of the <anchor-select>
--select-border-widthSet the border width of the <anchor-select>
--select-border-width-errorSet the border width of the <anchor-select> in case of an error
--select-font-familySet the font-family of the <anchor-select>
--select-list-offsetSet the offset of the <anchor-select> dropdown list
--select-message-gapSet the message gap of the <anchor-select>
--select-text-colorSet the text color of the <anchor-select>
--select-text-color-disabledSet the text color of the <anchor-select> when disabled
--select-text-color-expandedSet the text color of the <anchor-select> when the dropdown is expanded
--select-z-indexSet the z index of the <anchor-select> dropdown

Accessibility

The component is designed to work with both mouse and keyboard navigation, and to be compliant with the Anchor accessibility guidelines.

  • Avoid very long option names to facilitate understanding and perception.
  • Don't use the same word or phrase at the beginning of a set of options.
  • Avoid options that contain headings and interactive elements such as links, buttons or checkboxes.
  • If the dropdown is a required field include the aria-required property and indicate that it is a required field.

API

Select

anchor-select

Properties

PropertyAttributeDescriptionTypeDefault
disableddisabledValue indicating whether or not this particular SelectItem should be disabled from selectingbooleanfalse
errorerrorBoolean value indicating whether or not this particular SelectItem should display an error messagebooleanfalse
expandedexpandedValue indicating whether or not the DropDown select should be expandedbooleanfalse
initialValueinitial-valueValues to be shown in the DropDown selectstring'- Select a value -'
optionsoptionsValues to be shown in the DropDown selectOptionValue[] | string | string[]undefined
requiredrequiredMark the field as requiredbooleanfalse
selectIdselect-idUnique identificator for this DOM node. Default generated by uuidv4.stringuuidv4()
selectedIndexselected-indexThe index of the item which should be pre-selected - defaults to the first item in the Arraynumberundefined
selectedItemselected-item[DEPRECATED] use selectedIndex instead. This has the same functionality, but a better name. This field will be removed 23.12.23

numberundefined
validityMissingValueTextvalidity-missing-value-textText to be displayed if when value is missing an native form validation is usedstringundefined

Events

EventDescriptionType
collapseEvent emitted when the dropdown select collapsesCustomEvent<any>
expandEvent emitted when the dropdown select expandsCustomEvent<any>
selectedEvent emitted when an select-item is selected - containing the value of that select-itemCustomEvent<any>

Methods

collapseComponent(e?: any) => Promise<CustomEvent<any>>

Parameters

NameTypeDescription
eany

Returns

Type: Promise<CustomEvent<any>>

expandAndFocus() => Promise<boolean>

Returns

Type: Promise<boolean>

expandComponent(e?: any) => Promise<CustomEvent<any>>

Parameters

NameTypeDescription
eany

Returns

Type: Promise<CustomEvent<any>>

focusFirst() => Promise<boolean>

Returns

Type: Promise<boolean>

focusLast() => Promise<boolean>

Returns

Type: Promise<boolean>

handleNext(e: any) => Promise<boolean>

Parameters

NameTypeDescription
eany

Returns

Type: Promise<boolean>

handlePressed(e: MouseEvent, index: number) => Promise<CustomEvent<any>>

Parameters

NameTypeDescription
eMouseEvent
indexnumber

Returns

Type: Promise<CustomEvent<any>>

handlePrevious(e: any) => Promise<boolean>

Parameters

NameTypeDescription
eany

Returns

Type: Promise<boolean>

selectAndCollapse(index: number) => Promise<CustomEvent<any>>

Parameters

NameTypeDescription
indexnumber

Returns

Type: Promise<CustomEvent<any>>

setFocus(index?: number) => Promise<boolean>

Parameters

NameTypeDescription
indexnumber

Returns

Type: Promise<boolean>

setSelect(index: number) => Promise<CustomEvent<any>>

Parameters

NameTypeDescription
indexnumber

Returns

Type: Promise<CustomEvent<any>>

CSS Custom Properties

NameDescription
--select-background-colorSet the background color of the
--select-background-color-listSet the background color of the 's dropdown list, defaults to the same as the select
--select-border-colorSet the border color of the
--select-border-color-disabledSet the disabled border color of the
--select-border-color-errorSet the error border color of the
--select-border-color-focusSet the focus border color of the
--select-border-color-hoverSet the hover border color of the
--select-border-color-readonlySet the readonly border color of the
--select-border-color-warningSet the warning border color of the
--select-border-radiusSet the border radius of the
--select-border-widthSet the border width of the
--select-border-width-errorSet the border width of the in case of an error
--select-font-familySet the font-family of the
--select-list-offsetSet the offset of the dropdown list
--select-message-gapSet the message gap of the
--select-text-colorSet the text color of the
--select-text-color-disabledSet the text color of the when disabled
--select-text-color-expandedSet the text color of the when the dropdown is expanded
--select-z-indexSet the z index of the dropdown

Dependencies

Depends on

Graph

graph TD;
  anchor-select --> anchor-label
  anchor-select --> anchor-icon
  anchor-select --> anchor-option
  anchor-option --> anchor-icon
  style anchor-select fill:#f9f,stroke:#333,stroke-width:4px

Built with StencilJS

Select Item

AnchorSelectItem is used inside an AnchorSelect to define individual options. It supports icons, descriptions, disabled state, and selection tracking.

PropertyAttributeDescriptionTypeDefault
valuevalueValue assigned to this SelectItemstring | { value: string; label?: string; description: string }undefined
descriptiondescriptionDescription text for this itemstringundefined
disableddisabledWhether this item is disabledbooleanfalse
selectedselectedWhether this item is already selectedbooleanfalse
iconiconIcon to show inside the itemIconNameundefined
readonlyreadonlyWhether this item is readonlybooleanfalse

Events: @pressed, @next, @previous

anchor-select-item

Properties

PropertyAttributeDescriptionTypeDefault
descriptiondescriptionValue to assigned to this particular SelectItem that will be emitted with the event when its selectedstringundefined
disableddisabledValue indicating whether or not this particular SelectItem should be disabled from selectingbooleanfalse
focusedfocusedValue indicating whether or not this particular SelectItem is already selectedbooleanfalse
iconiconValue indicating an icon to be shown inside of the SelectItem"activity" | "airplay" | "alarm" | "alert-circle" | "alert-octagon" | "alert-triangle" | "align-center" | "align-justify" | "align-left" | "align-right" | "anchor" | "aperture" | "archive" | "arrow-down" | "arrow-down-circle" | "arrow-down-left" | "arrow-down-right" | "arrow-left" | "arrow-left-circle" | "arrow-right" | "arrow-right-circle" | "arrow-up" | "arrow-up-circle" | "arrow-up-left" | "arrow-up-right" | "at-sign" | "award" | "band-aid" | "bar-chart" | "bar-chart-2" | "basket" | "battery" | "battery-charging" | "bell" | "bell-off" | "bluetooth" | "bold" | "bonus-tryghedsgruppen" | "book" | "book-open" | "bookmark" | "box" | "briefcase" | "calculator" | "calendar" | "camera" | "camera-off" | "cast" | "check" | "check-circle" | "check-square" | "chevron-down" | "chevron-left" | "chevron-right" | "chevron-up" | "chevrons-down" | "chevrons-left" | "chevrons-right" | "chevrons-up" | "child" | "chrome" | "circle" | "clipboard" | "clock" | "cloud" | "cloud-drizzle" | "cloud-lightning" | "cloud-off" | "cloud-rain" | "cloud-snow" | "code" | "codepen" | "codesandbox" | "coffee" | "columns" | "command" | "company" | "compass" | "copy" | "corner-down-left" | "corner-down-right" | "corner-left-down" | "corner-left-up" | "corner-right-down" | "corner-right-up" | "corner-up-left" | "corner-up-right" | "cpu" | "credit-card" | "crop" | "crosshair" | "database" | "delete" | "disc" | "divide" | "divide-circle" | "divide-square" | "dollar-sign" | "download" | "download-cloud" | "dribbble" | "droplet" | "edit" | "edit-2" | "edit-3" | "external-link" | "eye" | "eye-off" | "facebook" | "fast-forward" | "feather" | "figma" | "file" | "file-minus" | "file-pdf" | "file-plus" | "file-text" | "film" | "filter" | "flag" | "folder" | "folder-minus" | "folder-plus" | "framer" | "frown" | "gift" | "git-branch" | "git-commit" | "git-merge" | "git-pull-request" | "github" | "gitlab" | "globe" | "grid" | "hard-drive" | "hash" | "headphones" | "heart" | "help-circle" | "hexagon" | "home" | "image" | "inbox" | "info" | "instagram" | "italic" | "key" | "layers" | "layout" | "life-buoy" | "link" | "link-2" | "linkedin" | "list" | "loader" | "lock" | "log-in" | "log-out" | "mail" | "map" | "map-pin" | "maximize" | "maximize-2" | "megaphone" | "meh" | "menu" | "message-circle" | "message-square" | "mic" | "mic-off" | "minimize" | "minimize-2" | "minus" | "minus-circle" | "minus-square" | "monitor" | "moon" | "more-horizontal" | "more-vertical" | "mouse-pointer" | "move" | "music" | "navigation" | "navigation-2" | "octagon" | "offer" | "package" | "paperclip" | "pause" | "pause-circle" | "pen-tool" | "percent" | "phone" | "phone-call" | "phone-forwarded" | "phone-incoming" | "phone-missed" | "phone-off" | "phone-outgoing" | "pie-chart" | "play" | "play-circle" | "plus" | "plus-circle" | "plus-square" | "pocket" | "power" | "printer" | "radio" | "refresh-ccw" | "refresh-cw" | "repeat" | "rewind" | "rotate-ccw" | "rotate-cw" | "rss" | "save" | "scissors" | "search" | "send" | "server" | "settings" | "share" | "share-2" | "shield" | "shield-off" | "shopping-bag" | "shopping-cart" | "shuffle" | "sidebar" | "skip-back" | "skip-forward" | "slack" | "slash" | "sliders" | "smartphone" | "smile" | "speaker" | "sprout" | "square" | "star" | "star-filled" | "stop-circle" | "storm" | "sun" | "sunrise" | "sunset" | "table" | "tablet" | "tag" | "target" | "terminal" | "thermometer" | "thumbs-down" | "thumbs-up" | "toggle-left" | "toggle-right" | "tool" | "trash" | "trash-2" | "trello" | "trending-down" | "trending-up" | "triangle" | "truck" | "trygfonden" | "tv" | "twitch" | "twitter" | "type" | "umbrella" | "underline" | "unlock" | "upload" | "upload-cloud" | "user" | "user-check" | "user-minus" | "user-plus" | "user-x" | "users" | "video" | "video-off" | "voicemail" | "volume" | "volume-1" | "volume-2" | "volume-x" | "watch" | "wifi" | "wifi-off" | "wind" | "x" | "x-circle" | "x-octagon" | "x-square" | "youtube" | "zap" | "zap-off" | "zoom-in" | "zoom-out"undefined
itemIditem-idUnique identificator for this DOM nodestringundefined
readonlyreadonlyValue indicating whether or not this particular SelectItem should be readonlybooleanfalse
selectedselectedValue indicating whether or not this particular SelectItem is already selectedbooleanfalse
valuevalueValue to assigned to this particular SelectItem that will be emitted with the event when its selectedstring | { value: string; label?: string; description: string; }undefined

Events

EventDescriptionType
nextEvent emitted when attempting to navigate to the next SelectItemCustomEvent<any>
pressedEvent emitted when a SelectItem is pressedCustomEvent<any>
previousEvent emitted when attempting to navigate to the previous SelectItemCustomEvent<any>

Methods

emitSelectedEvent(e?: any) => Promise<void>

Parameters

NameTypeDescription
eany

Returns

Type: Promise<void>

CSS Custom Properties

NameDescription
--select-item-background-colorSet the background color of the
--select-item-background-color-disabledSet the background color of the when disabled
--select-item-background-color-hoverSet the background color of the when hovered
--select-item-background-color-pressedSet the background color of the when pressed
--select-item-border-colorSet the border color of the
--select-item-border-color-disabledSet the border color of the when disabled
--select-item-border-color-dividerSet the border color of the divider
--select-item-border-color-divider-disabledSet the border color of the divider when disabled
--select-item-border-color-divider-hoverSet the border color of the divider when hovered
--select-item-border-color-divider-pressedSet the border color of the divider when pressed
--select-item-border-color-hoverSet the border color of the when hovered
--select-item-border-color-pressedSet the border color of the when pressed
--select-item-border-radiusSet the border radius of the
--select-item-border-widthSet the border width of the
--select-item-border-width-focusSet the border width of the when focused
--select-item-cursorSet the cursor of the
--select-item-cursor-disabledSet the cursor of the when disabled
--select-item-cursor-pressedSet the cursor of the when pressed
--select-item-font-familySet the font family of the
--select-item-font-sizeSet the font size of the
--select-item-font-weightSet the font weight of the
--select-item-line-heightSet the line height of the
--select-item-line-height-insideSet the line height inside of the
--select-item-paddingSet the padding of the
--select-item-text-colorSet the text color of the
--select-item-text-color-disabledSet the text color of the when disabled
--select-item-text-color-hoverSet the text color of the when hovered
--select-item-text-color-pressedSet the text color of the when pressed
--select-item-widthSet the width of the

Dependencies

Used by

Depends on

Graph

graph TD;
  anchor-select-item --> anchor-icon
  anchor-phone --> anchor-select-item
  style anchor-select-item fill:#f9f,stroke:#333,stroke-width:4px

Built with StencilJS

On this page