what-works-global

heading field

by what-works-global
payload-packages
Custom fields
v3
>=3.30.0 <4

Overview

Summary generated from the README

Provides a headingField() helper that wraps an existing text, textarea, or richText field in a group that also stores the selected heading tag. The admin shows a compact tag dropdown beside the field label. It is not a registered plugin, so you wrap the field in your config and regenerate the import map. A RenderHeading component is included for rendering the chosen tag on the front end. Requires Payload 3.30 or later.

Features

  • Wraps text, textarea, or richText fields and stores the chosen tag alongside the value
  • Inline tag dropdown beside the label with a configurable tooltip
  • Configurable list of allowed tags and a default tag
  • Hooks coerce legacy values into the new tag and value shape so existing documents still load
  • normalizeHeadingValue helper for eager migration of stored content
  • RenderHeading component for React Server Components with ref and attribute forwarding

Use cases

  • Let editors control the page heading outline without code changes
  • Add heading level selection to existing text or rich text heading fields
  • Render headings on the front end using the tag chosen in the admin

From the author

Payload field that lets content editors pick the rendered heading tag (h1–h6) for any text, textarea, or rich text heading.

Installation

npm i @whatworks/payload-heading-field

16

Stars

1

Forks

2

Open Issues

3 days ago

Last Updated

177

Weekly Downloads

v2.1.1

npm Version

77.7 KB

Unpacked Size

0

Dependencies

Repository stars

16+1 since Sep 6

Show data
Repository stars by day (UTC)
DateStars
Dec 5, 202616
Dec 4, 202616
Dec 3, 202616
Dec 2, 202616
Dec 1, 202616
Nov 30, 202616
Nov 29, 202616
Nov 28, 202616
Nov 27, 202616
Nov 26, 202616
Nov 25, 202616
Nov 24, 202616
Nov 23, 202616
Nov 22, 202616
Nov 21, 202616
Nov 20, 202616
Nov 19, 202616
Nov 18, 202616
Nov 17, 202615
Nov 16, 202615
Nov 15, 202615
Nov 14, 202615
Nov 13, 202615
Nov 12, 202615
Nov 11, 202615
Nov 10, 202615
Nov 9, 202615
Nov 8, 202615
Nov 7, 202615
Nov 6, 202615
Nov 5, 202615
Nov 4, 202615
Nov 3, 202615
Nov 2, 202615
Nov 1, 202615
Oct 31, 202615
Oct 30, 202615
Oct 29, 202615
Oct 28, 202615
Oct 27, 202615
Oct 26, 202615
Oct 25, 202615
Oct 24, 202615
Oct 23, 202615
Oct 22, 202615
Oct 21, 202615
Oct 20, 202615
Oct 19, 202615
Oct 18, 202615
Oct 17, 202615
Oct 16, 202615
Oct 15, 202615
Oct 14, 202615
Oct 13, 202615
Oct 12, 202615
Oct 11, 202615
Oct 10, 202615
Oct 9, 202615
Oct 8, 202615
Oct 7, 202615
Oct 6, 202615
Oct 5, 202615
Oct 4, 202615
Oct 3, 202615
Oct 2, 202615
Oct 1, 202615
Sep 30, 202615
Sep 29, 202615
Sep 28, 202615
Sep 27, 202615
Sep 26, 202615
Sep 25, 202615
Sep 24, 202615
Sep 23, 202615
Sep 22, 202615
Sep 21, 202615
Sep 20, 202615
Sep 19, 202615
Sep 18, 202615
Sep 17, 202615
Sep 16, 202615
Sep 15, 202615
Sep 14, 202615
Sep 13, 202615
Sep 12, 202615
Sep 11, 202615
Sep 10, 202615
Sep 9, 202615
Sep 8, 202615
Sep 7, 202615
Sep 6, 202615

Shared by 12 plugins in what-works-global/payload-packages.

npm weekly downloads

168+157 since Sep 6

