class sap.m.Label

Control sample: sap.m.Label
Visiblity: public
UX Guidelines: Label
Implements: sap.ui.core.Labelsap.ui.core.IShrinkablesap.m.IOverflowToolbarContentsap.m.IHyphenation
Available since: N/A
Module: sap/m/Label
Application Component: CA-UI5-CTR

Provides a textual label for other controls.

Overview

Labels are used as titles for single controls or groups of controls. Labels for required fields are marked with an asterisk.

Label appearance can be influenced by properties, such as textAlign, design, displayOnly, wrapping and wrappingType.

As of version 1.50, the default value of the wrapping property is set to false.

As of version 1.60, you can hyphenate the label's text with the use of the wrappingType property. For more information, see Text Controls Hyphenation.

Usage

When to use

When not to use


Constructor

Constructor for a new Label.

Accepts an object literal mSettings that defines initial property values, aggregated and associated objects as well as event handlers. See sap.ui.base.ManagedObject#constructor for a general description of the syntax of the settings object.

new sap.m.Label(sId?, mSettings?)
Param Type Default Value Description
sId? string

ID for the new control, generated automatically if no ID is given

mSettings? object

Initial settings for the new control


Properties

Name Type Default Value Description
design sap.m.LabelDesign Standard

Sets the design of a Label to either Standard or Bold.

Visibility: public
displayOnly boolean false

Determines if the label is in displayOnly mode.

Note: This property should be used only in Form controls in preview mode.

Since: 1.50.0.

Visibility: public
required boolean false

Indicates that user input is required for input control labeled by the sap.m.Label. When the property is set to true and associated input field is empty an asterisk character is added to the label text.

Visibility: public
text string

Determines the Label text to be displayed.

Visibility: public
textAlign sap.ui.core.TextAlign Begin

Available alignment settings are "Begin", "Center", "End", "Left", and "Right".

Visibility: public
textDirection sap.ui.core.TextDirection Inherit

Options for the text direction are RTL and LTR. Alternatively, the control can inherit the text direction from its parent container.

Visibility: public
vAlign sap.ui.core.VerticalAlign Inherit

Specifies the vertical alignment of the Label related to the tallest and lowest element on the line.

Since: 1.54.

Visibility: public
width sap.ui.core.CSSSize empty string

Determines the width of the label.

Visibility: public
wrapping boolean false

Determines the wrapping of the text within the Label. If set to true the Label will wrap, when set to false the Label will be truncated and replaced with ellipsis which is the default behavior.

Since: 1.50.

Visibility: public
wrappingType sap.m.WrappingType Normal

Defines the type of text wrapping to be used (hyphenated or normal).

Note: This property takes effect only when the wrapping property is set to true.

Since: 1.60.

Visibility: public

Associations

Name Cardinality Type Description
labelFor 0..1 sap.ui.core.Control

Association to the labeled control. By default the label set the for attribute to the ID of the labeled control. This can be changed by implementing the function getIdForLabel on the labelled control.


Methods Overview

Method Description
sap.m.Label.extend

Creates a new subclass of class sap.m.Label with name sClassName and enriches it with the information contained in oClassInfo.

oClassInfo might contain the same kind of information as described in sap.ui.core.Control.extend.

getAccessibilityInfo

Provides the current accessibility state of the control.

References:

getDesign

Gets current value of property design.

Sets the design of a Label to either Standard or Bold.

Default value is Standard.

getDisplayOnly

Gets current value of property displayOnly.

Determines if the label is in displayOnly mode.

Note: This property should be used only in Form controls in preview mode.

Default value is false.

getLabelFor

ID of the element which is the current target of the association labelFor, or null.

sap.m.Label.getMetadata

Returns a metadata object for class sap.m.Label.

getOverflowToolbarConfig

Enables the sap.m.Label to move inside the sap.m.OverflowToolbar. Required by the sap.m.IOverflowToolbarContent interface.

getRequired

Gets current value of property required.

Indicates that user input is required for input control labeled by the sap.m.Label. When the property is set to true and associated input field is empty an asterisk character is added to the label text.

Default value is false.

getText

Gets current value of property text.

Determines the Label text to be displayed.

getTextAlign

Gets current value of property textAlign.

Available alignment settings are "Begin", "Center", "End", "Left", and "Right".

Default value is Begin.

getTextDirection

