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. In addition, tabs (\t) and whitespace (" ") can be preserved by setting the renderWhitespace property to true
Constructor Summary
new sap.m.Text(sId?, mSettings?)Constructor for a new Text.
Field Summary
sap.m.Text.hasNativeLineClampDefines whether browser supports native line clamp or not and if browser is Chrome
cacheLineHeightDetermines per instance whether line height should be cached or not.
ellipsisEllipsis(.
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.clampHeight(oDomRef?)Sets the max height to support maxLines property.
sap.m.Text.clampText(oDomRef?, iStartPos?, iEndPos?)Clamps the wrapping text according to max lines and returns the found ellipsis position.
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.getAccessibilityInfo()Gets the accessibility information for the text.
sap.m.Text.getClampHeight(oDomRef?)Returns the max height according to max lines and line height calculation.
sap.m.Text.getLineHeight(oDomRef?)Caches and returns the computed line height of the text.
sap.m.Text.getMetadata()Returns a metadata object for class sap.m.Text.
sap.m.Text.getText(bNormalize)Gets the text.
sap.m.Text.getTextDomRef()Returns the text node container's DOM reference.
sap.m.Text.hasMaxLines()Determines whether max lines should be rendered or not.
sap.m.Text.onAfterRendering()Overwrites onAfterRendering
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.
sap.m.Text.setText(sText)Sets the text.
bindText(oBindingInfo)Binds property text to model data.
canUseNativeLineClamp()Decides whether the control can use native line clamp feature or not.
getMaxLines()Gets current value of property maxLines.
getRenderWhitespace()Gets current value of property renderWhitespace.
getText()Gets current value of property text.
getTextAlign()Gets current value of property textAlign.
getTextDirection()Gets current value of property textDirection.
getWidth()Gets current value of property width.
getWrapping()Gets current value of property wrapping.
setMaxLines(iMaxLines)Sets a new value for property maxLines.
setRenderWhitespace(bRenderWhitespace)Sets a new value for property renderWhitespace.
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
sap.m.Text.hasNativeLineClamp
Defines whether browser supports native line clamp or not and if browser is Chrome
Since:
1.13.2
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 : int

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 it also varies from one font face to another and can also vary within a given face.

Since:
1.22
Method Detail
sap.m.Text.clampHeight(oDomRef?): int
Sets the max height to support maxLines property.
Parameters:
HTMLElementoDomRef?DOM reference of the text container.
Returns:
intCalculated max height value.
Since:
1.22
sap.m.Text.clampText(oDomRef?, iStartPos?, iEndPos?): int|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.
intiStartPos?Start point of the ellipsis search.
intiEndPos?End point of the ellipsis search.
Returns:
int|undefinedReturns found ellipsis position or undefined.
Since:
1.20
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.getAccessibilityInfo(): object
Gets the accessibility information for the text.
Returns:
objectAccessibility information for the text.
See:
sap.ui.core.Control#getAccessibilityInfo
sap.m.Text.getClampHeight(oDomRef?): int
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:
intThe clamp height of the text.
Since:
1.22
sap.m.Text.getLineHeight(oDomRef?): int
Caches and returns the computed line height of the text.
Parameters:
HTMLElementoDomRef?DOM reference of the text container.
Returns:
intreturns calculated line height
Since:
1.22
See:
sap.m.Text#cacheLineHeight
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.getText(bNormalize): string
Gets the text.
Parameters:
booleanbNormalizeIndication for normalized text.
Returns:
stringText value.
sap.m.Text.getTextDomRef(): HTMLElement|null
Returns the text node container's DOM reference. This can be different from getDomRef when inner wrapper is needed.
Returns:
HTMLElement|nullDOM reference of the text.
Since:
1.22
sap.m.Text.hasMaxLines(): HTMLElement|null
Determines whether max lines should be rendered or not.
Returns:
HTMLElement|nullMax lines of the text.
Since:
1.22
sap.m.Text.onAfterRendering()
Overwrites onAfterRendering
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
sap.m.Text.setText(sText): sap.m.Text
Sets the text.
Parameters:
stringsTextText value.
Returns:
sap.m.Textthis Text reference for chaining.
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
canUseNativeLineClamp(): Boolean

Decides whether the control can use native line clamp feature or not.

In RTL mode native line clamp feature is not supported.

Returns:
Boolean
Since:
1.20
getMaxLines(): int

Gets current value of property maxLines.

Limits the number of lines for wrapping texts.

Note: The multi-line overflow indicator depends on the browser line clamping support. For such browsers, this will be shown as ellipsis, for the other browsers the overflow will just be hidden.

Returns:
intValue of property maxLines
Since:
1.13.2
getRenderWhitespace(): boolean

Gets current value of property renderWhitespace.

Specifies how whitespace and tabs inside the control are handled. If true, whitespace will be preserved by the browser. Depending on wrapping property text will either only wrap on line breaks or wrap when necessary, and on line breaks.

Note: Special characters that can be used are : \t , \n and " " respectively Tab, New line and Space.

Default value is false.

Returns:
booleanValue of property renderWhitespace
Since:
1.51
getText(): string

Gets current value of property text.

Determines the text to be displayed.

Default value is empty string.

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
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
setMaxLines(iMaxLines): sap.m.Text

Sets a new value for property maxLines.

Limits the number of lines for wrapping texts.

Note: The multi-line overflow indicator depends on the browser line clamping support. For such browsers, this will be shown as ellipsis, for the other browsers the overflow will just be hidden.

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
setRenderWhitespace(bRenderWhitespace): sap.m.Text

Sets a new value for property renderWhitespace.

Specifies how whitespace and tabs inside the control are handled. If true, whitespace will be preserved by the browser. Depending on wrapping property text will either only wrap on line breaks or wrap when necessary, and on line breaks.

Note: Special characters that can be used are : \t , \n and " " respectively Tab, New line and Space.

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

Default value is false.

Parameters:
booleanbRenderWhitespaceNew value for property renderWhitespace
Returns:
sap.m.TextReference to this in order to allow method chaining
Since:
1.51
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 empty string.

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