Search code examples
sapui5

How to display newline in TimelineItem control's text property?


We have a SAPUI5 timeline control, where we are showing the comments coming from server.

The issue is, if the comments contain a newline \n, then the Timeline control is not able to display the text in newline. Instead, it introduces space wherever \n is present. We have tried formatting \n to unicode character also but that also didn't worked. Timeline control aggregates TimelineItem. The control we are using is: https://ui5.sap.com/#/api/sap.suite.ui.commons.TimelineItem

Code snippet can be found at: https://jsbin.com/kuluyehilu/edit?html,output


Solution

  • I inspected your example and came up with the following solution.

    Since the text is embedded in a <span>, all unnecessary whitespace will be trimmed. What you can do is telling the span (via CSS) that it should display the whitespace anyway.

    If you don't have a CSS file in your project yet, create one. Then add the following lines

    div.sapSuiteUiCommonsTimelineItemShellBody>span {
        white-space: pre;
    }
    

    This should do the trick.

    JSBin: https://jsbin.com/feladeneso/1/edit?html,output