Class sap.m.TextModule: sap/m/Text

extends Control

The Text control can be used for embedding longer text paragraphs, that need text wrapping, into your app. If the configured text value contains HTML code or script tags, those will be escaped.
Note: Line breaks (\r\n, \n\r, \r, \n) will always be visualized except when the wrapping property is set to false.
Constructor Summary
new sap.m.Text(sId?, mSettings?)Constructor for a new Text.
Field Summary
cacheLineHeightDetermines per instance whether line height should be cached or not.
ellipsisEllipsis(…) text to indicate more text when clampText function is used.
normalLineHeightDefault line height value as a number when line-height is normal.
Events borrowed from class sap.ui.core.Control
Method Summary
sap.m.Text.extend(sClassName, oClassInfo?, FNMetaImpl?)Creates a new subclass of class sap.m.Text with name sClassName and enriches it with the information contained in oClassInfo.
sap.m.Text.getMetadata()Returns a metadata object for class sap.m.Text.
sap.m.Text.setNodeValue(oDomRef, sNodeValue?)To prevent from the layout thrashing of the textContent call, this method first tries to set the nodeValue of the first child if it exists.
bindText(oBindingInfo)Binds property text to model data.
clampHeight(oDomRef?)Sets the max-height to support maxLines property.
clampText(oDomRef?, iStartPos?, iEndPos?)Clamps the wrapping text according to max lines and returns the found ellipsis position.
getClampHeight(oDomRef?)Returns the max height according to max lines and line height calculation.
getLineHeight(oDomRef?)Caches and returns the computed line height of the text.
getMaxLines()Gets current value of property maxLines.
getText()Gets current value of property text.
getTextAlign()Gets current value of property textAlign.
getTextDirection()Gets current value of property textDirection.
getTextDomRef()Returns the text node container's DOM reference.
getWidth()Gets current value of property width.
getWrapping()Gets current value of property wrapping.
hasMaxLines()Determines whether max lines should be rendered or not.
setMaxLines(iMaxLines)Sets a new value for property maxLines.
setText(sText)Sets a new value for property text.
setTextAlign(sTextAlign)Sets a new value for property textAlign.
setTextDirection(sTextDirection)Sets a new value for property textDirection.
setWidth(sWidth)Sets a new value for property width.
setWrapping(bWrapping)Sets a new value for property wrapping.
unbindText()Unbinds property text from model data.
Constructor Detail
new sap.m.Text(sId?, mSettings?)

Constructor for a new Text.

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

The supported settings are:

In addition, all settings applicable to the base type sap.ui.core.Control can be used as well.

Parameters:
stringsId?ID for the new control, generated automatically if no ID is given
objectmSettings?Initial settings for the new control
Field Detail
cacheLineHeight : boolean

Determines per instance whether line height should be cached or not.

Default value is true.

Since:
1.22
ellipsis : string

Ellipsis(…) text to indicate more text when clampText function is used.

Can be overwritten with 3dots(...) if fonts do not support this UTF-8 character.

Since:
1.13.2
normalLineHeight : number

Default line height value as a number when line-height is normal.

This value is required during max-height calculation for the browsers that do not support line-clamping. It is better to define line-height in CSS instead of "normal" to get consistent maxLines results since normal line-height not only varies from browser to browser but they also vary from one font face to another and can also vary within a given face.

Default value is 1.2

Since:
1.22
Method Detail
sap.m.Text.extend(sClassName, oClassInfo?, FNMetaImpl?): function

Creates a new subclass of class sap.m.Text 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.

Parameters:
stringsClassNameName of the class being created
objectoClassInfo?Object literal with information about the class
functionFNMetaImpl?Constructor function for the metadata object; if not given, it defaults to sap.ui.core.ElementMetadata
Returns:
functionCreated class / constructor function
sap.m.Text.getMetadata(): sap.ui.base.Metadata
Returns a metadata object for class sap.m.Text.
Returns:
sap.ui.base.MetadataMetadata object describing this class
sap.m.Text.setNodeValue(oDomRef, sNodeValue?)
To prevent from the layout thrashing of the textContent call, this method first tries to set the nodeValue of the first child if it exists.
Parameters:
HTMLElementoDomRefDOM reference of the text node container.
StringsNodeValue?new Node value.
Since:
1.30.3
bindText(oBindingInfo): sap.m.Text

Binds property text to model data.

See ManagedObject.bindProperty for a detailed description of the possible properties of oBindingInfo

Parameters:
objectoBindingInfoThe binding information
Returns:
sap.m.TextReference to this in order to allow method chaining
clampHeight(oDomRef?): Number
Sets the max-height to support maxLines property.
Parameters:
HTMLElementoDomRef?DOM reference of the text container.
Returns:
Numbercalculated max height value
Since:
1.22
clampText(oDomRef?, iStartPos?, iEndPos?): number|undefined

