clickworks
Works / Forms

NPS Survey

The score sits on a dial like a watch face. Tap, drag or use the arrow keys and a pointer moves round the arc while it fills to the score, and the big number in the middle changes with a soft blur. After a score, a follow-up question opens that fits the answer.

Free1 filemotion dependency8.3 kB gzippedRenders on the serverKeyboard and screen reader

Install

npx shadcn@latest add https://clickworks.dev/r/nps-survey.json

The files land in components/clickworks/nps-survey/. The CLI also installs motion.

Usage

"use client"

import { NPSSurvey } from "@/components/clickworks/nps-survey/react/NPSSurvey"

export function Feedback() {
  return (
    <NPSSurvey
      onSubmit={(answer) => fetch("/api/feedback", { method: "POST", body: JSON.stringify(answer) }).then((r) => r.ok)}
    />
  )
}

Props

onSubmit
(answer: { score, category, comment }) => unknown

Receives the answer when the survey isn't in a form. Return false or throw to keep it open.

question / description
string

The question and the line under it.

labels
{ low?, high? }

The words at both ends of the dial.

Default Not likely / Very likely

followUp
{ detractor?, passive?, promoter?, placeholder?, maxChars? } | null

A follow-up question for each kind of score. null skips it.

thanks
{ title?, message? }

What it says once it's sent.

theme
"light" | "dark" | "auto"

Auto follows the page (its background, data-theme or dark class), then the device.

Default "auto"

light / dark
object

Colours for each theme, including the Send button text.

fieldName / required
string / boolean

Inside a form: the field names it submits under, and whether a score is required.

Default "nps" / true

sendLabel
string

Text on its own Send button.

Default "Send"

Events

Styling

Colours come in through the light and dark props, and each layer of text can take its own font through typography.

Behaviour and accessibility

  • The dial is a slider: arrow keys move the score and screen readers hear it as "7 out of 10".
  • Inside a form the score, category and comment are real fields, and a required score blocks the form.
  • Cmd or Ctrl and Enter in the comment sends it.
  • With reduced motion the numbers swap without the blur.

Files

react/NPSSurvey.tsxReact component