Skip to content

feat(surveys): add SliderQuestion survey type#3774

Draft
TJLSmith0831 wants to merge 9 commits into
PostHog:mainfrom
TJLSmith0831:feat/slider-survey-question
Draft

feat(surveys): add SliderQuestion survey type#3774
TJLSmith0831 wants to merge 9 commits into
PostHog:mainfrom
TJLSmith0831:feat/slider-survey-question

Conversation

@TJLSmith0831

@TJLSmith0831 TJLSmith0831 commented Jun 9, 2026

Copy link
Copy Markdown

Summary

  • Adds a new slider survey question type (SurveyQuestionType.Slider) with configurable min, max, step, optional prefix/suffix for value display, and lowerBoundLabel/upperBoundLabel
  • Renders full-width with the slider track spanning the card, and a three-column row underneath: left label | live value chip | right label — matching the layout convention of the rating question
  • Value updates live on drag (onInput) rather than only on release
  • Fixes the vite-surveys playground which was broken (referencing a removed createShadow/style export); rewired to use the current getSurveyStylesheet API and added a Vite plugin to handle the survey.css raw string import

Screenshot

Screenshot 2026-06-16 at 5 51 47 AM

Test plan

  • pnpm --filter=posthog-js build passes
  • pnpm --filter=posthog-js lint passes
  • pnpm --filter=posthog-js test:unit passes
  • Playground at packages/browser/playground/vite-surveys renders slider questions correctly
  • Slider value updates live while dragging
  • Long bound labels wrap without interfering with the slider track or value chip

🤖 Generated with Claude Code

Adds a new `slider` survey question type with configurable min/max/step,
optional prefix/suffix for value formatting, and lower/upper bound labels.
The slider renders full-width with labels and the live value chip displayed
in a three-column row underneath — matching the layout convention of the
rating question type.

Also fixes the vite-surveys playground which was referencing a removed
`createShadow`/`style` export; rewired to use the current
`getSurveyStylesheet` API so the playground works out of the box.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@vercel

vercel Bot commented Jun 9, 2026

Copy link
Copy Markdown

@TJLSmith0831 is attempting to deploy a commit to the PostHog Team on Vercel.

A member of the Team first needs to authorize it.

@greptile-apps

greptile-apps Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor
Prompt To Fix All With AI
Fix the following 1 code review issue. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 1
packages/browser/src/extensions/surveys/components/QuestionTypes.tsx:583-593
Default value not snapped to `step` — chip and thumb can show different positions on first render. `Math.round((min + max) / 2)` does not account for the step increment, so e.g. `min=0, max=10, step=3` produces a default of `5` while the browser normalises the thumb to `6`. The chip will display `5`, but if the user submits without touching the slider the recorded response is `5` — a value that is not a valid step position. The same misalignment applies to numeric and string `initialValue` paths.

```suggestion
    const snapToStep = (val: number): number => {
        const steps = Math.round((val - question.min) / question.step)
        return Math.max(question.min, Math.min(question.max, question.min + steps * question.step))
    }

    const [value, setValue] = useState<number>(() => {
        if (isNumber(initialValue)) {
            return snapToStep(Math.max(question.min, Math.min(question.max, initialValue as number)))
        }
        if (isString(initialValue) && !isNaN(Number(initialValue))) {
            const numValue = Number(initialValue)
            return snapToStep(Math.max(question.min, Math.min(question.max, numValue)))
        }
        // Default to middle of range, snapped to nearest step
        return snapToStep((question.min + question.max) / 2)
    })
```

Reviews (1): Last reviewed commit: "Merge branch 'main' into feat/slider-sur..." | Re-trigger Greptile

Avoids chip/thumb misalignment on first render when the computed default
doesn't land on a valid step position (e.g. min=0, max=10, step=3 would
produce 5, but the browser normalises the thumb to 6). Applies to all
initialisation paths: numeric initialValue, string initialValue, and the
default midpoint.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@marandaneto

Copy link
Copy Markdown
Member

ping @PostHog/team-surveys

@TJLSmith0831 TJLSmith0831 marked this pull request as ready for review June 15, 2026 11:20
@TJLSmith0831 TJLSmith0831 requested a review from a team as a code owner June 15, 2026 11:21
@socket-security

Copy link
Copy Markdown

Dependency limit exceeded — report not shown.

This pull request scan exceeded the 10,000-dependency limit applied to this scan, so the results are incomplete and may be inaccurate. To avoid reporting false positives, Socket has not posted a report.

Upgrade your plan to raise the dependency limit and get complete reports, or view the partial scan in the dashboard.

Socket is always free for open source. If this is a non-commercial open source project, contact us to request a free Team account.

@greptile-apps

greptile-apps Bot commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Reviews (2): Last reviewed commit: "Merge branch 'main' into feat/slider-sur..." | Re-trigger Greptile

@lucasheriques

lucasheriques commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

@TJLSmith0831 do you mind adding e2e tests as well as screenshots to the PR?

also, we will need a PR on the main repo too, so users can properly set that up. do you plan on adding it too?

@marandaneto marandaneto marked this pull request as draft June 16, 2026 06:06
@marandaneto

Copy link
Copy Markdown
Member

made it a draft until we support the frontend/backend bits
#3774 (comment)

TJLSmith0831 and others added 2 commits June 16, 2026 05:05
…ound

Adds Playwright coverage for the new slider survey question (default
snapping, value capture, prefix/suffix rendering) and a self-contained
playground page that previews the slider via renderSurveysPreview so
reviewers can interact with the component locally.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@TJLSmith0831

TJLSmith0831 commented Jun 16, 2026

Copy link
Copy Markdown
Author

@lucasheriques Just added the e2e tests and here are the screenshots:

Additionally, the main repo PR is here

e2e tests: added packages/browser/playwright/mocked/surveys/slider-question.spec.ts covering:

  • default value is snapped to the middle of the range and submits the chip value as-is
  • arrow-key interaction captures the selected value in the survey sent event
  • step-aware default snapping (the min=0, max=10, step=3 case the greptile bot flagged) — verifies chip and thumb agree on first render
  • prefix/suffix rendering around the value
  • a screenshot test that emits the images below into playwright/mocked/surveys/screenshots/

All cases pass on chromium via pnpm playwright:surveys.

Preview / screenshot: I also added a tiny local playground at packages/browser/playground/slider-demo/index.html that uses renderSurveysPreview so it can be opened with any static server (e.g. pnpm playwright-webserverhttp://localhost:2345/playground/slider-demo/index.html). The controls let you tweak min/max/step/prefix/suffix/bound labels and the slider re-renders live. Screenshot of the default render:

Screenshot 2026-06-16 at 5 51 47 AM

@github-actions

Copy link
Copy Markdown
Contributor

This PR hasn't seen activity in a week! Should it be merged, closed, or further worked on? If you want to keep it open, post a comment or remove the stale label – otherwise this will be closed in another week.

@github-actions github-actions Bot added the stale label Jun 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants