Skip to main content

Dropdown class

📖 Description

The Dropdown class defines a dropdown control for the Tripetto builder. It is derived from the DataControl class.

📺 Preview


🆕 constructor

Creates a new Dropdown instance.

Signature

constructor(
options:
(IOption | IOptionGroup)[] |
((done: (options: IOption | IOptionGroup[]) => void) => void),
value: any | Binding,
style?: IDropdownStyle
): Dropdown

Parameters

NameTypeOptionalDescription
options(IOption | IOptionGroup)[] | ((done: (options: IOption | IOptionGroup[]) => void) => void)NoSpecifies the option array or a function in case you want to load the options asynchronously.
valueany | BindingNoSpecifies the initially selected value or a data binding created with bind.
styleIDropdownStyleYesSpecifies the style (when omitted the default global style will be used).

Return value

Returns a reference to the new Dropdown instance.

📌 Statics


🏷️ style

Contains the global default style for the dropdown control.

Type

IDropdownStyle


🔧 bind

Binds an object property to the control allowing its value to update automatically when the value of the control changes. If the control is disabled or invisible, the supplied valueWhenInactive is automatically set as the property value. When a control is enabled and visible, the supplied defaultWhenActive is set automatically if the property value is currently not defined.

Signature

bind<Target, P extends keyof Target>(
target: Target,
property: P,
valueWhenInactive: any,
defaultWhenActive?: any,
modifier?: (value?: any) => any
): Binding;

Parameters

NameTypeOptionalDescription
targetTargetNoReference to the target object which contains the property.
propertyPNoSpecifies the name of the property.
valueWhenInactiveanyNoSpecifies the value which is set to the property when the control is inactive (disabled or invisible).
defaultWhenActiveanyYesSpecifies the default (initial) value that will be used when the control is active (enabled and visible).
modifier(value?: any) => anyYesSpecifies a modifier function for the data.

Return value

Returns a Binding instance that can be used in the controls constructor to bind a value to a control.

Example

import { Forms } from "@tripetto/builder";

const example = {
selected: "a"
};

const dropdown = new Forms.Dropdown(
[
{
label: "Option A",
value: "a"
},
{
label: "Option B",
value: "b"
}
],
Forms.dropdown.bind(example, "selected", "a"));

🗃️ Fields


🏷️ hasFocus

Retrieves if the control has input focus.

Type

boolean


🏷️ isDisabled

Sets or retrieves if the control is disabled.

Type

boolean


🏷️ isLocked

Sets or retrieves if the control is locked (readonly).

Type

boolean


🏷️ isObservable

Retrieves if the control is observable.

Type

boolean


🏷️ isRequired

Sets or retrieves if the control is required.

Type

boolean


🏷️ isVisible

Sets or retrieves the visibility of the control.

Type

boolean


🏷️ style

Contains the dropdown control style.

Type

IDropdownStyle


🏷️ value

Sets or retrieves the selected value.

Type

any

▶️ Methods


🔧 blur

Blurs the focus of the control.

Signature

blur(): void

🔧 disable

Disables the control.

Signature

disable(): this

Return value

Returns a reference to the Dropdown instance to allow chaining.


🔧 disabled

Specifies the state of the control.

Signature

disabled(disabled?: boolean): this

Parameters

NameTypeOptionalDescription
disabledbooleanYesSpecifies if the control is disabled (default is true).

Return value

Returns a reference to the Dropdown instance to allow chaining.


🔧 enable

Enables the control.

Signature

enable(): this

Return value

Returns a reference to the Dropdown instance to allow chaining.


🔧 focus

Sets the focus to the control.

Signature

focus(): boolean

Return value

Returns true if the focus is set.


🔧 hide

Hides the control.

Signature

hide(): this

Return value

Returns a reference to the Dropdown instance to allow chaining.


🔧 indent

Enables control indentation. This can only be set during construction.

Signature

indent(size: number): this

Parameters

NameTypeOptionalDescription
sizenumberNoSpecifies the indent size in pixels.

Return value

Returns a reference to the Dropdown instance to allow chaining.


🔧 label

Sets the label for the control.

tip

If you want to use markdown in the label, activate it first using the markdown method.

Signature

label(label: string): this

Parameters

NameTypeOptionalDescription
labelstringNoSpecifies the control label.

Return value

Returns a reference to the Dropdown instance to allow chaining.


🔧 lock

Locks the control.

Signature

lock(): this

Return value

Returns a reference to the Dropdown instance to allow chaining.


🔧 locked

Specifies if the control is locked (readonly).

Signature

locked(locked?: boolean): this

Parameters

NameTypeOptionalDescription
lockedbooleanYesSpecifies if the control is locked/readonly (default is true).

Return value

Returns a reference to the Dropdown instance to allow chaining.


🔧 markdown

Specifies if the label should support markdown formatting.

Signature

markdown(options?: IMarkdownOptions): this

Parameters

NameTypeOptionalDescription
optionsIMarkdownOptionsYesSpecifies the markdown options.

Return value