Show data
npm weekly downloads by day (UTC)
DateWeekly downloads
Dec 5, 2026168
Dec 4, 2026200
Dec 3, 2026147
Dec 2, 2026120
Dec 1, 2026126
Nov 30, 2026124
Nov 29, 202697
Nov 28, 202689
Nov 27, 202652
Nov 26, 202619
Nov 25, 202625
Nov 24, 202619
Nov 23, 202622
Nov 22, 202629
Nov 21, 202632
Nov 20, 202632
Nov 19, 202626
Nov 18, 202621
Nov 17, 202621
Nov 16, 202619
Nov 15, 202626
Nov 14, 202646
Nov 13, 202653
Nov 12, 202676
Nov 11, 2026100
Nov 10, 2026134
Nov 9, 2026133
Nov 8, 2026123
Nov 7, 2026103
Nov 6, 2026103
Nov 5, 202681
Nov 4, 202674
Nov 3, 202640
Nov 2, 202642
Nov 1, 202638
Oct 31, 202635
Oct 30, 202625
Oct 29, 202624
Oct 28, 20264
Oct 27, 20264
Oct 26, 20263
Oct 25, 20266
Oct 24, 20267
Oct 23, 20265
Oct 22, 202612
Oct 21, 202612
Oct 20, 202612
Oct 19, 202611
Oct 18, 202618
Oct 17, 202652
Oct 16, 202653
Oct 15, 202646
Oct 14, 202646
Oct 13, 202646
Oct 12, 202650
Oct 11, 202665
Oct 10, 202635
Oct 9, 202644
Oct 8, 202644
Oct 7, 202644
Oct 6, 202648
Oct 5, 202644
Oct 4, 202620
Oct 3, 202616
Oct 2, 20267
Oct 1, 20267
Sep 30, 20268
Sep 29, 20264
Sep 28, 20264
Sep 27, 20263
Sep 26, 20269
Sep 25, 20269
Sep 24, 202612
Sep 23, 202612
Sep 22, 202613
Sep 21, 202621
Sep 20, 202622
Sep 19, 202619
Sep 18, 202619
Sep 17, 202616
Sep 16, 202617
Sep 15, 202616
Sep 14, 20268
Sep 13, 20267
Sep 12, 20265
Sep 11, 20265
Sep 10, 20265
Sep 9, 20263
Sep 8, 20265
Sep 7, 20267
Sep 6, 202611

Each point is npm's rolling 7-day download count.

Health Score

62/100Good

Composite score based on GitHub activity, stars, npm downloads, publish recency, dependency count, and package size.

Badge for your README