Gets current value of property textDirection.

Options for the text direction are RTL and LTR. Alternatively, the control can inherit the text direction from its parent container.

Default value is Inherit.

getVAlign

Gets current value of property vAlign.

Specifies the vertical alignment of the Label related to the tallest and lowest element on the line.

Default value is Inherit.

getWidth

Gets current value of property width.

Determines the width of the label.

Default value is empty string.

getWrapping

Gets current value of property wrapping.

Determines the wrapping of the text within the Label. If set to true the Label will wrap, when set to false the Label will be truncated and replaced with ellipsis which is the default behavior.

Default value is false.

getWrappingType

Gets current value of property wrappingType.

Defines the type of text wrapping to be used (hyphenated or normal).

Note: This property takes effect only when the wrapping property is set to true.

Default value is Normal.

setDesign

Sets a new value for property design.

Sets the design of a Label to either Standard or Bold.

When called with a value of null or undefined, the default value of the property will be restored.

Default value is Standard.

setDisplayOnly

Sets a new value for property displayOnly.

Determines if the label is in displayOnly mode.

Note: This property should be used only in Form controls in preview mode.

When called with a value of null or undefined, the default value of the property will be restored.

Default value is false.

setLabelFor

Sets the associated labelFor.

setRequired

Sets a new value for property required.

Indicates that user input is required for input control labeled by the sap.m.Label. When the property is set to true and associated input field is empty an asterisk character is added to the label text.

When called with a value of null or undefined, the default value of the property will be restored.

Default value is false.

setText

Sets a new value for property text.

Determines the Label text to be displayed.

When called with a value of null or undefined, the default value of the property will be restored.

setTextAlign

Sets a new value for property textAlign.

Available alignment settings are "Begin", "Center", "End", "Left", and "Right".

When called with a value of null or undefined, the default value of the property will be restored.

Default value is Begin.

setTextDirection

Sets a new value for property textDirection.

Options for the text direction are RTL and LTR. Alternatively, the control can inherit the text direction from its parent container.

When called with a value of null or undefined, the default value of the property will be restored.

Default value is Inherit.

setVAlign

Sets a new value for property vAlign.

Specifies the vertical alignment of the Label related to the tallest and lowest element on the line.

When called with a value of null or undefined, the default value of the property will be restored.

Default value is Inherit.

setWidth

Sets a new value for property width.

Determines the width of the label.

When called with a value of null or undefined, the default value of the property will be restored.

Default value is empty string.

setWrapping

Sets a new value for property wrapping.

Determines the wrapping of the text within the Label. If set to true the Label will wrap, when set to false the Label will be truncated and replaced with ellipsis which is the default behavior.

When called with a value of null or undefined, the default value of the property will be restored.

Default value is false.

setWrappingType

Sets a new value for property wrappingType.

Defines the type of text wrapping to be used (hyphenated or normal).

Note: This property takes effect only when the wrapping property is set to true.

When called with a value of null or undefined, the default value of the property will be restored.

Default value is Normal.

sap.m.Label.extend

Creates a new subclass of class sap.m.Label with name sClassName and enriches it with the information contained in oClassInfo.

oClassInfo might contain the same kind of information as described in sap.ui.core.Control.extend.

Param Type DefaultValue Description
sClassName string

Name of the class being created

oClassInfo object

Object literal with information about the class

FNMetaImpl function

Constructor function for the metadata object; if not given, it defaults to the metadata implementation used by this class

getAccessibilityInfo

Provides the current accessibility state of the control.

References:

getDesign

Gets current value of property design.

Sets the design of a Label to either Standard or Bold.

Default value is Standard.

getDisplayOnly

Gets current value of property displayOnly.

Determines if the label is in displayOnly mode.

Note: This property should be used only in Form controls in preview mode.

Default value is false.

getLabelFor

ID of the element which is the current target of the association labelFor, or null.

sap.m.Label.getMetadata

Returns a metadata object for class sap.m.Label.

getOverflowToolbarConfig

Enables the sap.m.Label to move inside the sap.m.OverflowToolbar. Required by the sap.m.IOverflowToolbarContent interface.

getRequired

Gets current value of property required.

Indicates that user input is required for input control labeled by the sap.m.Label. When the property is set to true and associated input field is empty an asterisk character is added to the label text.

Default value is false.

getText

Gets current value of property text.

