Plate
PlateEditorsCreateTemplates
GitHub16kGitHub
DiscordDiscord
    • Stream
    • Copilot
    • Prompt Editor
  • Comments
  • Discussion
  • Suggestions
    • Basic Blocks
      • Blockquote
      • Heading
      • Horizontal Rule
    • Board
    • Callout
    • Code Block
    • Column
    • Date
    • Equation
    • FieldExperimental
    • Link
    • Media
    • MentionElement
    • Table
    • Table of Contents
    • Footnote
    • Details
  • Marks
    • Bold
    • Italic
    • Underline
    • Code
    • Highlight
    • Keyboard Input
    • Strikethrough
    • Subscript
    • Superscript
      • Font
      • Line Height
      • Text Align
      • Clear Formatting
      • Format Painter
    • Indent
    • List
      • Exit Break
      • Single Block
      • Trailing Block
    • Autoformat
    • Block Menu
    • Block Placeholder
    • Combobox
      • Emoji
      • MentionElement
      • Slash Command
    • Drag & Drop
    • Navigation Feedback
    • Linting
    • Tabbable
    • Toolbar
    • Yjs
    • Multi SelectEditor
    • DOCX
    • HTML
    • Markdown

Date

PreviousNext

Inline void date elements with one authored string value.

Date ElementPlus

Date adds inline void elements that display a date label inside text. One required value preserves either a canonical YYYY-MM-DD date or authored text such as sometime next week.

Loading…
ColumnEquation

On This Page

FeaturesFast pathAdd the kitRender the elementAdd an insert actionOwnershipManual setupInstall packageAdd the pluginAdd static renderingInsert a dateValue shapeDate valuesPicker behaviorMarkdownAPI Reference
Build your editor
Production-ready AI template and reusable components.
Get all-access

Features

  • Inline void date element.
  • date.insert transaction command.
  • One required value for canonical dates or authored date text.
  • Calendar editing in the registry UI.
  • Static renderer for read-only output and exports.
  • Markdown round-trip through <date value="YYYY-MM-DD" /> and <date text="…" />, and reading of <date> child text.
Report an issue

Fast path

Add the kit

DateKit installs DatePlugin with the registry DateElement.

'use client';
 
import { cn } from 'cn';
import { formatDateValue, parseCanonicalDateValue } from 'platejs/date';
import { DatePlugin } from 'platejs/date/react';
import {
  type EditorElementProps,
  EditorElement,
  useEditorReadOnly,
} from 'platejs/react';
import * as React from 'react';
 
import { Calendar } from '@/components/ui/calendar';
import {
  Popover,
  PopoverContent,
  PopoverTrigger,
} from '@/components/ui/popover';
import { inlineSuggestionVariants } from '@/lib/inline-suggestion';
 
const DAY_MS = 86_400_000;
const RELATIVE_DAYS: Partial<Record<number, string>> = {
  [-1]: 'Yesterday',
  0: 'Today',
  1: 'Tomorrow',
};
const dateFormat = new Intl.DateTimeFormat('en-US', {
  dateStyle: 'long',
  timeZone: 'UTC',
});
 
const getDateLabel = (value: string) => {
  if (!parseCanonicalDateValue(value)) return value;
 
  const day = Date.parse(value);
  const today = Date.parse(formatDateValue(new Date()));
 
  return RELATIVE_DAYS[(day - today) / DAY_MS] ?? dateFormat.format(day);
};
 
export function DateElement(props: EditorElementProps<typeof DatePlugin>) {
  const { editor, element } = props;
  const readOnly = useEditorReadOnly();
  const openRef = React.useRef(false);
  const openAtPointerDownRef = React.useRef(false);
  const [open, setOpen] = React.useState(false);
  const selectedDate = parseCanonicalDateValue(element.value);
  const setOpenState = React.useCallback((nextOpen: boolean) => {
    openRef.current = nextOpen;
    setOpen(nextOpen);
  }, []);
 
  const trigger = (
    <button
      className={cn(
        'w-fit cursor-pointer rounded-sm bg-muted px-1 text-muted-foreground',
        inlineSuggestionVariants({ on: 'parent' })
      )}
      contentEditable={false}
      draggable
      onClick={(event) => {
        const beganOpen =
          event.detail === 0 ? openRef.current : openAtPointerDownRef.current;
 
        if (readOnly || beganOpen) return;
 
        event.preventDefault();
        setOpenState(true);
      }}
      onPointerDown={() => {
        openAtPointerDownRef.current = openRef.current;
      }}
      type="button"
    >
      {getDateLabel(element.value)}
    </button>
  );
 
  return (
    <EditorElement
      {...props}
      className="inline-block"
      attributes={{
        ...props.attributes,
        contentEditable: false,
      }}
    >
      {readOnly ? (
        trigger
      ) : (
        <Popover open={open} onOpenChange={setOpenState}>
          <PopoverTrigger asChild>{trigger}</PopoverTrigger>
          <PopoverContent className="w-auto p-0">
            <Calendar
              defaultMonth={selectedDate}
              selected={selectedDate}
              onSelect={(date) => {
                if (!date) return;
 
                editor.update.nodes.set(
                  { value: formatDateValue(date) },
                  { at: element }
                );
              }}
              mode="single"
              autoFocus
            />
          </PopoverContent>
        </Popover>
      )}
      {props.children}
    </EditorElement>
  );
}
 
