HomeDocsComponentsBlocksForm contractValidation
Components / CronInput

CronInput

A cron expression field that describes itself in English and previews the next few runs, so a five-field string stops being a guess. minInterval catches the * * * * * that somebody always ships by accident. An expression that is already equivalent is never rewritten — 1-5 stays 1-5 rather than being expanded to 1,2,3,4,5 the moment the field mounts.

$ npx shadcn@latest add https://input-cn.vercel.app/r/cron-input.json
Build with an agent

Hand this to Claude Code

1,478 chars

Most people reach this component through an agent rather than by reading the page. Pick how you want it wired and take a prompt that already carries the canonical value, the real prop names and the mistakes worth avoiding.

Wiring
Extras
Open in Claude Code

Nothing runs on its own. The link opens the tool with the prompt typed into the box; you read it and press Enter. If the button does nothing, Claude Code is not installed on this machine — use Copy prompt instead.

Live demo

At 09:00, Monday through Friday

Next runsFri, Sep 18, 09:00 AMMon, Sep 21, 09:00 AMTue, Sep 22, 09:00 AM

Try */15 * * * * or @daily.

value = "0 9 * * 1-5"

Constraints

Validation rules, declared as props. Each one produces its own message and its own data-rule value, so a test can assert the rule rather than the sentence.

PROPTYPEDESCRIPTION
minInterval?IntervalBoundReject schedules that fire more often than this. The constraint that earns its keep — it stops someone scheduling a job every second and taking down a worker queue.

Props

PROPTYPEDESCRIPTION
previewCount?numberHow many upcoming runs to compute for the preview. Default 3.
label?ReactNodeVisible label. Supply this or `aria-label` — a field with neither has no accessible name.
hint?ReactNodeHelper text under the field. Replaced by the error message while one is showing.
layout?CronLayout`expression` for engineers, `builder` for everyone else.
showDescription?booleanShow the plain-English reading. Default true.
showUpcoming?booleanShow upcoming run times. Default true.

Shared props

Implemented identically by all eleven components. These tables are generated from the source interfaces at build time, so a renamed prop changes this page rather than quietly making it wrong.

PROPTYPEDESCRIPTION
value?TCanonical value. Controlled mode.
defaultValue?TCanonical value. Uncontrolled mode. Mutually exclusive with `value`.
onChange?(value: T) => voidEmits the canonical value — never a DOM event.
onBlur?() => voidFires when focus leaves the whole component, not between its parts.
name?stringApplied to the hidden canonical input so FormData carries the real value.
disabled?boolean—
readOnly?boolean—
required?boolean | string—
validate?(value: T) => true | stringCustom synchronous rule. Return true, or the message to display.
messages?MessageMapOverride built-in messages by rule name.
showError?ShowErrorDefault `"touched"`.
onValidityChange?(state: ValidityState) => voidReports validity upward regardless of mode.
mode?FieldModeForce a mode instead of auto-detecting. Escape hatch only.
variant?FieldVariantSurface treatment. Default `"outline"`.
size?FieldSizeDensity. Default `"default"` (32px).
id?string—
className?string—
placeholder?string—
autoFocus?boolean—
aria-label?string—
aria-labelledby?string—
aria-describedby?string—
aria-invalid?boolean | "true" | "false"—

With react-hook-form

import { useForm, Controller } from "react-hook-form"
import { zodResolver } from "@hookform/resolvers/zod"
import { cronSchema } from "@inputcn/cron/schema"
import { CronInput } from "@/components/ui/cron-input"
import { z } from "zod"

// The companion schema validates the CANONICAL value, so the resolver and the
// field can never disagree about what "valid" means.
const schema = z.object({ schedule: cronSchema() })

export function Example() {
  const { control } = useForm({ resolver: zodResolver(schema) })

  return (
    <Controller
      name="schedule"
      control={control}
      render={({ field, fieldState }) => (
        <CronInput
          label="Schedule"
          {...field}
          aria-invalid={fieldState.invalid}
        />
      )}
    />
  )
}

With a Server Action

import { CronInput } from "@/components/ui/cron-input"

export default function Page() {
  return (
    <form action={save}>
      <CronInput name="schedule" label="Schedule" />
      <button>Save</button>
    </form>
  )
}

async function save(data: FormData) {
  "use server"
  // The hidden canonical input carries the real value, not the display text.
  const schedule = data.get("schedule") // "0 9 * * 1-5"
}

Keyboard

KEYDOES
Enter / SpaceToggles a day in the builder layout.

Emits string, for example "0 9 * * 1-5". Keyboard operation is covered by automated tests; screen readers have not been verified yet.