feat(surveys): add SliderQuestion survey type#3774
Conversation
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>
|
@TJLSmith0831 is attempting to deploy a commit to the PostHog Team on Vercel. A member of the Team first needs to authorize it. |
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Prompt To Fix All With AIFix 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>
|
ping @PostHog/team-surveys |
|
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. |
|
Reviews (2): Last reviewed commit: "Merge branch 'main' into feat/slider-sur..." | Re-trigger Greptile |
|
@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? |
|
made it a draft until we support the frontend/backend bits |
…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>
|
@lucasheriques Just added the e2e tests and here are the screenshots: Additionally, the main repo PR is here e2e tests: added
All cases pass on chromium via Preview / screenshot: I also added a tiny local playground at
|
|
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 |

Summary
slidersurvey question type (SurveyQuestionType.Slider) with configurablemin,max,step, optionalprefix/suffixfor value display, andlowerBoundLabel/upperBoundLabelonInput) rather than only on releasevite-surveysplayground which was broken (referencing a removedcreateShadow/styleexport); rewired to use the currentgetSurveyStylesheetAPI and added a Vite plugin to handle thesurvey.cssraw string importScreenshot
Test plan
pnpm --filter=posthog-js buildpassespnpm --filter=posthog-js lintpassespnpm --filter=posthog-js test:unitpassespackages/browser/playground/vite-surveysrenders slider questions correctly🤖 Generated with Claude Code