export const DateKit = [DatePlugin.configure({ component: DateElement })];
'use client';
 
import { cn } from 'cn';
import { formatDateValue, parseCanonicalDateValue } from 'platejs/date';
import { DatePlugin } from 'platejs/date/react';
import {
  type EditorElementProps,
  EditorElement,
  useEditorReadOnly,
} from 'platejs/react';
import * as React from 'react';
 
import { Calendar } from '@/components/ui/calendar';
import {
  Popover,
  PopoverContent,
  PopoverTrigger,
} from '@/components/ui/popover';

































































































import { createEditor } from 'platejs/react';
 
import { DateKit } from '@/components/editor/date';
 
export const editor = createEditor({
  plugins: DateKit,
});
import { createEditor } from 'platejs/react';
 
import { DateKit } from '@/components/editor/date';
 
export const editor = createEditor({
  plugins: DateKit,

Render the element

date owns the inline wrapper, label, popover and calendar picker.

'use client';
 
import { cn } from 'cn';
import { formatDateValue, parseCanonicalDateValue } from 'platejs/date';
import { DatePlugin } from 'platejs/date/react';
import {
  type EditorElementProps,
  EditorElement,
  useEditorReadOnly,
} from 'platejs/react';
import * as React from 'react';
 
import { Calendar } from '@/components/ui/calendar';
import {
  Popover,
  PopoverContent,
  PopoverTrigger,
} from '@/components/ui/popover';

































































































Add an insert action

The registry insert toolbar maps PLUGINS.date to the plugin-owned update.

components/editor/transforms.ts
import { BaseDatePlugin } from 'platejs/date';
import { PLUGINS } from 'platejs';
 
export const insertInlineMap = {
  [PLUGINS.date]: (editor) =>
    editor.plugin(BaseDatePlugin).update.insert({}, { select: true }),
};
components/editor/transforms.ts
import { BaseDatePlugin } from 'platejs/date';





Ownership

LayerOwnerWhat It Does
platejs/datePackageExports BaseDatePlugin, formatDateValue and parseCanonicalDateValue, and maps the <date> Markdown tag.
platejs/date/reactPackageExports DatePlugin.
dateRegistryAdds DatePlugin.configure({ component: DateElement }) and renders the label and calendar popover.
date-staticRegistryAdds BaseDatePlugin.configure({ component: DateElementStatic }) and renders the full-date label.
platejs/markdownPackageRuns BaseDatePlugin's <date> mapping when Markdown is parsed or serialized.

BaseDatePlugin is inline and void. The text child exists only to satisfy Plate's element shape.

Manual setup

Install package

pnpm add platejs
pnpm add platejs

Add the plugin

Use the React plugin when the editor renders the calendar popover.

import { DatePlugin } from 'platejs/date/react';
import { createEditor } from 'platejs/react';
 
import { DateElement } from '@/components/editor/date';
 
export const editor = createEditor({
  plugins: [DatePlugin.configure({ component: DateElement })],
});
import { DatePlugin } from 'platejs/date/react';
import { createEditor } from 'platejs/react';
 
import { DateElement } from '@/components/editor/date';
 
export const editor = createEditor({
  plugins: [DatePlugin.configure({ component: DateElement })],
});

Add static rendering

Use the base kit when rendering read-only output with platejs/static.

import { BaseDatePlugin, parseCanonicalDateValue } from 'platejs/date';
import { type EditorElementProps, EditorElement } from 'platejs/static';
import * as React from 'react';
 
const dateFormat = new Intl.DateTimeFormat('en-US', {
  dateStyle: 'long',
  timeZone: 'UTC',
});
 
const getDateLabel = (value: string) =>
  parseCanonicalDateValue(value) ? dateFormat.format(Date.parse(value)) : value;
 
export
















Insert a date

DatePlugin exposes date insertion through the date transaction group.

editor.update((tx) =>
  tx.date.insert({ value: '2026-03-23' }, { select: true })
);
editor.update((tx) =>
  tx.date.insert({ value: '2026-03-23' }, { select: true })
);

Value shape

Date elements store one non-empty authored string. Parsing is derived from that value rather than persisted as a second field.

const value = [
  {
    children: [
      { text: 'Due ' },
      {
        children: [{ text: '' }],
        type: 'date',
        value: '2026-03-23',
      },
      { text: '.' },
    ],
    type: 'paragraph',
  },
];
const value = [
  {
    children: [
      { text: 'Due ' },
      {
        children: [{ text: '' }],
        type: 'date',
        value: '2026-03-23',
      },
      { text: '.' },
    ],
    type: 'paragraph',
  },
];
FieldTypeNotes
type'date'Persisted element type owned by BaseDatePlugin.
children[{ text: '' }]Required Plate child for the inline void element.
valuestringRequired canonical date or authored date text.

Date values

update.insert stores one string.

InputStored Value
No valueToday's local day as YYYY-MM-DD.
Date objectformatDateValue(value); an invalid Date inserts nothing.
StringThe trimmed string, such as 2026-03-23 or sometime next week; a blank string inserts nothing.

parseCanonicalDateValue(value) returns a Date for a valid YYYY-MM-DD day and undefined for authored text. A string passed to insert is stored as written, so pass a Date to store a day.

The v54 migration and the Markdown reader read toDateString() text, such as Mon Mar 23 2026, as the day 2026-03-23 when its weekday matches. Other text stays as written.

Each copied component builds its own label. DateElement shows Today, Yesterday or Tomorrow for nearby days and the full date, such as March 23, 2026, otherwise. It reads the clock while rendering, so server HTML uses the server's day. DateElementStatic always prints the full date, so an export never goes stale. Both print US English; edit the copied dateFormat and words to change the language.

Picker behavior

The registry element is display-only while read-only. In editable mode, clicking the inline label opens a calendar popover.

StateBehavior
canonical valueThe trigger shows Today, Yesterday or Tomorrow for nearby days and the full date otherwise.
other valueThe trigger shows the authored string.
calendar selectionThe node is set to { value: formatDateValue(date) }.

The registry element uses contentEditable={false} on the inline wrapper, so users edit the date through the calendar instead of typing inside the void node.

Markdown

Canonical values serialize as a self-closing date tag with a value attribute.

Date: <date value="2026-03-23" />
Date: <date value="2026-03-23" />

Other authored values serialize with a text attribute, which the reader keeps as written. Child text would not survive, because Markdown can change it, such as at a blank line or an emoji shortcode.

Date: <date text="sometime next week" />
Date: <date text="sometime next week" />

The reader also accepts child text, such as <date>sometime next week</date>. It reads toDateString() text in a value attribute or child text, such as <date>Mon Mar 23 2026</date>, as value: '2026-03-23' when its weekday matches.

API Reference

APIPackageUse
BaseDatePluginplatejs/dateHeadless inline void date plugin.
DatePluginplatejs/date/reactReact date plugin.
editor.plugin(BaseDatePlugin).update.insert(input?, options?)BaseDatePlugin updateInserts a date from a Date or string value, with node placement options.
formatDateValue(date)platejs/dateFormats a Date object's local day as YYYY-MM-DD.
parseCanonicalDateValue(value)platejs/dateReturns a Date for a valid YYYY-MM-DD day, or undefined.
DateElementplatejs/dateElement shape with one required value.
import
{ inlineSuggestionVariants }
from
'@/lib/inline-suggestion'
;
const DAY_MS = 86_400_000;
const RELATIVE_DAYS: Partial<Record<number, string>> = {
[-1]: 'Yesterday',
0: 'Today',
1: 'Tomorrow',
};
const dateFormat = new Intl.DateTimeFormat('en-US', {
dateStyle: 'long',
timeZone: 'UTC',
});
const getDateLabel = (value: string) => {
if (!parseCanonicalDateValue(value)) return value;
const day = Date.parse(value);
const today = Date.parse(formatDateValue(new Date()));
return RELATIVE_DAYS[(day - today) / DAY_MS] ?? dateFormat.format(day);
};
export function DateElement(props: EditorElementProps<typeof DatePlugin>) {
const { editor, element } = props;
const readOnly = useEditorReadOnly();
const openRef = React.useRef(false);
const openAtPointerDownRef = React.useRef(false);
const [open, setOpen] = React.useState(false);
const selectedDate = parseCanonicalDateValue(element.value);
const setOpenState = React.useCallback((nextOpen: boolean) => {
openRef.current = nextOpen;
setOpen(nextOpen);
}, []);
const trigger = (
<button
className={cn(
'w-fit cursor-pointer rounded-sm bg-muted px-1 text-muted-foreground',
inlineSuggestionVariants({ on: 'parent' })
)}
contentEditable={false}
draggable
onClick={(event) => {
const beganOpen =
event.detail === 0 ? openRef.current : openAtPointerDownRef.current;
if (readOnly || beganOpen) return;
event.preventDefault();
setOpenState(true);
}}
onPointerDown={() => {
openAtPointerDownRef.current = openRef.current;
}}
type="button"
>
{getDateLabel(element.value)}
</button>
);
return (
<EditorElement
{...props}
className="inline-block"
attributes={{
...props.attributes,
contentEditable: false,
}}
>
{readOnly ? (
trigger
) : (
<Popover open={open} onOpenChange={setOpenState}>
<PopoverTrigger asChild>{trigger}</PopoverTrigger>
<PopoverContent className="w-auto p-0">
<Calendar
defaultMonth={selectedDate}
selected={selectedDate}
onSelect={(date) => {
if (!date) return;
editor.update.nodes.set(
{ value: formatDateValue(date) },
{ at: element }
);
}}
mode="single"
autoFocus
/>
</PopoverContent>
</Popover>
)}
{props.children}
</EditorElement>
);
}
export const DateKit = [DatePlugin.configure({ component: DateElement })];
});
import { inlineSuggestionVariants } from '@/lib/inline-suggestion';
const DAY_MS = 86_400_000;
const RELATIVE_DAYS: Partial<Record<number, string>> = {
[-1]: 'Yesterday',
0: 'Today',
1: 'Tomorrow',
};
const dateFormat = new Intl.DateTimeFormat('en-US', {
dateStyle: 'long',
timeZone: 'UTC',
});
const getDateLabel = (value: string) => {
if (!parseCanonicalDateValue(value)) return value;
const day = Date.parse(value);
const today = Date.parse(formatDateValue(new Date()));
return RELATIVE_DAYS[(day - today) / DAY_MS] ?? dateFormat.format(day);
};
export function DateElement(props: EditorElementProps<typeof DatePlugin>) {
const { editor, element } = props;
const readOnly = useEditorReadOnly();
const openRef = React.useRef(false);
const openAtPointerDownRef = React.useRef(false);
const [open, setOpen] = React.useState(false);
const selectedDate = parseCanonicalDateValue(element.value);
const setOpenState = React.useCallback((nextOpen: boolean) => {
openRef.current = nextOpen;
setOpen(nextOpen);
}, []);
const trigger = (
<button
className={cn(
'w-fit cursor-pointer rounded-sm bg-muted px-1 text-muted-foreground',
inlineSuggestionVariants({ on: 'parent' })
)}
contentEditable={false}
draggable
onClick={(event) => {
const beganOpen =
event.detail === 0 ? openRef.current : openAtPointerDownRef.current;
if (readOnly || beganOpen) return;
event.preventDefault();
setOpenState(true);
}}
onPointerDown={() => {
openAtPointerDownRef.current = openRef.current;
}}
type="button"
>
{getDateLabel(element.value)}
</button>
);
return (
<EditorElement
{...props}
className="inline-block"
attributes={{
...props.attributes,
contentEditable: false,
}}
>
{readOnly ? (
trigger
) : (
<Popover open={open} onOpenChange={setOpenState}>
<PopoverTrigger asChild>{trigger}</PopoverTrigger>
<PopoverContent className="w-auto p-0">
<Calendar
defaultMonth={selectedDate}
selected={selectedDate}
onSelect={(date) => {
if (!date) return;
editor.update.nodes.set(
{ value: formatDateValue(date) },
{ at: element }
);
}}
mode="single"
autoFocus
/>
</PopoverContent>
</Popover>
)}
{props.children}
</EditorElement>
);
}
export const DateKit = [DatePlugin.configure({ component: DateElement })];
'use client';
 
