Anchor Design System

Select

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

Usage

Webcomponent
<anchor-select options="[]"></anchor-select>

Option formatting

Webcomponent with options
<anchor-select options='["Option 1", "Option 2", "Option 3", "Option 4" ]'>Select</anchor-select>

Disabled

Webcomponent disabled
<anchor-select options="[]" disabled></anchor-select>

Selected item

Webcomponent
<anchor-select options="['Option 1','Option 2','Option 3']" selectedIndex="2"></anchor-select>

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

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

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

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

On this page