Anchor Design System
Form

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/ui-library

Usage

Individual only imports the desired component, and only needs to be included once within the application. Which is beneficial to keep the application size small.

Webcomponent
<script type="module">
  import { defineCustomElement } from '@tryg/ui-library/dist/components/anchor-select';
  defineCustomElement();
</script>
<anchor-select options='["Option 1", "Option 2", "Option 3", "Option 4" ]'>Select</anchor-select>

Global only needs to be defined once in the application, but it will import all components even the ones that are not in use..

Webcomponent
<script type="module">
  import { defineCustomElements } from '@tryg/ui-library/dist/loader';
  defineCustomElements();
</script>
<anchor-select options='["Option 1", "Option 2", "Option 3", "Option 4" ]'>Select</anchor-select>

Option formatting

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

Disabled

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

Selected item

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

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.23numberundefined
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


Built with StencilJS

On this page