import { cn } from 'cn';
import { formatDateValue, parseCanonicalDateValue } from 'platejs/date';
import { DatePlugin } from 'platejs/date/react';
import {
  type EditorElementProps,
  EditorElement,
  useEditorReadOnly,
} from 'platejs/react';
import * as React from 'react';
 
import { Calendar } from '@/components/ui/calendar';
import {
  Popover,
  PopoverContent,
  PopoverTrigger,
} from '@/components/ui/popover';
import { inlineSuggestionVariants } from '@/lib/inline-suggestion';
 
const DAY_MS = 86_400_000;
const RELATIVE_DAYS: Partial<Record<number, string>> = {
  [-1]: 'Yesterday',
  0: 'Today',
  1: 'Tomorrow',
};
const dateFormat = new Intl.DateTimeFormat('en-US', {
  dateStyle: 'long',
  timeZone: 'UTC',
});
 
const getDateLabel = (value: string) => {
  if (!parseCanonicalDateValue(value)) return value;
 
  const day = Date.parse(value);
  const today = Date.parse(formatDateValue(new Date()));
 
  return RELATIVE_DAYS[(day - today) / DAY_MS] ?? dateFormat.format(day);
};
 
export function DateElement(props: EditorElementProps<typeof DatePlugin>) {
  const { editor, element } = props;
  const readOnly = useEditorReadOnly();
  const openRef = React.useRef(false);
  const openAtPointerDownRef = React.useRef(false);
  const [open, setOpen] = React.useState(false);
  const selectedDate = parseCanonicalDateValue(element.value);
  const setOpenState = React.useCallback((nextOpen: boolean) => {
    openRef.current = nextOpen;
    setOpen(nextOpen);
  }, []);
 
  const trigger = (
    <button
      className={cn(
        'w-fit cursor-pointer rounded-sm bg-muted px-1 text-muted-foreground',
        inlineSuggestionVariants({ on: 'parent' })
      )}
      contentEditable={false}
      draggable
      onClick={(event) => {
        const beganOpen =
          event.detail === 0 ? openRef.current : openAtPointerDownRef.current;
 
        if (readOnly || beganOpen) return;
 
        event.preventDefault();
        setOpenState(true);
      }}
      onPointerDown={() => {
        openAtPointerDownRef.current = openRef.current;
      }}
      type="button"
    >
      {getDateLabel(element.value)}
    </button>
  );
 
  return (
    <EditorElement
      {...props}
      className="inline-block"
      attributes={{
        ...props.attributes,
        contentEditable: false,
      }}
    >
      {readOnly ? (
        trigger
      ) : (
        <Popover open={open} onOpenChange={setOpenState}>
          <PopoverTrigger asChild>{trigger}</PopoverTrigger>
          <PopoverContent className="w-auto p-0">
            <Calendar
              defaultMonth={selectedDate}
              selected={selectedDate}
              onSelect={(date) => {
                if (!date) return;
 
                editor.update.nodes.set(
                  { value: formatDateValue(date) },
                  { at: element }
                );
              }}
              mode="single"
              autoFocus
            />
          </PopoverContent>
        </Popover>
      )}
      {props.children}
    </EditorElement>
  );
}
 