Returns a reference to the Dropdown instance to allow chaining.


🔧 on

Specifies the function which is invoked when the dropdown selection is changed.

Signature

on(fn: (dropdown: Dropdown) => void): this

Parameters

NameTypeOptionalDescription
fn(dropdown: Dropdown) => voidNoSpecifies the change function.

Return value

Returns a reference to the Dropdown instance to allow chaining.


🔧 optionDisabled

Sets or retrieves the disabled state of the specified option or the current option if no option value is specified.

Signature

optionDisabled(value?: any, disabled?: boolean): boolean

Parameters

NameTypeOptionalDescription
valueanyYesSpecifies the option value.
disabledbooleanYesSpecifies the disabled state.

Return value

Returns the disabled state.


🔧 optionLabel

Sets or retrieves the label of the specified option or the current option if no option value is specified.

Signature

optionLabel(value?: any, label?: string): string

Parameters

NameTypeOptionalDescription
valueanyYesSpecifies the option value.
labelstringYesSpecifies a new label for the option.

Return value

Returns the label.


🔧 options

Sets the options for the dropdown.

Signature

options(options: (IOption | IOptionGroup)[]): this

Parameters

NameTypeOptionalDescription
options(IOption | IOptionGroup)[]NoSpecifies an array of options.

Return value

Returns a reference to the Dropdown instance to allow chaining.


🔧 placeholder

Sets a placeholder for the control.

Signature

placeholder(placeholder: string): this

Parameters

NameTypeOptionalDescription
placeholderstringNoSpecifies the placeholder string.

Return value

Returns a reference to the Dropdown instance to allow chaining.


🔧 readonly

Makes the control readonly.

Signature

readonly(): this

Return value

Returns a reference to the Dropdown instance to allow chaining.


🔧 require

Makes the control required.

Signature

require(): this

Return value

Returns a reference to the Dropdown instance to allow chaining.


🔧 required

Specifies if the control is required.

Signature

required(required?: boolean): this

Parameters

NameTypeOptionalDescription
requiredbooleanYesSpecifies if the control is required (default is true).

Return value

Returns a reference to the Dropdown instance to allow chaining.


🔧 select

Selects the specified option.

Signature

select(value: any): this

Parameters

NameTypeOptionalDescription
valueanyNoSpecifies the option value.

Return value

Returns a reference to the Dropdown instance to allow chaining.


🔧 show

Shows the control.

Signature

show(): this

Return value

Returns a reference to the Dropdown instance to allow chaining.


🔧 unlock

Unlocks the control.

Signature

unlock(): this

Return value

Returns a reference to the Dropdown instance to allow chaining.


🔧 visible

Specifies the visibility of the control.

Signature

visible(visible?: boolean): this

Parameters

NameTypeOptionalDescription
visiblebooleanYesSpecifies if the control is visible (default is true).

Return value

Returns a reference to the Dropdown instance to allow chaining.


🔧 width

Sets the width of the control.

Signature

width(width: number | "auto" | "full"): this

Parameters

NameTypeOptionalDescription
widthnumber | "auto" | "full"NoSpecifies the control width in pixels or sets the width to auto or full.

Return value

Returns a reference to the Dropdown instance to allow chaining.

⛓️ Interfaces


🔗 IDropdownStyle

Describes the interface for the dropdown styles.

Type declaration

interface IDropdownStyle {
/* Dropdown appearance. */
appearance?: IStyles;

/* Options. */
options?: IStyles;

/* Option groups. */
optGroups?: IStyles;

/* Placeholder option. */
placeholder?: IStyles;

/* Dropdown label. */
label?: IStyles;

/* Dropdown disabled. */
disabled?: IStyles;

/* Dropdown required. */
required?: IStyles;

/* Dropdown locked. */
locked?: IStyles;

/* Dropdown focus. */
focus?: IStyles;

/* Dropdown hover. */
hover?: IStyles;

/* Validation passed. */
passed?: IStyles;

/* Validation failed. */
failed?: IStyles;

/* Validation awaiting. */
awaiting?: IStyles;

/* Dropdown when fused with form card. */
fused?: {
/* Dropdown appearance. */
appearance?: IStyles;

/* Dropdown label. */
label?: IStyles;

/* Dropdown required. */
required?: IStyles;

/* Dropdown locked. */
locked?: IStyles;

/* Dropdown focus. */
focus?: IStyles;

/* Dropdown hover. */
hover?: IStyles;

/* Validation passed. */
passed?: IStyles;

/* Validation failed. */
failed?: IStyles;

/* Validation awaiting. */
awaiting?: IStyles;
};
}

🔗 IOption

Describes the interface for a dropdown option.

Type declaration

interface IOption {
/* Label for the option. */
label: string;

/* Value for the option. */
value: any;

/* Specifies if the option is disabled. */
disabled?: boolean;

/* Specifies an indentation level for an option. */
indent?: number;
}

🔗 IOptionGroup

Describes the interface for a dropdown option group.

Type declaration

interface IOptionGroup {
/* Label for the option group. */
optGroup: string;
}