Payload Directory health badge
Markdown
[![Payload Directory](https://payloaddirectory.dev/badge/1064440892-heading-field.svg)](https://payloaddirectory.dev/plugins/1064440892-heading-field)
HTML
<a href="https://payloaddirectory.dev/plugins/1064440892-heading-field"><img src="https://payloaddirectory.dev/badge/1064440892-heading-field.svg" alt="Payload Directory"></a>
Updated Dec 2, 2026Created Sep 26, 2025Published Jun 30, 2026

README

Payload Heading Field

Payload Heading Field

 

Let content editors choose the rendered heading tag (h1–h6) for any heading, without leaving the field they're already editing. headingField() wraps a text, textarea, or richText field in a group that also stores the chosen tag, and renders it as a single, normal-looking field with a compact tag dropdown sitting inline beside the field label.

Demo

Editors pick the heading level inline, right where they write the heading — and the front end renders the tag they chose.

In the Payload admin, every heading field gets a compact HTML Tag dropdown beside its label. It works the same for text, textarea, and richText:

Three heading fields in the Payload admin — Page heading, Sub heading, and Rich heading — each with an inline HTML Tag dropdown set to H1, H2, and H3.

On the front end, render the stored value through <RenderHeading>:

import { RenderHeading } from '@whatworks/payload-heading-field/rsc'

export default async function Page() {
  const page = await getPage()

  return (
    <>
      <RenderHeading data={page.heading} /> {/* editor picked H1 → <h1> */}
      <RenderHeading data={page.subheading} /> {/* editor picked H2 → <h2> */}
      <RenderHeading data={page.richHeading} render={(value) => <RichText data={value} />} />
    </>
  )
}

What renders — the emitted element matches the tag the editor chose, so the page outline is theirs to control without touching code:

The rendered front end — “Welcome to Northwind” as an h1, “Tools that get out of your way” as an h2, and “Trusted by teams everywhere” as an h3, each labelled with its emitted tag.

Contents

Installation

pnpm add @whatworks/payload-heading-field

The custom field component is referenced by string path, so run your import map generation after adding a heading field:

payload generate:importmap

Usage

Wrap an existing field object in headingField() — that's the whole change. The field is the first argument, so adopting it in an existing codebase is a one-line edit:

import { buildConfig } from 'payload'
import { lexicalEditor } from '@payloadcms/richtext-lexical'
import { headingField } from '@whatworks/payload-heading-field'

export default buildConfig({
  collections: [
    {
      slug: 'pages',
      fields: [
        // Just wrap the field — defaults to tags ['h1'–'h5'], default 'h2'.
        headingField({
          name: 'heading',
          type: 'text',
          label: 'Page heading',
          required: true,
        }),

        // Pass a second argument only when you want to override the defaults.
        // Works with textarea and richText values too.
        headingField(
          {
            name: 'intro',
            type: 'richText',
            editor: lexicalEditor(),
          },
          { tags: ['h2', 'h3', 'h4'], defaultTag: 'h3' },
        ),
      ],
    },
  ],
})

There is no plugin to register — headingField() returns a normal Payload field.

Arguments

headingField(field, config?)

field (required, first argument)

The field that captures the heading's value. Must be a named TextField, TextareaField, or RichTextField. Pass your existing field object here — that is the only change needed to adopt it. Its label drives the rendered field label; its value is stored under <name>.value.

config (optional, second argument)

KeyTypeDefaultNotes
tags('h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6')[]['h1', 'h2', 'h3', 'h4', 'h5']Tags offered in the inline dropdown, in display order.
defaultTagsame union as above'h2'Pre-selected tag for new documents. Must be in tags.
tooltipstringcontent-editor explainerText for the “(?)” tooltip beside the label. Overrides the built-in.

headingField() throws if defaultTag is not included in tags, or if any tag is outside h1–h6.

Customising the label

The header (the label plus the tag dropdown) is rendered by a custom Label component, so set one on the field exactly as you would for any Payload field — headingField() lifts it up to the group so it renders in the header:

headingField({
  name: 'heading',
  type: 'text',
  admin: {
    components: {
      Label: './components/HeadingLabel#HeadingLabel',
    },
  },
})

A custom Label replaces the entire header, so it owns the layout. Two building blocks are exported so you can reconstruct it however you like:

  • HeadingTagSelect — the tag dropdown.
  • HeadingTagTooltip — the muted “— HTML Tag (?)” indicator (styled like Payload's localized-field indicator) with a simple CSS tooltip on the “(?)”.

Inside a heading field both need no props — HeadingTagSelect reads the path, tags and read-only state from context:

'use client'

import { HeadingTagSelect, HeadingTagTooltip } from '@whatworks/payload-heading-field/client'

export function HeadingLabel({ label }: { label: string }) {
  return (
    <div style={{ alignItems: 'center', display: 'flex', gap: '0.5rem' }}>
      <span>{label}</span>
      <HeadingTagTooltip tooltip="Pick the heading level for SEO and outline." />
      <HeadingTagSelect />
    </div>
  )
}

Other slots (Description, BeforeInput, AfterInput, a custom value Field) stay with the value field and render around the input as usual. Omitting the Label keeps the built-in header (label + tooltip + dropdown).

HeadingTagTooltip accepts label, tooltip, and hideSeparator props; HeadingTagSelect accepts explicit path and tags props for use outside a heading field.

Because the label is resolved at the group's path, a custom Label receives the group's props — not the value field's. If you need the value field's required or localized (e.g. to render the required asterisk), set them directly in your custom component; the built-in fallback handles them for you.

Stored shape

The field is stored as a group named after field.name:

{
  "heading": {
    "tag": "h2",
    "value": "Welcome", // string for text/textarea, Lexical state for richText
  },
}

Backwards compatibility

headingField() is a drop-in replacement for a plain text, textarea, or richText field. Wrapping an existing field changes its stored shape — the raw value moves from field.name down to field.name.value — but documents saved before the wrap keep loading without error or data loss.

// Before
{ name: 'richHeading', type: 'richText', editor: lexicalEditor() }

// After — wrap the same field object; existing `richHeading` documents still load fine
headingField({ name: 'richHeading', type: 'richText', editor: lexicalEditor() })

The generated group carries afterRead and beforeValidate hooks that coerce a legacy value (a bare string, or a Lexical editor state like { root }) into { tag, value }, using the configured defaultTag. Reads return the canonical shape, and saving a migrated document persists it — so the migration happens lazily, document by document, as content is edited. Values already in { tag, value } shape are never re-wrapped.

To migrate eagerly instead of waiting for edits, the same coercion is exported as normalizeHeadingValue(value, defaultTag) for use in a script or Payload migration:

import { normalizeHeadingValue } from '@whatworks/payload-heading-field'

const { docs } = await payload.find({ collection: 'pages', limit: 0 })

for (const doc of docs) {
  await payload.update({
    collection: 'pages',
    id: doc.id,
    data: { richHeading: normalizeHeadingValue(doc.richHeading, 'h2') },
  })
}

Rendering on the front end

A small, framework-agnostic RenderHeading component is provided from the /rsc entry point (safe to use in React Server Components). It renders the chosen tag, spreads any extra HTML attributes (className, id, style, …) onto it, forwards a ref to the emitted heading element, and renders nothing when there is no resolvable content — so you never ship an empty heading. It handles plain string values out of the box; for rich text, supply a converter via render or pre-rendered nodes via children.

The forwarded ref is handy when a client component needs to measure or animate the heading (e.g. a fit-to-width font-size hook). It is not attached when the component renders nothing.

'use client'
const ref = useRef<HTMLHeadingElement>(null)
;<RenderHeading data={page.heading} ref={ref} />

It's deliberately named RenderHeading, not Heading, so the short name stays free for your own component — most apps wrap it (see below) and call the wrapper Heading.

This component is an intentionally minimal starting point — rich text converters are app-specific, so the wiring is left to you.

import { RenderHeading } from '@whatworks/payload-heading-field/rsc'

// text / textarea
;<RenderHeading data={page.heading} className="display" />

// richText (bring your own Lexical → JSX converter)
;<RenderHeading data={page.intro} render={(value) => <RichText data={value} />} />

It accepts Payload's generated types directly — data is a nullable partial, so an optional, nullable value (or a whole optional group) on a non-required field is fine; null/missing tag and value are handled for you. It is also generic over the value type, so the render argument is typed from data with no cast.

Wrapping RenderHeading

Most apps have a single Lexical → JSX converter, so rather than passing render at every call site, wrap RenderHeading once to inject it. Type the wrapper to the value it renders and the render argument is fully typed. Since the library export is RenderHeading, you're free to call your wrapper Heading:

import { RenderHeading, type RenderHeadingProps } from '@whatworks/payload-heading-field/rsc'
import type { SerializedEditorState } from '@payloadcms/richtext-lexical/lexical'

import { RichText } from '@/components/RichText'

export function Heading(props: RenderHeadingProps<SerializedEditorState>) {
  // `value` is SerializedEditorState here — no cast. Callers can still override
  // `render`/`children`, and `data`, `className`, etc. forward through.
  return <RenderHeading render={(value) => <RichText data={value} />} {...props} />
}

Because render only runs once data is present, the converter never has to guard against a missing value. Plain string headings need no wrapper — use RenderHeading directly.

Notes

  • The group is always rendered through a custom Field component, so it never appears as a default Payload group in the admin UI.
  • The tag sub-field is required and always carries a default, so it is never empty.
  • Use headingFieldMatches(field) and getHeadingTags(field) (exported from the package root) if you need to detect or introspect heading fields elsewhere.

Similar plugins