Determines the Label text to be displayed.

getTextAlign

Gets current value of property textAlign.

Available alignment settings are "Begin", "Center", "End", "Left", and "Right".

Default value is Begin.

getTextDirection

Gets current value of property textDirection.

Options for the text direction are RTL and LTR. Alternatively, the control can inherit the text direction from its parent container.

Default value is Inherit.

getVAlign

Gets current value of property vAlign.

Specifies the vertical alignment of the Label related to the tallest and lowest element on the line.

Default value is Inherit.

getWidth

Gets current value of property width.

Determines the width of the label.

Default value is empty string.

getWrapping

Gets current value of property wrapping.

Determines the wrapping of the text within the Label. If set to true the Label will wrap, when set to false the Label will be truncated and replaced with ellipsis which is the default behavior.

Default value is false.

getWrappingType

Gets current value of property wrappingType.

Defines the type of text wrapping to be used (hyphenated or normal).

Note: This property takes effect only when the wrapping property is set to true.

Default value is Normal.

setDesign

Sets a new value for property design.

Sets the design of a Label to either Standard or Bold.

When called with a value of null or undefined, the default value of the property will be restored.

Default value is Standard.

Param Type DefaultValue Description
sDesign sap.m.LabelDesign Standard

New value for property design

setDisplayOnly

Sets a new value for property displayOnly.

Determines if the label is in displayOnly mode.

Note: This property should be used only in Form controls in preview mode.

When called with a value of null or undefined, the default value of the property will be restored.

Default value is false.

Param Type DefaultValue Description
bDisplayOnly boolean false

New value for property displayOnly

setLabelFor

Sets the associated labelFor.

Param Type DefaultValue Description
oLabelFor sap.ui.core.ID sap.ui.core.Control

ID of an element which becomes the new target of this labelFor association; alternatively, an element instance may be given

setRequired

Sets a new value for property required.

Indicates that user input is required for input control labeled by the sap.m.Label. When the property is set to true and associated input field is empty an asterisk character is added to the label text.

When called with a value of null or undefined, the default value of the property will be restored.

Default value is false.

Param Type DefaultValue Description
bRequired boolean false

New value for property required

setText

Sets a new value for property text.

Determines the Label text to be displayed.

When called with a value of null or undefined, the default value of the property will be restored.

Param Type DefaultValue Description
sText string

New value for property text

setTextAlign

Sets a new value for property textAlign.

Available alignment settings are "Begin", "Center", "End", "Left", and "Right".

When called with a value of null or undefined, the default value of the property will be restored.

Default value is Begin.

Param Type DefaultValue Description
sTextAlign sap.ui.core.TextAlign Begin

New value for property textAlign

setTextDirection

Sets a new value for property textDirection.

Options for the text direction are RTL and LTR. Alternatively, the control can inherit the text direction from its parent container.

When called with a value of null or undefined, the default value of the property will be restored.

Default value is Inherit.

Param Type DefaultValue Description
sTextDirection sap.ui.core.TextDirection Inherit

New value for property textDirection

setVAlign

Sets a new value for property vAlign.

Specifies the vertical alignment of the Label related to the tallest and lowest element on the line.

When called with a value of null or undefined, the default value of the property will be restored.

Default value is Inherit.

Param Type DefaultValue Description
sVAlign sap.ui.core.VerticalAlign Inherit

New value for property vAlign

setWidth

Sets a new value for property width.

Determines the width of the label.

When called with a value of null or undefined, the default value of the property will be restored.

Default value is empty string.

Param Type DefaultValue Description
sWidth sap.ui.core.CSSSize ''

New value for property width

setWrapping

Sets a new value for property wrapping.

Determines the wrapping of the text within the Label. If set to true the Label will wrap, when set to false the Label will be truncated and replaced with ellipsis which is the default behavior.

When called with a value of null or undefined, the default value of the property will be restored.

Default value is false.

Param Type DefaultValue Description
bWrapping boolean false

New value for property wrapping

setWrappingType

Sets a new value for property wrappingType.

Defines the type of text wrapping to be used (hyphenated or normal).

Note: This property takes effect only when the wrapping property is set to true.

When called with a value of null or undefined, the default value of the property will be restored.

Default value is Normal.

Param Type DefaultValue Description
sWrappingType sap.m.WrappingType Normal

New value for property wrappingType