@scania/tegel
Version:
Tegel Design System
1,129 lines (1,128 loc) • 45.3 kB
JavaScript
import { Host, h, } from "@stencil/core";
import findNextFocusableElement from "../../utils/findNextFocusableElement";
import findPreviousFocusableElement from "../../utils/findPreviousFocusableElement";
import appendHiddenInput from "../../utils/appendHiddenInput";
import { convertToString, convertArrayToStrings } from "../../utils/convertToString";
import generateUniqueId from "../../utils/generateUniqueId";
function hasValueChanged(newValue, currentValue) {
if (newValue.length !== currentValue.length)
return true;
return newValue.some((val) => !currentValue.includes(val));
}
/**
* @slot <default> - <b>Unnamed slot.</b> For dropdown option elements.
*/
export class TdsDropdown {
constructor() {
this.setDefaultOption = () => {
if (this.internalDefaultValue) {
// Convert the internal default value to an array if it's not already
const defaultValues = this.multiselect
? this.internalDefaultValue.split(',')
: [this.internalDefaultValue];
this.updateDropdownStateInternal(defaultValues);
}
};
this.getChildren = () => {
const tdsDropdownOptions = Array.from(this.host.children).filter((element) => element.tagName === 'TDS-DROPDOWN-OPTION');
if (tdsDropdownOptions.length === 0) {
console.warn('TDS DROPDOWN: No options found. Disregard if loading data asynchronously.');
}
return tdsDropdownOptions;
};
this.getSelectedChildren = () => {
if (this.selectedOptions.length === 0)
return [];
return this.selectedOptions
.map((stringValue) => {
var _a;
const matchingElement = (_a = this.getChildren()) === null || _a === void 0 ? void 0 : _a.find((element) => convertToString(element.value) === convertToString(stringValue));
return matchingElement;
})
.filter(Boolean);
};
this.getSelectedChildrenLabels = () => {
var _a;
return (_a = this.getSelectedChildren()) === null || _a === void 0 ? void 0 : _a.map((element) => element.textContent.trim());
};
this.getValue = () => {
const labels = this.getSelectedChildrenLabels();
if (!labels) {
return '';
}
return labels === null || labels === void 0 ? void 0 : labels.join(', ');
};
this.setValueAttribute = () => {
if (this.selectedOptions.length === 0) {
this.host.removeAttribute('value');
}
else {
this.host.setAttribute('value', this.selectedOptions.join(','));
}
};
this.getOpenDirection = () => {
var _a, _b, _c, _d, _e;
if (this.openDirection === 'auto' || !this.openDirection) {
const dropdownMenuHeight = (_b = (_a = this.dropdownList) === null || _a === void 0 ? void 0 : _a.offsetHeight) !== null && _b !== void 0 ? _b : 0;
const distanceToBottom = (_e = (_d = (_c = this.host).getBoundingClientRect) === null || _d === void 0 ? void 0 : _d.call(_c).top) !== null && _e !== void 0 ? _e : 0;
const viewportHeight = window.innerHeight;
if (distanceToBottom + dropdownMenuHeight + 57 > viewportHeight) {
return 'up';
}
return 'down';
}
return this.openDirection;
};
this.handleToggleOpen = () => {
if (!this.disabled) {
this.open = !this.open;
if (this.open) {
if (this.filter) {
this.focusInputElement();
}
else {
const button = this.host.shadowRoot.querySelector('button');
if (button) {
button.focus();
}
}
}
}
};
this.focusInputElement = () => {
if (this.inputElement)
this.inputElement.focus();
};
this.handleFilter = (event) => {
this.tdsInput.emit(event);
const query = event.target.value.toLowerCase();
/* Check if the query is empty, and if so, show all options */
const children = this.getChildren();
if (query === '') {
children.forEach((element) => {
element.removeAttribute('hidden');
return element;
});
this.filterResult = null;
/* Hide the options that do not match the query */
}
else {
this.filterResult = children.filter((element) => {
if (!this.normalizeString(element.textContent)
.toLowerCase()
.includes(this.normalizeString(query).toLowerCase())) {
element.setAttribute('hidden', '');
}
else {
element.removeAttribute('hidden');
}
return !element.hasAttribute('hidden');
}).length;
}
};
this.handleFilterReset = () => {
this.reset();
this.inputElement.value = '';
this.handleFilter({ target: { value: '' } });
this.inputElement.focus();
// Add this line to ensure internal value is cleared
this.internalValue = '';
};
this.handleFocus = (event) => {
this.open = true;
this.filterFocus = true;
if (this.multiselect && this.inputElement) {
this.inputElement.value = '';
}
this.tdsFocus.emit(event);
if (this.filter) {
this.handleFilter({ target: { value: '' } });
}
};
this.handleBlur = (event) => {
this.tdsBlur.emit(event);
};
this.resetInput = () => {
const inputEl = this.host.querySelector('input');
if (inputEl) {
this.reset();
}
};
this.name = undefined;
this.disabled = false;
this.helper = undefined;
this.label = undefined;
this.labelPosition = undefined;
this.modeVariant = null;
this.openDirection = 'auto';
this.placeholder = undefined;
this.size = 'lg';
this.animation = 'slide';
this.error = false;
this.multiselect = false;
this.filter = false;
this.normalizeText = true;
this.noResultText = 'No result';
this.defaultValue = undefined;
this.value = null;
this.tdsAriaLabel = undefined;
this.open = false;
this.internalValue = undefined;
this.filterResult = undefined;
this.filterFocus = undefined;
this.internalDefaultValue = undefined;
this.selectedOptions = [];
}
handleValueChange(newValue) {
// Normalize to array
const normalizedValue = this.normalizeValue(newValue);
// Only update if actually changed
if (hasValueChanged(normalizedValue, this.selectedOptions)) {
this.updateDropdownStateFromUser(normalizedValue);
}
}
normalizeValue(value) {
if (value === null || value === undefined || value === '')
return [];
// For single select, ensure we handle both string and array inputs
if (!this.multiselect) {
// If array is passed to single select, take first value
if (Array.isArray(value)) {
return [convertToString(value[0])];
}
return [convertToString(value)];
}
// For multiselect
if (Array.isArray(value)) {
return convertArrayToStrings(value);
}
// Handle comma-separated string for multiselect
return value
.toString()
.split(',')
.filter((v) => v !== '');
}
updateDropdownStateInternal(values) {
this.updateDropdownState(values, false);
}
updateDropdownStateFromUser(values) {
this.updateDropdownState(values, true);
}
updateDropdownState(values, emitChange = true) {
// Validate the values first
const validValues = this.validateValues(values);
// Update internal state
this.selectedOptions = [...validValues];
// Update the value prop
this.value = this.multiselect ? this.selectedOptions : this.selectedOptions[0] || null;
// Update internal value for display
this.internalValue = this.getValue();
// Update DOM
this.updateOptionElements();
// Update display value
this.updateDisplayValue();
// Emit change event only if value has changed by user
if (emitChange)
this.emitChange();
// Update value attribute
this.setValueAttribute();
}
validateValues(values) {
// Make sure we have children before validation
const children = this.getChildren();
if (!children || children.length === 0) {
console.warn('No dropdown options found');
return values; // Return original values if no children yet
}
return values.filter((val) => {
const isValid = children.some((element) => convertToString(element.value) === convertToString(val));
if (!isValid) {
console.warn(`Option with value "${val}" does not exist`);
}
return isValid;
});
}
updateOptionElements() {
var _a;
(_a = this.getChildren()) === null || _a === void 0 ? void 0 : _a.forEach((element) => {
// Convert element.value to string for comparison
element.setSelected(this.selectedOptions.includes(convertToString(element.value)));
});
}
updateDisplayValue() {
this.internalValue = this.getSelectedChildrenLabels().join(', ');
if (this.filter && this.inputElement) {
this.inputElement.value = this.internalValue;
}
}
emitChange() {
const value = this.multiselect
? this.selectedOptions.join(',')
: this.selectedOptions[0] || null;
this.tdsChange.emit({
name: this.name,
value: value !== null && value !== void 0 ? value : null,
});
}
/** Method for setting the selected value of the Dropdown.
*
* Single selection example:
*
* <code>
* dropdown.setValue('option-1', 'Option 1');
* </code>
*
* Multiselect example:
*
* <code>
* dropdown.setValue(['option-1', 'option-2']);
* </code>
*/
// @ts-expect-error for label: the label is optional here ONLY to not break the API. Should be removed for 2.0.
// eslint-disable-next-line no-unused-vars, @typescript-eslint/no-unused-vars
async setValue(value, label) {
let normalizedValue;
if (Array.isArray(value)) {
normalizedValue = convertArrayToStrings(value);
}
else {
normalizedValue = [convertToString(value)];
}
this.updateDropdownStateFromUser(normalizedValue);
return this.getSelectedChildren().map((element) => ({
value: element.value,
label: element.textContent.trim(),
}));
}
async reset() {
this.updateDropdownStateFromUser([]);
}
async removeValue(oldValue) {
const newValues = this.selectedOptions.filter((v) => v !== oldValue);
this.updateDropdownStateFromUser(newValues);
}
/** Method that forces focus on the input element. */
async focusElement() {
if (this.filter) {
// For filter mode, focus the input element
this.focusInputElement();
}
else {
// For non-filter mode, focus the button element
const button = this.host.shadowRoot.querySelector('button');
if (button) {
button.focus();
}
}
// Always trigger the focus event to open the dropdown
this.handleFocus({});
}
/** Method for closing the Dropdown. */
async close() {
this.open = false;
}
/** Method to force update the dropdown display value.
* Use this method when you programmatically change the text content of dropdown options
* to ensure the selected value display updates immediately.
*/
async updateDisplay() {
this.updateDisplayValue();
}
onAnyClick(event) {
if (this.open) {
// Source: https://lamplightdev.com/blog/2021/04/10/how-to-detect-clicks-outside-of-a-web-component/
const isClickOutside = !event.composedPath().includes(this.host);
if (isClickOutside) {
this.open = false;
}
}
}
async onKeyDown(event) {
var _a;
// Get the active element
const { activeElement } = document;
if (!activeElement) {
return;
}
const children = this.getChildren();
if (event.key === 'ArrowDown') {
/* Get the index of the current focus index, if there is no
nextElementSibling return the index for the first child in our Dropdown. */
const startingIndex = activeElement.nextElementSibling
? children.findIndex((element) => element === activeElement.nextElementSibling)
: 0;
const elementIndex = findNextFocusableElement(children, startingIndex);
children[elementIndex].focus();
}
else if (event.key === 'ArrowUp') {
/* Get the index of the current focus index, if there is no
previousElementSibling return the index for the first last in our Dropdown. */
const startingIndex = activeElement.nextElementSibling
? this.getChildren().findIndex((element) => element === activeElement.previousElementSibling)
: 0;
const elementIndex = findPreviousFocusableElement(children, startingIndex);
children[elementIndex].focus();
}
else if (event.key === 'Escape') {
this.open = false;
// Return focus to input/button when Escape key is used
if (this.filter) {
(_a = this.inputElement) === null || _a === void 0 ? void 0 : _a.focus();
}
else {
const button = this.host.shadowRoot.querySelector('button');
button === null || button === void 0 ? void 0 : button.focus();
}
}
}
// If the Dropdown gets closed,
// this sets the value of the dropdown to the current selection labels or null if no selection is made.
handleOpenState() {
if (this.filter && this.multiselect) {
if (!this.open) {
this.inputElement.value = this.selectedOptions.length ? this.getValue() : '';
}
}
// Update the inert state of dropdown list when open state changes
this.updateDropdownListInertState();
}
handleDefaultValueChange(newValue) {
if (newValue !== undefined && newValue !== null) {
this.internalDefaultValue = convertToString(newValue);
this.setDefaultOption();
}
}
componentWillLoad() {
// First handle the value prop if it exists
if (this.value !== null && this.value !== undefined) {
const normalizedValue = this.normalizeValue(this.value);
this.updateDropdownStateInternal(normalizedValue);
return; // Exit early if we handled the value prop
}
// Only use defaultValue if no value prop was provided
if (this.defaultValue !== null && this.defaultValue !== undefined) {
const defaultValueStr = convertToString(this.defaultValue);
const initialValue = this.multiselect
? defaultValueStr.split(',').map(convertToString)
: [defaultValueStr];
this.updateDropdownStateInternal(initialValue);
}
}
/** Method to handle slot changes */
handleSlotChange() {
this.setDefaultOption();
}
/** Method to check if we should normalize text */
normalizeString(text) {
return this.normalizeText ? text.normalize('NFD').replace(/\p{Diacritic}/gu, '') : text;
}
/**
* @internal
*/
async appendValue(value) {
if (this.multiselect) {
this.updateDropdownStateFromUser([...this.selectedOptions, value]);
}
else {
this.updateDropdownStateFromUser([value]);
}
}
componentDidRender() {
const form = this.host.closest('form');
if (form) {
form.addEventListener('reset', this.resetInput);
}
// Initialize inert state after rendering
this.updateDropdownListInertState();
}
disconnectedCallback() {
const form = this.host.closest('form');
if (form) {
form.removeEventListener('reset', this.resetInput);
}
}
connectedCallback() {
if (!this.tdsAriaLabel) {
console.warn('Tegel Dropdown component: tdsAriaLabel prop is missing');
}
}
updateDropdownListInertState() {
if (this.dropdownList) {
if (this.open) {
this.dropdownList.removeAttribute('inert');
}
else {
this.dropdownList.setAttribute('inert', '');
}
}
}
render() {
appendHiddenInput(this.host, this.name, this.selectedOptions.join(','), this.disabled);
// Generate unique IDs for associating labels and helpers with the input/button
const labelId = this.label ? `dropdown-label-${this.name || generateUniqueId()}` : undefined;
const helperId = this.helper ? `dropdown-helper-${this.name || generateUniqueId()}` : undefined;
return (h(Host, { key: '676f9d61c5fd8488cedbc949757e992be13e49eb', class: {
[`tds-mode-variant-${this.modeVariant}`]: Boolean(this.modeVariant),
} }, this.label && this.labelPosition === 'outside' && (h("div", { key: 'ac4f3c9ca2719acc72f06ae977bf032d05913c6d', id: labelId, class: `label-outside ${this.disabled ? 'disabled' : ''}` }, this.label)), h("div", { key: 'c9d4142f63e315c73daef5038f266a32b05559a1', class: {
'dropdown-select': true,
[this.size]: true,
'disabled': this.disabled,
} }, this.filter ? (h("div", { class: {
filter: true,
focus: this.filterFocus,
disabled: this.disabled,
error: this.error,
} }, h("div", { class: "value-wrapper" }, this.label && this.labelPosition === 'inside' && this.placeholder && (h("div", { id: labelId, class: `label-inside ${this.size}` }, this.label)), this.label && this.labelPosition === 'inside' && !this.placeholder && (h("div", { id: labelId, class: `
label-inside-as-placeholder
${this.size}
${this.selectedOptions.length ? 'selected' : ''}
` }, this.label)), h("input", { "aria-label": this.tdsAriaLabel, "aria-labelledby": labelId, "aria-describedby": helperId, "aria-disabled": this.disabled,
// eslint-disable-next-line no-return-assign
ref: (inputEl) => (this.inputElement = inputEl), class: {
placeholder: this.labelPosition === 'inside',
}, type: "text", placeholder: this.filterFocus ? '' : this.placeholder, value: this.multiselect && this.filterFocus ? '' : this.getValue(), disabled: this.disabled, onInput: (event) => this.handleFilter(event), onBlur: (event) => {
this.filterFocus = false;
if (this.multiselect) {
this.inputElement.value = this.getValue();
}
this.handleBlur(event);
}, onFocus: (event) => this.handleFocus(event), onKeyDown: (event) => {
if (event.key === 'Escape') {
this.open = false;
}
} })), h("tds-icon", { tabIndex: 0, role: "button", "aria-label": "Clear filter", svgTitle: "Clear filter", onClick: this.handleFilterReset, onKeyDown: (event) => {
if (event.key === 'Enter') {
this.handleFilterReset();
}
}, class: {
'clear-icon': true,
'hide': !(this.open && this.inputElement.value !== ''),
}, name: "cross", size: "16px" }), h("tds-icon", { tdsAriaHidden: true, role: "button", "aria-label": "Open/Close dropdown", svgTitle: "Open/Close dropdown", onClick: this.handleToggleOpen, onKeyDown: (event) => {
if (event.key === 'Enter') {
this.handleToggleOpen();
}
}, class: `menu-icon ${this.open ? 'open' : 'closed'}`, name: "chevron_down", size: "16px" }))) : (h("button", { "aria-label": this.tdsAriaLabel, "aria-labelledby": labelId, "aria-describedby": helperId, "aria-disabled": this.disabled, onClick: () => this.handleToggleOpen(), onKeyDown: (event) => {
if (event.key === 'Escape') {
this.open = false;
}
}, class: `
${this.selectedOptions.length ? 'value' : 'placeholder'}
${this.open ? 'open' : 'closed'}
${this.error ? 'error' : ''}
`, disabled: this.disabled }, h("div", { class: `value-wrapper ${this.size}` }, this.label && this.labelPosition === 'inside' && this.placeholder && (h("div", { id: labelId, class: `label-inside ${this.size}` }, this.label)), this.label && this.labelPosition === 'inside' && !this.placeholder && (h("div", { id: labelId, class: `
label-inside-as-placeholder
${this.size}
${this.selectedOptions.length ? 'selected' : ''}
` }, this.label)), h("div", { class: `placeholder ${this.size}` }, this.selectedOptions.length ? this.getValue() : this.placeholder), h("tds-icon", { "aria-label": "Open/Close dropdown", svgTitle: "Open/Close dropdown", class: `menu-icon ${this.open ? 'open' : 'closed'}`, name: "chevron_down", size: "16px" }))))), h("div", { key: '6de931198040eec79815f83e2617d2646507b6a1', role: "listbox", "aria-label": this.tdsAriaLabel, inert: !this.open, "aria-orientation": "vertical", "aria-multiselectable": this.multiselect, ref: (element) => {
this.dropdownList = element;
}, class: {
'dropdown-list': true,
[this.size]: true,
[this.getOpenDirection()]: true,
'label-outside': this.label && this.labelPosition === 'outside',
'open': this.open,
'closed': !this.open,
[`animation-enter-${this.animation}`]: this.animation !== 'none' && this.open,
[`animation-exit-${this.animation}`]: this.animation !== 'none' && !this.open,
} }, h("slot", { key: '61ab9737181371073b25b95c34dad3311c2995c0', onSlotchange: () => this.handleSlotChange() }), this.filterResult === 0 && this.noResultText !== '' && (h("div", { key: 'aca39f881a57a6a23de03da78b5062e5dff55af7', class: `no-result ${this.size}` }, this.noResultText))), this.helper && (h("div", { key: '1e4221e58bc16608bfb0f780b7bc8040935eab37', id: helperId, class: {
helper: true,
error: this.error,
disabled: this.disabled,
} }, this.error && h("tds-icon", { key: 'ec946e77add75e7eaf194e2b38e5dd1c548ab32f', name: "error", size: "16px" }), this.helper))));
}
static get is() { return "tds-dropdown"; }
static get encapsulation() { return "shadow"; }
static get originalStyleUrls() {
return {
"$": ["dropdown.scss"]
};
}
static get styleUrls() {
return {
"$": ["dropdown.css"]
};
}
static get properties() {
return {
"name": {
"type": "string",
"mutable": false,
"complexType": {
"original": "string",
"resolved": "string",
"references": {}
},
"required": false,
"optional": false,
"docs": {
"tags": [],
"text": "Name for the Dropdowns input element."
},
"attribute": "name",
"reflect": false
},
"disabled": {
"type": "boolean",
"mutable": false,
"complexType": {
"original": "boolean",
"resolved": "boolean",
"references": {}
},
"required": false,
"optional": false,
"docs": {
"tags": [],
"text": "Sets the Dropdown in a disabled state"
},
"attribute": "disabled",
"reflect": false,
"defaultValue": "false"
},
"helper": {
"type": "string",
"mutable": false,
"complexType": {
"original": "string",
"resolved": "string",
"references": {}
},
"required": false,
"optional": false,
"docs": {
"tags": [],
"text": "Helper text for the Dropdown."
},
"attribute": "helper",
"reflect": false
},
"label": {
"type": "string",
"mutable": false,
"complexType": {
"original": "string",
"resolved": "string",
"references": {}
},
"required": false,
"optional": false,
"docs": {
"tags": [],
"text": "Label text for the Dropdown."
},
"attribute": "label",
"reflect": false
},
"labelPosition": {
"type": "string",
"mutable": false,
"complexType": {
"original": "'inside' | 'outside'",
"resolved": "\"inside\" | \"outside\"",
"references": {}
},
"required": false,
"optional": false,
"docs": {
"tags": [],
"text": "Label text position"
},
"attribute": "label-position",
"reflect": false
},
"modeVariant": {
"type": "string",
"mutable": false,
"complexType": {
"original": "'primary' | 'secondary'",
"resolved": "\"primary\" | \"secondary\"",
"references": {}
},
"required": false,
"optional": false,
"docs": {
"tags": [],
"text": "Mode variant of the component, based on current mode."
},
"attribute": "mode-variant",
"reflect": false,
"defaultValue": "null"
},
"openDirection": {
"type": "string",
"mutable": false,
"complexType": {
"original": "'up' | 'down' | 'auto'",
"resolved": "\"auto\" | \"down\" | \"up\"",
"references": {}
},
"required": false,
"optional": false,
"docs": {
"tags": [],
"text": "The direction the Dropdown should open, auto if not specified."
},
"attribute": "open-direction",
"reflect": false,
"defaultValue": "'auto'"
},
"placeholder": {
"type": "string",
"mutable": false,
"complexType": {
"original": "string",
"resolved": "string",
"references": {}
},
"required": false,
"optional": false,
"docs": {
"tags": [],
"text": "Placeholder text for the Dropdown."
},
"attribute": "placeholder",
"reflect": false
},
"size": {
"type": "string",
"mutable": false,
"complexType": {
"original": "'xs' | 'sm' | 'md' | 'lg'",
"resolved": "\"lg\" | \"md\" | \"sm\" | \"xs\"",
"references": {}
},
"required": false,
"optional": false,
"docs": {
"tags": [],
"text": "The size of the Dropdown."
},
"attribute": "size",
"reflect": false,
"defaultValue": "'lg'"
},
"animation": {
"type": "string",
"mutable": false,
"complexType": {
"original": "'none' | 'slide'",
"resolved": "\"none\" | \"slide\"",
"references": {}
},
"required": false,
"optional": false,
"docs": {
"tags": [],
"text": ""
},
"attribute": "animation",
"reflect": false,
"defaultValue": "'slide'"
},
"error": {
"type": "boolean",
"mutable": false,
"complexType": {
"original": "boolean",
"resolved": "boolean",
"references": {}
},
"required": false,
"optional": false,
"docs": {
"tags": [],
"text": "Sets the Dropdown in an error state"
},
"attribute": "error",
"reflect": false,
"defaultValue": "false"
},
"multiselect": {
"type": "boolean",
"mutable": false,
"complexType": {
"original": "boolean",
"resolved": "boolean",
"references": {}
},
"required": false,
"optional": false,
"docs": {
"tags": [],
"text": "Enables multiselect in the Dropdown."
},
"attribute": "multiselect",
"reflect": false,
"defaultValue": "false"
},
"filter": {
"type": "boolean",
"mutable": false,
"complexType": {
"original": "boolean",
"resolved": "boolean",
"references": {}
},
"required": false,
"optional": false,
"docs": {
"tags": [],
"text": "Enables filtration in the Dropdown."
},
"attribute": "filter",
"reflect": false,
"defaultValue": "false"
},
"normalizeText": {
"type": "boolean",
"mutable": false,
"complexType": {
"original": "boolean",
"resolved": "boolean",
"references": {}
},
"required": false,
"optional": false,
"docs": {
"tags": [],
"text": "Normalizes input text for fuzzier search"
},
"attribute": "normalize-text",
"reflect": false,
"defaultValue": "true"
},
"noResultText": {
"type": "string",
"mutable": false,
"complexType": {
"original": "string",
"resolved": "string",
"references": {}
},
"required": false,
"optional": true,
"docs": {
"tags": [],
"text": "Text that is displayed if filter is used and there are no options that matches the search.\nSetting it to an empty string disables message from showing up."
},
"attribute": "no-result-text",
"reflect": false,
"defaultValue": "'No result'"
},
"defaultValue": {
"type": "any",
"mutable": false,
"complexType": {
"original": "string | number",
"resolved": "number | string",
"references": {}
},
"required": false,
"optional": false,
"docs": {
"tags": [],
"text": "Default value selected in the Dropdown."
},
"attribute": "default-value",
"reflect": false
},
"value": {
"type": "any",
"mutable": true,
"complexType": {
"original": "string | number | (string | number)[]",
"resolved": "(string | number)[] | number | string",
"references": {}
},
"required": false,
"optional": false,
"docs": {
"tags": [],
"text": "Value of the dropdown. For multiselect, provide array of strings/numbers. For single select, provide a string/number."
},
"attribute": "value",
"reflect": false,
"defaultValue": "null"
},
"tdsAriaLabel": {
"type": "string",
"mutable": false,
"complexType": {
"original": "string",
"resolved": "string",
"references": {}
},
"required": false,
"optional": false,
"docs": {
"tags": [],
"text": "Defines aria-label attribute for input"
},
"attribute": "tds-aria-label",
"reflect": false
}
};
}
static get states() {
return {
"open": {},
"internalValue": {},
"filterResult": {},
"filterFocus": {},
"internalDefaultValue": {},
"selectedOptions": {}
};
}
static get events() {
return [{
"method": "tdsChange",
"name": "tdsChange",
"bubbles": true,
"cancelable": false,
"composed": true,
"docs": {
"tags": [],
"text": "Change event for the Dropdown."
},
"complexType": {
"original": "{\n name: string;\n value: string;\n }",
"resolved": "{ name: string; value: string; }",
"references": {}
}
}, {
"method": "tdsFocus",
"name": "tdsFocus",
"bubbles": true,
"cancelable": false,
"composed": true,
"docs": {
"tags": [],
"text": "Focus event for the Dropdown."
},
"complexType": {
"original": "FocusEvent",
"resolved": "FocusEvent",
"references": {
"FocusEvent": {
"location": "global",
"id": "global::FocusEvent"
}
}
}
}, {
"method": "tdsBlur",
"name": "tdsBlur",
"bubbles": true,
"cancelable": false,
"composed": true,
"docs": {
"tags": [],
"text": "Blur event for the Dropdown."
},
"complexType": {
"original": "FocusEvent",
"resolved": "FocusEvent",
"references": {
"FocusEvent": {
"location": "global",
"id": "global::FocusEvent"
}
}
}
}, {
"method": "tdsInput",
"name": "tdsInput",
"bubbles": true,
"cancelable": false,
"composed": true,
"docs": {
"tags": [],
"text": "Input event for the Dropdown."
},
"complexType": {
"original": "InputEvent",
"resolved": "InputEvent",
"references": {
"InputEvent": {
"location": "global",
"id": "global::InputEvent"
}
}
}
}];
}
static get methods() {
return {
"setValue": {
"complexType": {
"signature": "(value: string | number | string[] | number[], label?: string) => Promise<{ value: string | number; label: string; }[]>",
"parameters": [{
"name": "value",
"type": "string | number | string[] | number[]",
"docs": ""
}, {
"name": "label",
"type": "string",
"docs": ""
}],
"references": {
"Promise": {
"location": "global",
"id": "global::Promise"
},
"HTMLTdsDropdownOptionElement": {
"location": "global",
"id": "global::HTMLTdsDropdownOptionElement"
}
},
"return": "Promise<{ value: string | number; label: string; }[]>"
},
"docs": {
"text": "Method for setting the selected value of the Dropdown.\n\nSingle selection example:\n\n<code>\ndropdown.setValue('option-1', 'Option 1');\n</code>\n\nMultiselect example:\n\n<code>\ndropdown.setValue(['option-1', 'option-2']);\n</code>",
"tags": []
}
},
"reset": {
"complexType": {
"signature": "() => Promise<void>",
"parameters": [],
"references": {
"Promise": {
"location": "global",
"id": "global::Promise"
}
},
"return": "Promise<void>"
},
"docs": {
"text": "",
"tags": []
}
},
"removeValue": {
"complexType": {
"signature": "(oldValue: string) => Promise<void>",
"parameters": [{
"name": "oldValue",
"type": "string",
"docs": ""
}],
"references": {
"Promise": {
"location": "global",
"id": "global::Promise"
}
},
"return": "Promise<void>"
},
"docs": {
"text": "",
"tags": []
}
},
"focusElement": {
"complexType": {
"signature": "() => Promise<void>",
"parameters": [],
"references": {
"Promise": {
"location": "global",
"id": "global::Promise"
}
},
"return": "Promise<void>"
},
"docs": {
"text": "Method that forces focus on the input element.",
"tags": []
}
},
"close": {
"complexType": {
"signature": "() => Promise<void>",
"parameters": [],
"references": {
"Promise": {
"location": "global",
"id": "global::Promise"
}
},
"return": "Promise<void>"
},
"docs": {
"text": "Method for closing the Dropdown.",
"tags": []
}
},
"updateDisplay": {
"complexType": {
"signature": "() => Promise<void>",
"parameters": [],
"references": {
"Promise": {
"location": "global",
"id": "global::Promise"
}
},
"return": "Promise<void>"
},
"docs": {
"text": "Method to force update the dropdown display value.\nUse this method when you programmatically change the text content of dropdown options\nto ensure the selected value display updates immediately.",
"tags": []
}
},
"appendValue": {
"complexType": {
"signature": "(value: string) => Promise<void>",
"parameters": [{
"name": "value",
"type": "string",
"docs": ""
}],
"references": {
"Promise": {
"location": "global",
"id": "global::Promise"
}
},
"return": "Promise<void>"
},
"docs": {
"text": "",
"tags": [{
"name": "internal",
"text": undefined
}]
}
}
};
}
static get elementRef() { return "host"; }
static get watchers() {
return [{
"propName": "value",
"methodName": "handleValueChange"
}, {
"propName": "open",
"methodName": "handleOpenState"
}, {
"propName": "defaultValue",
"methodName": "handleDefaultValueChange"
}];
}
static get listeners() {
return [{
"name": "mousedown",
"method": "onAnyClick",
"target": "window",
"capture": false,
"passive": true
}, {
"name": "keydown",
"method": "onKeyDown",
"target": undefined,
"capture": false,
"passive": false
}];
}
}