From 5f488f4c492e73a57f7f3d847888e28c426e79ed Mon Sep 17 00:00:00 2001 From: Hassan Abouelela Date: Thu, 10 Jun 2021 23:22:39 +0300 Subject: Adds Support For Linebreaks In Content Adds support for inserting line breaks in question names, and in the case of sections, question data. --- src/components/Question.tsx | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) (limited to 'src/components/Question.tsx') diff --git a/src/components/Question.tsx b/src/components/Question.tsx index 0af745e..2f5c496 100644 --- a/src/components/Question.tsx +++ b/src/components/Question.tsx @@ -205,6 +205,9 @@ class RenderedQuestion extends React.Component { render(): JSX.Element { const question = this.props.question; + const name = question.name.split("\n").map((line, index) => {line}
); + name.push({name.pop()?.props.children[0]}); + if (question.type === QuestionType.Section) { const styles = css` h1 { @@ -227,18 +230,24 @@ class RenderedQuestion extends React.Component { } `; + const data = question.data["text"]; + let text; + + if (data && typeof(data) === "string") { + text = data.split("\n").map((line, index) =>

{line}

); + text.push(

{text.pop()?.props.children[0]}

); + } else { + text = ""; + } + return
-

{question.name}

- { question.data["text"] ?

{question.data["text"]}

: "" } +

{name}

+ { text }
; } else { const requiredStarStyles = css` - span { - display: none; - } - .required { display: inline-block; position: relative; @@ -261,7 +270,7 @@ class RenderedQuestion extends React.Component { return

- {question.name}* + {name}*

{ create_input(this.props, this.handler, this.blurHandler, this.props.focus_ref) } -- cgit v1.2.3