Clamps the wrapping text according to max lines and returns the found ellipsis position.

Parameters can be used for better performance.

Parameters:
HTMLElementoDomRef?DOM reference of the text container.
numberiStartPos?Start point of the ellipsis search.
numberiEndPos?End point of the ellipsis search.
Returns:
number|undefinedReturns found ellipsis position or undefined
Since:
1.20
getAccessibilityInfo()
See:
sap.ui.core.Control#getAccessibilityInfo
getClampHeight(oDomRef?): Number

Returns the max height according to max lines and line height calculation.

This is not calculated max-height!

Parameters:
HTMLElementoDomRef?DOM reference of the text container.
Returns:
Number
Since:
1.22
getLineHeight(oDomRef?): Number
Caches and returns the computed line height of the text.
Parameters:
HTMLElementoDomRef?DOM reference of the text container.
Returns:
Numberreturns calculated line-height
Since:
1.22
See:
sap.m.Text#cacheLineHeight
getMaxLines(): int

Gets current value of property maxLines.

Limits the number of lines for wrapping texts.

Note: In multi-line text the overflow will be hidden (ellipsis won't be shown).

Returns:
intValue of property maxLines
Since:
1.13.2
getText(): string

Gets current value of property text.

Determines the text to be displayed.

Default value is .

Returns:
stringValue of property text
getTextAlign(): sap.ui.core.TextAlign

Gets current value of property textAlign.

Sets the horizontal alignment of the text.

Default value is Begin.

Returns:
sap.ui.core.TextAlignValue of property textAlign
getTextDirection(): sap.ui.core.TextDirection

Gets current value of property textDirection.

Available options for the text direction are LTR and RTL. By default the control inherits the text direction from its parent control.

Default value is Inherit.

Returns:
sap.ui.core.TextDirectionValue of property textDirection
getTextDomRef(): HTMLElement|null

Returns the text node container's DOM reference.

This can be different from getDomRef when inner wrapper is needed.

Returns:
HTMLElement|null
Since:
1.22
getWidth(): sap.ui.core.CSSSize

Gets current value of property width.

Sets the width of the Text control. By default, the Text control uses the full width available. Set this property to restrict the width to a custom value.

Returns:
sap.ui.core.CSSSizeValue of property width
getWrapping(): boolean

Gets current value of property wrapping.

Enables text wrapping.

Default value is true.

Returns:
booleanValue of property wrapping
hasMaxLines(): HTMLElement|null
Determines whether max lines should be rendered or not.
Returns:
HTMLElement|null
Since:
1.22
setMaxLines(iMaxLines): sap.m.Text

Sets a new value for property maxLines.

Limits the number of lines for wrapping texts.

Note: In multi-line text the overflow will be hidden (ellipsis won't be shown).

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

Parameters:
intiMaxLinesNew value for property maxLines
Returns:
sap.m.TextReference to this in order to allow method chaining
Since:
1.13.2
setText(sText): sap.m.Text

Sets a new value for property text.

Determines the text to be displayed.

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

Default value is .

Parameters:
stringsTextNew value for property text
Returns:
sap.m.TextReference to this in order to allow method chaining
setTextAlign(sTextAlign): sap.m.Text

Sets a new value for property textAlign.

Sets the horizontal alignment of the text.

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

Default value is Begin.

Parameters:
sap.ui.core.TextAlignsTextAlignNew value for property textAlign
Returns:
sap.m.TextReference to this in order to allow method chaining
setTextDirection(sTextDirection): sap.m.Text

Sets a new value for property textDirection.

Available options for the text direction are LTR and RTL. By default the control inherits the text direction from its parent control.

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

Default value is Inherit.

Parameters:
sap.ui.core.TextDirectionsTextDirectionNew value for property textDirection
Returns:
sap.m.TextReference to this in order to allow method chaining
setWidth(sWidth): sap.m.Text

Sets a new value for property width.

Sets the width of the Text control. By default, the Text control uses the full width available. Set this property to restrict the width to a custom value.

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

Parameters:
sap.ui.core.CSSSizesWidthNew value for property width
Returns:
sap.m.TextReference to this in order to allow method chaining
setWrapping(bWrapping): sap.m.Text

Sets a new value for property wrapping.

Enables text wrapping.

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

Default value is true.

Parameters:
booleanbWrappingNew value for property wrapping
Returns:
sap.m.TextReference to this in order to allow method chaining
unbindText(): sap.m.Text
Unbinds property text from model data.
Returns:
sap.m.TextReference to this in order to allow method chaining