Skip to main content

blockly > FieldImage

FieldImage class

Class for an image on a block.

Signature:

export declare class FieldImage extends Field<string>

Extends: Field<string>

Constructors

Constructor

Modifiers

Description

(constructor)(src, width, height, alt, onClick, flipRtl, config)

Constructs a new instance of the FieldImage class

Properties

Property

Modifiers

Type

Description

EDITABLE

readonly

(not declared)

Editable fields usually show some sort of UI indicating they are editable. This field should not.

imageElement

protected

SVGImageElement | null

The rendered field's image element.

imageHeight

protected

readonly

number

isDirty_

protected

boolean

Used to tell if the field needs to be rendered the next time the block is rendered. Image fields are statically sized, and only need to be rendered at initialization.

Methods

Method

Modifiers

Description

computeAriaLabel(includeTypeInfo)

Computes a descriptive ARIA label to represent this field with configurable verbosity.

A 'verbose' label includes type information, if available, whereas a non-verbose label only contains the field's value.

Note that this will always return the latest representation of the field's label which may differ from any previously set ARIA label for the field itself. Implementations are largely responsible for ensuring that the field's ARIA label is set correctly at relevant moments in the field's lifecycle (such as when its value changes).

Finally, it is never guaranteed that implementations use the label returned by this method for their actual ARIA label. Some implementations may rely on other contexts to convey information like the field's value. Example: checkboxes represent their checked/non-checked status (i.e. value) through a separate ARIA property.

Returns an empty string on clickable images (buttons), as we do not want to include image buttons on the block-level ARIA label. When the button is focused the label is set in recomputeAriaContext below.

configure_(config)

protected

Configure the field based on the given map of options.

doClassValidation_(newValue)

protected

Ensure that the input value (the source URL) is a string.

doValueUpdate_(newValue)

protected

Update the value of this image field, and update the displayed image.

getAriaTypeName()

Gets an ARIA-friendly label representation of this field's type.

Implementations are responsible for, and encouraged to, return a localized version of the ARIA representation of the field's type.

getAriaValue()

Gets an ARIA-friendly label representation of this field's value.

Implementations are responsible for, and encouraged to, return a localized version of the ARIA representation of the field's value.

getFlipRtl()

Get whether to flip this image in RTL

getText_()

protected

Use the getText_ developer hook to override the field's text representation. Return the image alt text instead.

initView()

Create the block UI for this image.

isClickable()

Check whether this field should be clickable.

recomputeAriaContext()

Customizes label and sets additional aria state.

setAlt(alt)

Set the alt text of this image.

setOnClickHandler(func)

Set the function that is called when this image is clicked.

showEditor_()

protected

If field click is called, and click handler defined, call the handler.

updateSize_()