blockly > FieldDropdown

FieldDropdown class

Class for an editable dropdown field.

Signature:

export declare class FieldDropdown extends Field<string> 

Extends: Field<string>

Constructors

Constructor Modifiers Description
(constructor)(menuGenerator, validator, config) Constructs a new instance of the FieldDropdown class
(constructor)(menuGenerator) Constructs a new instance of the FieldDropdown class

Properties

Property Modifiers Type Description
ARROW_CHAR static string
clickTarget_ SVGElement | null
IMAGE_Y_OFFSET

protected

static

number The y offset from the top of the field to the top of the image, if an image is selected.
IMAGE_Y_PADDING

protected

static

number The total vertical padding above and below an image.
menu_ protected Menu | null The dropdown menu.
menuGenerator_? protected MenuGenerator (Optional)
SEPARATOR

static

readonly

(not declared) Magic constant used to represent a separator in a list of dropdown items.
SERIALIZABLE boolean Serializable fields are saved by the serializer, non-serializable fields are not. Editable fields should also be serializable.

Methods

Method Modifiers Description
applyColour() Updates the dropdown arrow to match the colour/style of the block.
createSVGArrow_() protected Create an SVG based arrow.
createTextArrow_() protected Create a tspan based arrow.
doClassValidation_(newValue) protected Ensure that the input value is a valid language-neutral option.
doClassValidation_(newValue) protected
doValueUpdate_(newValue) protected Update the value of this dropdown field.
dropdownDispose_() protected Disposes of events and DOM-references belonging to the dropdown editor.
getOptions(useCache) Return a list of the options for this dropdown.
getText_() protected

Use the getText_ developer hook to override the field's text representation. Get the selected option text. If the selected option is an image we return the image alt text. If the selected option is an HTMLElement, return the title, ariaLabel, or innerText of the element.

If you use HTMLElement options in Node.js and call this function, ensure that you are supplying an implementation of HTMLElement, such as through jsdom-global.

initView() Create the block UI for this dropdown.
isOptionListDynamic()
onItemSelected_(menu, menuItem) protected Handle the selection of an item in the dropdown menu.
render_() protected Draws the border with the correct width.
setOptions(menuGenerator) Update the options on this dropdown. This will reset the selected item to the first item in the list.
shouldAddBorderRect_() protected Whether or not the dropdown should add a border rect.
showEditor_(e) protected Create a dropdown menu under the text.
trimOptions(options) protected Factor out common words in statically defined options. Create prefix and/or suffix labels.
validateOptions(options) protected Validates the data structure to be processed as an options list.