@cas-smartdesign/token-selector
v3.0.17
Published
A token-selector based on LitElement
Readme
@cas-smartdesign/token-selector
A token-selector element with SmartDesign 3.0 look & feel.
This element must be used together with the design tokens of SmartDesign. For an independent application, make sure to include the @cas-smartdesign/design-tokens package. For a web app / web widget, refer to the official documentation about design token usage.
Attributes - Token-Selector
selection-mode: string (default = "multi")multi: it is possible to select, deselect existing tokens or create new ones with the help of asd-inputelement.remove-only: there is nosd-inputelement shown, tokens may only be removed.- In addition the property usage of
itemsandselectedIndexesdiffers. Further information below.
placeholder: string (default = null)- Defines the default text content of the selector if there is no selected token present. Just like a placeholder for an HTML input element.
suggest-list-class: string (default = null)- The classname of the suggestion list.
aria-disabled: boolean (default = absent)- Value
truedisables the editing possibilities and closes open suggestions. Any other values or the absence of the attribute means the selector is editable.
- Value
role: string (default = 'listbox')aria-multiselectable: boolean (default = true)aria-activedescendant: string (default = null)- The
idattribute of the currently activesd-token.
- The
aria-haspopup: string (default = 'listbox')- Set only for multi selection mode when the selector has a listbox popup.
token-type: string (default = null)- Shown as a drag shadow suffix after the amount when moving multiple tokens. Without it the drag source is used as a drag image with an indicator from the amount of additional selected tokens.
drop: boolean (default = absent)- Present with empty value when the selector is a potential drop candidate.
drag-source: boolean (default = absent)- Present with empty value while an active dragging started from this selector.
case-sensitive: boolean (default = absent)- Based on its presence - regardless the value - the token-selector differentiates values with or without case sensitive checking.
- Applies to typed values as well as to pasted and dropped tokens. Without it, a pasted or dropped token selects the item with the same caption, or else one whose caption differs only in case.
keep-suggestions-on-select: boolean (default = absent)- When present, the suggestion popover stays open after a value was selected (by click or Enter), so multiple suggestions can be picked in a row. The entered search term is kept as the active filter.
- As the popover only offers not-yet-selected tokens, the selected one disappears from the list, and the popover still closes automatically once no suggestion is left. Escape, Tab and clicking outside close it as usual.
Properties - Token-Selector
selectionMode: string (default = "multi")- Reflects the corresponding attribute.
items: array (default = empty)- The data to be used by the token-selector.
- remove-only
- The passed items are directly visualized as tokens
- multi select
- The passed items are used as the datasource of the token-selector.
- Based on this datasource, tokens are visualized when
selectedIndexesare present. - In addition the datasource is used for the token suggestions, which will be shown when the user starts typing.
selectedIndexes: array (default = empty)- The indexes of the currently selected items.
- Only relevant when the selection mode is multi
placeholder: string (default = null)- Reflects the corresponding attribute.
suggestListClass: string (default = null)- Reflects the
suggest-list-classattribute.
- Reflects the
disabled: boolean (default = false)- Reflects the
aria-disabledattribute.
- Reflects the
tokenGenerator: Default value is the one from the token element.- Tokens can be further customized in addition to the regular properties.
autoSuggestItemGenerator: Default value is the one from the list-item element.- Auto suggest items can be further customized in addition to the regular properties.
tokenType: string (default = null)- Reflects the
token-typeattribute.
- Reflects the
caseSensitive: boolean (default = null)- Reflects the
case-sensitiveattribute.
- Reflects the
keepSuggestionsOnSelect: boolean (default = false)- Reflects the
keep-suggestions-on-selectattribute.
- Reflects the
suggestionFilter: Function (searchTerm: string, allTokens: TokenData[]) => TokenData[]- A custom filter function can be passed to override the default caption based search of suggestions.
suggestionDebounceDelay: number (default = 200)- Milliseconds after the last keystroke before the suggestions open.
isIdle: boolean (read-only)- True while neither the debounced opening of the suggestions nor an element update is pending.
In addition it allows to inject elements with slot named additional-content that is shown right after the tokens part.
Attributes/properties - delegated to the internal sd-input
placeholder: string (default = null)inputLabel: string (default = null)validationMessage: string (default = null)validationIconSrc: string (default = null)validationLevel: string (default = null)
For declarative usage, the camelCase properties map to the attributes input-label,
validationmessage, validationiconsrc and validationlevel.
The embedded sd-input's CSS custom properties (e.g. --sd-input-validation-message-minheight,
--sd-input-wrapper-background-color) work as well: custom properties inherit into the shadow
tree, so setting them on the sd-token-selector (or any ancestor) tunes the internal input.
Attributes - Token
value: string (default = "")- The displayed value of the token.
type: string (default = "")- The type of the token. Used to mark tokens by usecases.
aria-disabled: boolean (default = false)- Indicates if the token can be edited or removed for example. An edited token may provide a delete button as well.
aria-current: boolean (default = false)- Indicates if the token is the active descendant of the relevant
sd-token-selector.
- Indicates if the token is the active descendant of the relevant
aria-checked: boolean (default = false)- Indicates if the token is checked for potentially batch actions like removal or drag and drop.
aria-selected: boolean (default = true)- Set to true initially since every visible token element in a
sd-token-selectorcan be considered as selected. The non-selected ones are not present in the DOM normally.
Properties - Token
value,type- Reflect the corresponding attributes.
icon: string (default = "")- Defines the icon url. If present the icon is shown at the start of the token.
iconPlaceholder: string (default = "")- Defines the placeholder icon of the token
iconBackgroundColor: string (default = "")- Defines the background color of the icon container. Only relevant when the icon has a transparent background.
statusIcon: string (default = "")- Defines the url of a small status icon (12px) overlaid on the bottom-right corner of the token's icon.
- Only shown when
iconoriconPlaceholderis present. The default token generator populates it from the item'sstatusIconfield.
disabled- Reflects the
aria-disabledattribute.
- Reflects the
current- Reflects the
aria-currentattribute.
- Reflects the
checked- Reflects the
aria-checkedattribute. - A disabled token cannot be checked: disabling a checked token unchecks it.
- Reflects the
In addition it allows to inject elements with slots named before-icon & after-icon.
CSS Custom Properties & parts
--sd-token-icon-background-color- Defines the icon background color of the token.
--sd-token-icon-border-radius- Defines the border radius of the icon of the token.
--sd-token-icon-height- Defines the height of the icon of the token.
--sd-token-icon-margin- Defines the margin of the icon of the token.
--sd-token-icon-width- Defines the width of the icon of the token.
remove-only-placeholderpart- Applies to the placeholder text which is shown when the selector has no selection in
remove-onlymode.
- Applies to the placeholder text which is shown when the selector has no selection in
iconpart of tokens- Applies to the icon element within the wrapper around it that defines the
iconBackgroundColorfor example.
- Applies to the icon element within the wrapper around it that defines the
Custom Events
sd-token-selector-token-clicked- Dispatched when a token is clicked.
- Contains the index of the token in the items list and the referenced HTML Element.
sd-token-selector-tokens-removed- Dispatched when the remove button of a token is clicked or checked tokens are removed via keyboard.
- Contains the indexes of the removed tokens in the items list.
- Contains also an updated list of selectedIndices if the selection-mode is
multi.
sd-token-selector-tokens-selected- Dispatched when an existing and not yet selected token was selected.
- Contains the indexes of the selected tokens in the items list and the updated selectedIndices.
sd-token-selector-token-created- Dispatched when a not existing token value was submitted.
- Contains the value of the new token.
sd-token-selector-auto-suggest-initialized- Dispatched when the auto suggest popover is shown for the first time.
Focus ring
The token-selector does not draw focus rings itself — they are drawn by
@cas-smartdesign/focus-ring (an optional peer dependency). Install it
once per application, not per component:
import { FocusRing } from "@cas-smartdesign/focus-ring";
FocusRing.install();