Expression Editor
betaA formula field with highlighting, autocomplete for variables and functions, the error where it is, and a live result. Evaluated without eval.
- Forms
- 6 files
- 1 npm package
- Accessibility notes
pnpm dlx @dowel-ui/cli add expression-editornpm packages installed: class-variance-authority.
import { ExpressionEditor } from "@/components/ui/expression-editor";Default
Error State
Custom Functions
Multiline
Without Result
<ExpressionEditor>
| Prop | Type | Default |
|---|---|---|
aria-describedby | string | — |
aria-invalid | AriaAttributes["aria-invalid"] | — |
aria-labelGoes to the field, where the role is. | string | — |
aria-labelledby | string | — |
defaultValue | string | "" |
descriptionA hint under the label, read with the field. | ReactNode | — |
disabled | boolean | false |
editorSize | "sm" | "md" | "lg" | "md" |
fieldIdThe field's id, for a | string | — |
fieldRefThe input or textarea itself. | Ref<HTMLInputElement | HTMLTextAreaElement> | — |
formatResultReplaces how the result is written after "=". | (value: ExpressionValue) => string | — |
functionsThe functions that can be called. Replaces the defaults; spread | ExpressionFunctions | defaultExpressionFunctions |
labelVisible label. Without one, pass | ReactNode | — |
localeFor numbers in the result and the suggestions. | string | — |
multilineA textarea, where Enter starts a new line. Otherwise Enter never does. | boolean | false |
name | string | — |
onResultChangeCalled with each settled result, including the first. | (result: ExpressionResult) => void | — |
onValueChange | (value: string) => void | — |
placeholder | string | — |
readOnly | boolean | false |
required | boolean | — |
resultDelayMilliseconds of quiet typing before the result and any error update. | number | 300 |
rowsVisible lines when | number | 3 |
showResultShows "= 36" under the field. Errors show either way. | boolean | true |
valueThe expression. Controlled. | string | — |
variablesWhat names refer to. Nested objects are reached with dotted paths: | ExpressionVariables | — |
Plus every attribute of <div> except defaultValue, onChange, children, aria-label, aria-labelledby, aria-describedby, aria-invalid.
10/10
checks passed
- Tested — passes
- axe assertion — passes
- Keyboard tested — passes
- Storybook examples — passes
- Accessibility documented — passes
- Semantic tokens only — passes
- Motion from tokens — passes
- className merged — passes
- Visible focus — passes
- No fixed widths — passes