: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(surveys): match hosted survey rating preview to live rendering (#69633)
posthog[bot]6388f36ef885
diff --git a/frontend/public/surveys/hosted-survey.css b/frontend/public/surveys/hosted-survey.cssindex 2874ad4670e4..ed0f7af3efa6 100644--- a/frontend/public/surveys/hosted-survey.css+++ b/frontend/public/surveys/hosted-survey.css@@ -357,6 +357,11 @@ body.PostHogHostedSurvey {justify-content: space-between;}+/* Two-option (thumbs) ratings sit together, not pinned to the edges; posthog-js sets this but loses to the scoped rule above. */+.PostHogHostedSurvey .rating-options-emoji-2 {+ justify-content: space-around;+}+.PostHogHostedSurvey .ratings-emoji {min-width: 2.75rem;min-height: 2.75rem;diff --git a/frontend/src/scenes/surveys/hosted-canvas/HostedSurveyCanvas.scss b/frontend/src/scenes/surveys/hosted-canvas/HostedSurveyCanvas.scssindex 50fe2cecd9bd..2a27c3824519 100644--- a/frontend/src/scenes/surveys/hosted-canvas/HostedSurveyCanvas.scss+++ b/frontend/src/scenes/surveys/hosted-canvas/HostedSurveyCanvas.scss@@ -49,6 +49,18 @@}}+ // Thumbs (2-point) render icon SVGs; center and size them. Scoped so glyph scales keep default layout.+ .rating-options-emoji-2 .ratings-emoji {+ display: inline-flex;+ align-items: center;+ justify-content: center;++ svg {+ width: 1.5rem;+ height: 1.5rem;+ }+ }+// Display elements (h1.survey-question, p.survey-question-description,// span.form-submit, etc.) keep their natural styling — we ONLY add an edit// affordance. No font/padding/background/border-radius reset on these sodiff --git a/frontend/src/scenes/surveys/hosted-canvas/HostedSurveyCanvas.tsx b/frontend/src/scenes/surveys/hosted-canvas/HostedSurveyCanvas.tsxindex 4712d06d2f63..c5dcb5b8ce59 100644--- a/frontend/src/scenes/surveys/hosted-canvas/HostedSurveyCanvas.tsx+++ b/frontend/src/scenes/surveys/hosted-canvas/HostedSurveyCanvas.tsx@@ -6,12 +6,12 @@ import { CSS } from '@dnd-kit/utilities'import { useActions, useValues } from 'kea'import { type CSSProperties } from 'react'-import { IconPlus, IconTrash } from '@posthog/icons'+import { IconPlus, IconThumbsDown, IconThumbsUp, IconTrash } from '@posthog/icons'import { SortableDragIcon } from 'lib/lemon-ui/icons'import { defaultSurveyAppearance } from 'scenes/surveys/constants'import { surveyLogic } from 'scenes/surveys/surveyLogic'-import { canQuestionSkipSubmitButton, sanitizeHTML } from 'scenes/surveys/utils'+import { canQuestionSkipSubmitButton, isThumbQuestion, sanitizeHTML } from 'scenes/surveys/utils'import {type MultipleSurveyQuestion,@@ -25,7 +25,11 @@ import {import { type NewSurvey } from '../constants'import { InlineEditable } from './InlineEditable'-const RATING_EMOJI_PREVIEW = ['\u{1F621}', '\u{1F641}', '\u{1F610}', '\u{1F642}', '\u{1F60D}']+// Per-scale lists mirroring posthog-js emojiScaleLists; scale 2 (thumbs) renders icons instead.+const RATING_EMOJI_PREVIEW: Record<number, string[]> = {+ 3: ['\u{1F641}', '\u{1F610}', '\u{1F642}'],+ 5: ['\u{1F621}', '\u{1F641}', '\u{1F610}', '\u{1F642}', '\u{1F60D}'],+}function getLuminance(color: string | undefined): number | null {if (!color) {@@ -581,9 +585,18 @@ function RatingCanvas({}): JSX.Element {const scale = question.scaleconst length = scale === 10 ? 11 : scale+ const isThumbs = isThumbQuestion(question)+ // Emoji display is UI-restricted to scales 2/3/5; the [5] fallback is defensive.+ const emojis = RATING_EMOJI_PREVIEW[scale] ?? RATING_EMOJI_PREVIEW[5]return (<div className="rating-section">- <div className={question.display === 'emoji' ? 'rating-options-emoji' : 'rating-options-number'}>+ <div+ className={+ question.display === 'emoji'+ ? `rating-options-emoji${isThumbs ? ' rating-options-emoji-2' : ''}`+ : 'rating-options-number'+ }+ >{Array.from({ length }, (_, idx) => {const value = scale === 10 ? idx : idx + 1return (@@ -594,27 +607,38 @@ function RatingCanvas({tabIndex={-1}aria-hidden>- {question.display === 'emoji'- ? RATING_EMOJI_PREVIEW[idx] || RATING_EMOJI_PREVIEW[3]- : value}+ {isThumbs ? (+ // value 1 = thumbs up, 2 = thumbs down (the stored response mapping).+ value === 1 ? (+ <IconThumbsUp />+ ) : (+ <IconThumbsDown />+ )+ ) : question.display === 'emoji' ? (+ (emojis[idx] ?? emojis[emojis.length - 1])+ ) : (+ value+ )}</button>)})}</div>- <div className="rating-text">- <InlineEditable- value={question.lowerBoundLabel || ''}- onChange={onLowerBoundChange}- placeholder="Low end label"- ariaLabel="Lower bound label"- />- <InlineEditable- value={question.upperBoundLabel || ''}- onChange={onUpperBoundChange}- placeholder="High end label"- ariaLabel="Upper bound label"- />- </div>+ {!isThumbs ? (+ <div className="rating-text">+ <InlineEditable+ value={question.lowerBoundLabel || ''}+ onChange={onLowerBoundChange}+ placeholder="Low end label"+ ariaLabel="Lower bound label"+ />+ <InlineEditable+ value={question.upperBoundLabel || ''}+ onChange={onUpperBoundChange}+ placeholder="High end label"+ ariaLabel="Upper bound label"+ />+ </div>+ ) : null}</div>)}