Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(surveys): preserve newlines in hosted open text (#89755)

Lucas Faria6f9c20bd169b
diff --git a/frontend/src/scenes/surveys/hosted-canvas/HostedSurveyCanvas.tsx b/frontend/src/scenes/surveys/hosted-canvas/HostedSurveyCanvas.tsx
index c5dcb5b8ce59..4cd125bf76b3 100644
--- a/frontend/src/scenes/surveys/hosted-canvas/HostedSurveyCanvas.tsx
+++ b/frontend/src/scenes/surveys/hosted-canvas/HostedSurveyCanvas.tsx
@@ -9,6 +9,7 @@ import { type CSSProperties } from 'react'
import { IconPlus, IconThumbsDown, IconThumbsUp, IconTrash } from '@posthog/icons'
import { SortableDragIcon } from 'lib/lemon-ui/icons'
+import { platformCommandControlKey } from 'lib/utils/dom'
import { defaultSurveyAppearance } from 'scenes/surveys/constants'
import { surveyLogic } from 'scenes/surveys/surveyLogic'
import { canQuestionSkipSubmitButton, isThumbQuestion, sanitizeHTML } from 'scenes/surveys/utils'
@@ -386,11 +387,15 @@ function QuestionCanvas({ question, index }: { question: SurveyQuestion; index:
// hint set rendered by `posthog/templates/surveys/public_survey.html` so the
// canvas matches what respondents actually see.
function KeyboardHints({ questionType }: { questionType: SurveyQuestionType }): JSX.Element {
- const chips: { kbd: string; label: string }[] = [{ kbd: '\u21B5', label: 'submit' }]
-
- if (questionType === SurveyQuestionType.Open) {
- chips.push({ kbd: '\u21E7 \u21B5', label: 'new line' })
- } else if (questionType === SurveyQuestionType.SingleChoice) {
+ const chips: { kbd: string; label: string }[] =
+ questionType === SurveyQuestionType.Open
+ ? [
+ { kbd: '\u21B5', label: 'new line' },
+ { kbd: platformCommandControlKey('\u21B5'), label: 'submit' },
+ ]
+ : [{ kbd: '\u21B5', label: 'submit' }]
+
+ if (questionType === SurveyQuestionType.SingleChoice) {
chips.push({ kbd: '\u2191 \u2193', label: 'select' })
} else if (questionType === SurveyQuestionType.MultipleChoice) {
chips.push({ kbd: '\u2191 \u2193', label: 'select' })
diff --git a/posthog/templates/surveys/public_survey.html b/posthog/templates/surveys/public_survey.html
index 370869c0e383..5f13dc43e9b3 100644
--- a/posthog/templates/surveys/public_survey.html
+++ b/posthog/templates/surveys/public_survey.html
@@ -218,7 +218,10 @@
return
}
- if (event.key === 'Enter' && !event.shiftKey) {
+ const target = event.target
+ if (target instanceof HTMLElement && target.tagName === 'TEXTAREA') return
+
+ if (event.key === 'Enter' && !event.shiftKey && !event.isComposing) {
const submitButton = container.querySelector('.form-submit:not([disabled])')
if (!submitButton) return
event.preventDefault()
@@ -228,7 +231,6 @@
}
if (isArrowKey(event.key)) {
- const target = event.target
if (target instanceof HTMLElement) {
const tag = target.tagName
if (tag === 'TEXTAREA') return
@@ -334,11 +336,13 @@
const labels = getKeyboardHintLabels()
const chip = (kbd, label) =>
`<span class="survey-keyhint-row"><kbd class="survey-kbd">${kbd}</kbd><span class="survey-keyhint-label">${label}</span></span>`
+ const commandEnter = navigator.platform.includes('Mac') ? '⌘↵' : 'Ctrl + ↵'
- const chips = [chip('↵', labels.submit)]
- if (currentType === 'open') {
- chips.push(chip('⇧ ↵', labels.newline))
- } else if (currentType === 'single_choice') {
+ const chips =
+ currentType === 'open'
+ ? [chip('↵', labels.newline), chip(commandEnter, labels.submit)]
+ : [chip('↵', labels.submit)]
+ if (currentType === 'single_choice') {
chips.push(chip('↑ ↓', labels.select))
} else if (currentType === 'multiple_choice') {
chips.push(chip('↑ ↓', labels.select))