export const DateKit = [DatePlugin.configure({ component: DateElement })];
import
{ PLUGINS }
from
'platejs'
;
export const insertInlineMap = {
[PLUGINS.date]: (editor) =>
editor.plugin(BaseDatePlugin).update.insert({}, { select: true }),
};
function
DateElementStatic
(
props: EditorElementProps<typeof BaseDatePlugin>
) {
const { element } = props;
return (
<EditorElement as="span" className="inline-block" {...props}>
<span className="w-fit rounded-sm bg-muted px-1 text-muted-foreground">
{getDateLabel(element.value)}
</span>
{props.children}
</EditorElement>
);
}
export const BaseDateKit = [
BaseDatePlugin.configure({ component: DateElementStatic }),
];
import { BaseDatePlugin, parseCanonicalDateValue } from 'platejs/date';
import { type EditorElementProps, EditorElement } from 'platejs/static';
import * as React from 'react';
 
const dateFormat = new Intl.DateTimeFormat('en-US', {
  dateStyle: 'long',
  timeZone: 'UTC',
});
 
const getDateLabel = (value: string) =>
  parseCanonicalDateValue(value) ? dateFormat.format(Date.parse(value)) : value;
 
export function DateElementStatic(
  props: EditorElementProps<typeof BaseDatePlugin>
) {
  const { element } = props;
 
  return (
    <EditorElement as="span" className="inline-block" {...props}>
      <span className="w-fit rounded-sm bg-muted px-1 text-muted-foreground">
        {getDateLabel(element.value)}
      </span>
      {props.children}
    </EditorElement>
  );
}
 
export const BaseDateKit = [
  BaseDatePlugin.configure({ component: DateElementStatic }),
];