VeiaG

payload cmdk

by VeiaG
Admin customization
v3
^3.37.0

Overview

Summary generated from the README

Adds a command menu to the Payload admin panel, opened with a customizable keyboard shortcut or a search button. It lists collections and globals the user can access, supports searching documents within a collection, and can show live results from your own search endpoint. Custom items can link, call APIs or run client-side handlers. Requires Payload 3.37 or later.

Features

  • Configurable shortcut, defaulting to Cmd+K or Ctrl+K, plus a search button in the actions area or nav
  • Collection submenu that searches documents by their title field
  • Live document search from a custom endpoint with debounce, caching and highlighting
  • Custom items and groups with link, API and client function actions
  • Menu respects read access and admin.hidden; custom items take a server-side access check
  • Lucide icons, custom client filter, and built-in English and Ukrainian translations

Use cases

  • Jump to any collection, global or document in the admin without using the sidebar
  • Add quick actions such as clearing a cache or saving the current document from the keyboard
  • Search people or records across several collections through a custom search endpoint

From the author

A command menu plugin for Payload CMS to enhance navigation and accessibility within the admin panel.

Installation

npm i @veiag/payload-cmdk

32

Stars

7

Forks

0

Open Issues

3 weeks ago

Last Updated

478

Weekly Downloads

v1.3.0

npm Version

263.1 KB

Unpacked Size

4

Dependencies

GitHub stars

32+2 since Sep 6

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

452−138 since Sep 6

Show data
npm weekly downloads by day (UTC)
DateWeekly downloads
Dec 5, 2026452
Dec 4, 2026376
Dec 3, 2026335
Dec 2, 2026295
Dec 1, 2026289
Nov 30, 2026281
Nov 29, 2026273
Nov 28, 2026322
Nov 27, 2026366
Nov 26, 2026427
Nov 25, 2026468
Nov 24, 2026473
Nov 23, 2026490
Nov 22, 2026529
Nov 21, 2026528
Nov 20, 2026519
Nov 19, 2026651
Nov 18, 2026700
Nov 17, 2026699
Nov 16, 2026698
Nov 15, 2026672
Nov 14, 2026707
Nov 13, 2026751
Nov 12, 2026612
Nov 11, 2026566
Nov 10, 2026614
Nov 9, 2026602
Nov 8, 2026611
Nov 7, 2026548
Nov 6, 2026450
Nov 5, 2026396
Nov 4, 2026379
Nov 3, 2026337
Nov 2, 2026334
Nov 1, 2026343
Oct 31, 2026376
Oct 30, 2026452
Oct 29, 2026395
Oct 28, 2026322
Oct 27, 2026333
Oct 26, 2026363
Oct 25, 2026367
Oct 24, 2026429
Oct 23, 2026332
Oct 22, 2026503
Oct 21, 2026590
Oct 20, 2026574
Oct 19, 2026590
Oct 18, 2026626
Oct 17, 2026518
Oct 16, 2026568
Oct 15, 2026470
Oct 14, 2026508
Oct 13, 2026539
Oct 12, 2026493
Oct 11, 2026456
Oct 10, 2026480
Oct 9, 2026501
Oct 8, 2026518
Oct 7, 2026576
Oct 6, 2026570
Oct 5, 2026564
Oct 4, 2026537
Oct 3, 2026540
Oct 2, 2026535
Oct 1, 2026504
Sep 30, 2026383
Sep 29, 2026364
Sep 28, 2026388
Sep 27, 2026441
Sep 26, 2026416
Sep 25, 2026457
Sep 24, 2026447
Sep 23, 2026455
Sep 22, 2026460
Sep 21, 2026453
Sep 20, 2026433
Sep 19, 2026446
Sep 18, 2026402
Sep 17, 2026382
Sep 16, 2026365
Sep 15, 2026369
Sep 14, 2026463
Sep 13, 2026436
Sep 12, 2026426
Sep 11, 2026451
Sep 10, 2026524
Sep 9, 2026609
Sep 8, 2026622
Sep 7, 2026563
Sep 6, 2026590

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

Health Score

74/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/1111197152-root.svg)](https://payloaddirectory.dev/plugins/1111197152-root)
HTML
<a href="https://payloaddirectory.dev/plugins/1111197152-root"><img src="https://payloaddirectory.dev/badge/1111197152-root.svg" alt="Payload Directory"></a>
Updated Nov 10, 2026Created Dec 6, 2025Published Nov 10, 2026

README

Payload CMDK

A powerful command menu plugin for Payload CMS that enhances navigation and accessibility within the admin panel. Quickly search and navigate through collections, globals, and custom actions using keyboard shortcuts.

Demo of opening command menu, searching for a collection, and navigating

Features

✨ Quick Search - Instantly search across all collections and globals

⌨️ Keyboard Shortcuts - Fully customizable keyboard shortcuts powered by react-hotkeys-hook

🔍 Collection Submenu - Search within collection documents by their title field

📄 Live Document Search - Show documents from your own search endpoint while typing, above or below the menu

🎨 Custom Icons - Use any Lucide icon for collections and globals

🎯 Custom Items - Add custom actions and menu groups

🔒 Access Control - The menu shows only what a user may open, and custom items can guard themselves

🌍 i18n Support - Built-in English and Ukrainian translations, easily add your own

🖥️ Cross-platform - Optimized shortcuts for both macOS and Windows/Linux

Installation

npm install @veiag/payload-cmdk
# or
yarn add @veiag/payload-cmdk
# or
pnpm add @veiag/payload-cmdk

Quick Start

The plugin works out of the box with minimal configuration:

import { payloadCmdk } from '@veiag/payload-cmdk'
import { buildConfig } from 'payload'

export default buildConfig({
  // ... your config
  plugins: [
    payloadCmdk({
      // Plugin works without any options!
    }),
  ],
})

This will:

  • Add a search button to the admin panel
  • Enable ⌘K (Mac) / Ctrl+K (Windows/Linux) keyboard shortcut
  • List all collections and globals in the command menu
  • Enable collection submenu search

Configuration

Full Configuration Example

import { payloadCmdk } from '@veiag/payload-cmdk'
import { buildConfig } from 'payload'

export default buildConfig({
  plugins: [
    payloadCmdk({
      // Keyboard shortcut to open the menu
      shortcut: ['meta+k', 'ctrl+k'], // Default

      // Search button configuration
      searchButton: {
        position: 'actions', // 'actions' | 'nav'
      },

      // Backdrop blur effect
      blurBg: true, // Default

      // Collection submenu configuration
      submenu: {
        enabled: true, // Default
        shortcut: 'shift+enter', // 'shift+enter' | 'enter'
        icons: {
          posts: 'FileText',
          users: 'User',
        },
      },

      // Custom icons for collections and globals
      icons: {
        collections: {
          posts: 'FileText',
          pages: 'File',
          media: 'Image',
          users: 'Users',
        },
        globals: {
          settings: 'Settings',
          navigation: 'Menu',
        },
      },

      // Collections/globals to ignore
      slugsToIgnore: ['payload-migrations', 'payload-preferences'],

      // Custom menu items
      customItems: [
        {
          type: 'group',
          title: 'Quick Actions',
          items: [
            {
              type: 'item',
              slug: 'view-site',
              label: 'View Site',
              icon: 'ExternalLink',
              action: {
                type: 'link',
                href: 'https://your-site.com',
              },
            },
            {
              type: 'item',
              slug: 'clear-cache',
              label: 'Clear Cache',
              icon: 'Trash2',
              action: {
                type: 'api',
                method: 'POST',
                href: '/api/cache/clear',
              },
            },
          ],
        },
      ],

      // Disable the plugin
      disabled: false, // Default
    }),
  ],
})

Configuration Options

shortcut

Keyboard shortcut to open the command menu. Powered by react-hotkeys-hook.

  • Type: string | string[]
  • Default: ['meta+k', 'ctrl+k']

The default provides cross-platform support:

  • meta+k - Works on macOS (⌘K)
  • ctrl+k - Works on Windows/Linux (Ctrl+K)

Examples:

// Single shortcut
shortcut: 'ctrl+shift+k'

// Multiple shortcuts for cross-platform support
shortcut: ['meta+k', 'ctrl+k']

// Custom combinations
shortcut: ['meta+/', 'ctrl+/']

searchButton

Configuration for the search button displayed in the admin panel.

  • Type: { position?: 'actions' | 'nav' } | false
  • Default: { position: 'actions' }

Options:

  • position: 'actions' - Display in the action buttons area (default)
  • position: 'nav' - Display in the navigation sidebar
  • false - Hide the search button completely (keyboard shortcut still works)

Examples:

// Display in navigation
searchButton: {
  position: 'nav'
}

// Hide search button
searchButton: false

Actions button position:

Actions button

Navigation button position:

Navigation button

blurBg

Enable backdrop blur effect when the command menu is open.

  • Type: boolean
  • Default: true
blurBg: false // Disable blur effect

submenu

Configure submenu behavior for searching within collection documents.

  • Type: object
  • Default: { enabled: true, shortcut: 'shift+enter' }

Options:

PropertyTypeDefaultDescription
enabledbooleantrueEnable/disable submenu functionality
shortcut'shift+enter' | 'enter''shift+enter'Keyboard shortcut to open submenu
iconsobjectundefinedCustom icons for collection submenus

Shortcut behavior:

  • shift+enter: Shift+Enter opens submenu, Enter navigates to collection list
  • enter: Enter opens submenu, Shift+Enter navigates to collection list

Searching within a collection submenu

Example:

submenu: {
  enabled: true,
  shortcut: 'enter',
  icons: {
    posts: 'FileText',
    products: 'ShoppingCart',
  }
}

The submenu searches documents by their useAsTitle field (or id if not specified). You can configure this in your collection:

{
  slug: 'posts',
  admin: {
    useAsTitle: 'title' // Submenu will search by this field
  }
}

documentSearch

Show live documents from your own search endpoint on the main page while the user types, e.g. people by name, email or phone number across several collections. Off unless configured.

  • Type: DocumentSearchConfig
  • Default: undefined
documentSearch: {
  endpoint: '/api/cmdk-search', // required
  minLength: 2,                 // don't search shorter queries (default: 2)
  debounceMs: 60,               // wait after the last keystroke (default: 60)
  position: 'after',            // 'before' (default) or 'after' the menu entries
  toggle: true,                 // footer checkbox to turn the results off (default: false)
}

The menu calls GET <endpoint>?q=<query> with the user's cookies and expects a DocumentSearchResponse:

type DocumentSearchResponse = {
  query: string
  groups: {
    slug: string
    title: string    // group heading
    icon: string     // Lucide icon name
    items: {
      id: string           // unique across all groups, e.g. 'posts:123'
      label: string
      href: string         // where Enter takes the user
      description?: string // second line, e.g. an email address
      badge?: string       // small tag on the right, e.g. 'Draft'
    }[]
  }[]
  moreHref?: string  // optional "Show all results" link, e.g. to a search page
}

It also calls the endpoint once with an empty q when the menu opens, to warm it up; answer that with no groups. The types are exported from @veiag/payload-cmdk.

A minimal endpoint that searches posts by title, with the user's own access:

import type { Endpoint } from 'payload'
import type { DocumentSearchResponse } from '@veiag/payload-cmdk'

export const cmdkSearch: Endpoint = {
  path: '/cmdk-search',
  method: 'get',
  handler: async (req) => {
    const query = typeof req.query?.q === 'string' ? req.query.q.trim() : ''
    if (!req.user || query.length < 2) {
      return Response.json({ query, groups: [] } satisfies DocumentSearchResponse)
    }
    const { docs } = await req.payload.find({
      collection: 'posts',
      where: { title: { like: query } },
      limit: 5,
      depth: 0,
      overrideAccess: false,
      req,
    })
    return Response.json({
      query,
      groups: docs.length
        ? [{
            slug: 'posts',
            title: 'Posts',
            icon: 'Newspaper',
            items: docs.map((doc) => ({
              id: `posts:${doc.id}`,
              label: doc.title,
              href: `/admin/collections/posts/${doc.id}`,
            })),
          }]
        : [],
    } satisfies DocumentSearchResponse)
  },
}

Register it in endpoints of your Payload config. Results are cached per query for 30 seconds in the browser, matching words are highlighted, and Cmd/Ctrl+Enter opens a result in a new tab.

With position: 'before' the results show above the menu entries. With position: 'after' the menu entries (collections, globals, custom items) keep the top places, which suits users who mostly navigate with the menu; a query that matches no menu entry still highlights the first result, so Enter opens it.

With toggle: true the footer gets a "Show documents" checkbox (translation key showDocuments). Unticked, the menu neither fetches nor shows results, so it only searches the menu. The choice is saved per user as the Payload preference payload-cmdk-document-search ({ enabled: boolean }), and results are on until the user unticks it.

icons

Customize icons for collections and globals using Lucide icon names.

  • Type: object
  • Default: { collections: {}, globals: {} }

Default icons:

  • Collections: Files icon
  • Globals: Globe icon

Example:

icons: {
  collections: {
    posts: 'FileText',
    pages: 'File',
    media: 'Image',
    users: 'Users',
    categories: 'Folder',
  },
  globals: {
    settings: 'Settings',
    navigation: 'Menu',
    footer: 'Layout',
  }
}

Browse all available icons at lucide.dev/icons.

Icons preview

customItems

Add custom menu items and groups to the command menu.

  • Type: Array<CustomMenuItem | CustomMenuGroup>
  • Default: []
Custom Menu Item
{
  type: 'item',
  slug: 'unique-slug',           // Must be unique across all items
  label: 'Item Label',           // Can be a localized object — see Localization below
  icon: 'LucideIconName',        // Optional, from lucide.dev/icons
  collectionSlugs: ['posts'],    // Optional — only show on these collection pages
  collectionContext: ['list'],   // Optional — 'list', 'document', or both
  access: ({ req }) => true,     // Optional — server-side check, see Access Control below
  action: { ... }                // See Action Types below
}
Custom Menu Group

Groups are rendered with a heading and can contain multiple items. Groups with identical titles are automatically merged.

{
  type: 'group',
  title: 'Group Title',          // Can be a localized object
  collectionSlugs: ['posts'],    // Optional — only show on these collection pages
  collectionContext: ['list'],   // Optional
  access: ({ req }) => true,     // Optional — server-side check, see Access Control below
  items: [
    // Array of CustomMenuItem
  ]
}

Access Control

The menu never offers a user something they cannot open.

Collections and globals are filtered the same way Payload filters its own navigation: a collection appears only if the user passes its read access and it is not excluded by admin.hidden. Nothing needs configuring for this.

Custom items and groups answer for themselves through an optional access function:

customItems: [
  {
    type: 'item',
    slug: 'purge-cache',
    label: 'Purge Cache',
    access: ({ req }) => req.user?.role === 'admin',
    action: { type: 'api', href: '/api/cache/purge', method: 'POST' },
  },
]

The function receives the item itself and a req carrying the current user, so it can reach the Local API:

access: async ({ req }) => {
  const { totalDocs } = await req.payload.count({
    collection: 'invoices',
    where: { owner: { equals: req.user?.id } },
  })
  return totalDocs > 0
}

Three things are worth knowing: Denial is the safe answer. If the function throws, the item is dropped. A denied group takes its items with it, whatever their own access says. An allowed group still filters each item, and a group left with no items is dropped.


Action Types

Every item requires an action that determines what happens when the item is selected.

Navigates to a URL. Supports both internal paths and external URLs.

action: {
  type: 'link',
  href: '/admin/collections/posts', // or 'https://your-site.com'
}
api — Call an API endpoint

Makes an HTTP request when the item is selected. The menu closes after the request completes (or fails).

action: {
  type: 'api',
  href: '/api/cache/clear',
  method: 'POST',              // 'GET' | 'POST' | 'PUT' | 'DELETE' — default: 'GET'
  body: { scope: 'all' },      // Optional JSON body
}
function — Call a client-side handler

Because the plugin config is serialized across the Next.js server→client boundary, a handler that runs in the browser cannot live directly in payload.config.ts. Instead, you reference a handler by a string key in the config and register the actual function on the client. (The access functions above are the exception: they never cross that boundary, because they run on the server.)

Step 1 — reference the key in your config:

// payload.config.ts
customItems: [
  {
    type: 'item',
    slug: 'save-document',
    label: 'Save Document',
    icon: 'Save',
    collectionContext: ['document'],
    action: {
      type: 'function',
      key: 'save-current-doc',   // Must match the key used in registerCommandMenuAction
    },
  },
]

Step 2 — register the handler in a client component:

// e.g. app/(payload)/layout.tsx  or  a custom admin component
'use client'
import { registerCommandMenuAction, unregisterCommandMenuAction } from '@veiag/payload-cmdk/client'
import { useEffect } from 'react'

export default function AdminLayout({ children }) {
  useEffect(() => {
    registerCommandMenuAction('save-current-doc', () => {
      // Submit the currently active form (Payload's save button)
      document.querySelector<HTMLButtonElement>('button[type="submit"]')?.click()
    })

    // Clean up when the component unmounts
    return () => unregisterCommandMenuAction('save-current-doc')
  }, [])

  return <>{children}</>
}

The handler can be synchronous or return a Promise. The menu always closes after it resolves (or throws).

Full example with multiple function actions:

// payload.config.ts
customItems: [
  {
    type: 'group',
    title: 'Document Actions',
    collectionContext: ['document'],
    items: [
      {
        type: 'item',
        slug: 'save-document',
        label: 'Save Document',
        icon: 'Save',
        action: { type: 'function', key: 'save-current-doc' },
      },
      {
        type: 'item',
        slug: 'copy-doc-link',
        label: 'Copy Document Link',
        icon: 'Link',
        action: { type: 'function', key: 'copy-doc-link' },
      },
    ],
  },
  {
    type: 'item',
    slug: 'import-posts',
    label: 'Import Posts',
    icon: 'Upload',
    collectionSlugs: ['posts'],
    collectionContext: ['list'],
    action: { type: 'function', key: 'import-posts' },
  },
]
// Client component / layout
'use client'
import { registerCommandMenuAction, unregisterCommandMenuAction } from '@veiag/payload-cmdk/client'
import { useEffect } from 'react'

export default function AdminLayout({ children }) {
  useEffect(() => {
    registerCommandMenuAction('save-current-doc', () => {
      document.querySelector<HTMLButtonElement>('button[type="submit"]')?.click()
    })

    registerCommandMenuAction('copy-doc-link', () => {
      navigator.clipboard.writeText(window.location.href)
    })

    registerCommandMenuAction('import-posts', async () => {
      await fetch('/api/posts/import', { method: 'POST' })
    })

    return () => {
      unregisterCommandMenuAction('save-current-doc')
      unregisterCommandMenuAction('copy-doc-link')
      unregisterCommandMenuAction('import-posts')
    }
  }, [])

  return <>{children}</>
}

Note: If a key is used in the config but no handler has been registered, the plugin logs a warning to the console and the menu still closes normally.


collectionSlugs — Restrict to specific collections

Show an item or group only when the user is viewing a particular collection.

{
  type: 'item',
  slug: 'export-posts',
  label: 'Export Posts',
  icon: 'Download',
  collectionSlugs: ['posts'],         // only visible on /admin/collections/posts/*
  action: { type: 'function', key: 'export-posts' },
}

Omit collectionSlugs (or pass an empty array) to show the item on all pages, including non-collection pages.


collectionContext — Restrict to list or document pages

Use collectionContext on any item or group to control exactly where inside a collection it appears.

  • Type: ('document' | 'list')[]
  • Default: not set (appears on all pages)
ValueWhere it appears
'list'Collection list page — e.g. /admin/collections/posts
'document'Document edit or create page — e.g. /admin/collections/posts/abc123 or /admin/collections/posts/create

Pass both values, or omit the field entirely, to show the item on all collection pages.

collectionContext can be combined with collectionSlugs to target a specific collection and a specific page context, or used alone to apply to all collections.

Examples:

customItems: [
  // Only on the posts list page
  {
    type: 'item',
    slug: 'import-posts',
    label: 'Import Posts',
    icon: 'Upload',
    collectionSlugs: ['posts'],
    collectionContext: ['list'],
    action: { type: 'function', key: 'import-posts' },
  },

  // Only when editing or creating a post
  {
    type: 'item',
    slug: 'save-post',
    label: 'Save Post',
    icon: 'Save',
    collectionSlugs: ['posts'],
    collectionContext: ['document'],
    action: { type: 'function', key: 'save-current-doc' },
  },

  // On any document edit/create page across all collections
  {
    type: 'item',
    slug: 'copy-link',
    label: 'Copy Document Link',
    icon: 'Link',
    collectionContext: ['document'],
    action: { type: 'function', key: 'copy-doc-link' },
  },

  // On both list and document pages (same as omitting collectionContext)
  {
    type: 'item',
    slug: 'help',
    label: 'Open Help',
    icon: 'HelpCircle',
    collectionSlugs: ['posts'],
    collectionContext: ['list', 'document'],
    action: { type: 'link', href: '/docs' },
  },
]

Example with localization:

customItems: [
  {
    type: 'group',
    title: {
      en: 'Quick Actions',
      uk: 'Швидкі дії',
    },
    items: [
      {
        type: 'item',
        slug: 'view-site',
        label: {
          en: 'View Site',
          uk: 'Переглянути сайт',
        },
        icon: 'ExternalLink',
        action: {
          type: 'link',
          href: 'https://your-site.com',
        },
      },
      {
        type: 'item',
        slug: 'regenerate',
        label: 'Regenerate Cache',
        icon: 'RefreshCw',
        action: {
          type: 'api',
          method: 'POST',
          href: '/api/cache/regenerate',
        },
      },
    ],
  },
]

slugsToIgnore

Specify which collection/global slugs to exclude from the command menu.

  • Type: CollectionSlug[] | { ignoreList: CollectionSlug[], replaceDefaults?: boolean }
  • Default: ['payload-migrations', 'payload-preferences', 'payload-locked-documents']

Examples:

// Add to default ignore list
slugsToIgnore: ['internal-collection', 'test-data']

// Replace default ignore list completely
slugsToIgnore: {
  ignoreList: ['my-hidden-collection'],
  replaceDefaults: true
}

disabled

Completely disable the plugin.

  • Type: boolean
  • Default: false
disabled: process.env.DISABLE_COMMAND_MENU === 'true'

Custom menu filter (registerCommandMenuFilter)

By default the menu uses cmdk's fuzzy filter. To match differently (for example without diacritics, or only on whole words), register your own filter on the client:

'use client'
import { registerCommandMenuFilter } from '@veiag/payload-cmdk/client'

const normalize = (text: string) =>
  text.normalize('NFD').replace(/[\u0300-\u036f]/g, '').toLowerCase()

registerCommandMenuFilter((value, search, keywords = []) => {
  const query = normalize(search)
  const candidates = [value, ...keywords].map(normalize)
  if (candidates.some((c) => c === query)) return 1
  if (candidates.some((c) => c.startsWith(query))) return 0.8
  if (candidates.some((c) => c.includes(query))) return 0.5
  return 0
})
  • value is the entry's slug.
  • keywords is [group title, label] for an entry in a group, [label] otherwise.
  • Return 0 to hide the entry. A higher score puts the entry, and its group, higher up.
  • Call registerCommandMenuFilter(undefined) to go back to the default filter.

Whichever filter is active, groups are ordered by their best-matching entry while you type, so an exact match in a later group shows above a weak match in an earlier one.

Custom Translations

The plugin includes built-in translations for:

  • 🇬🇧 English (en)
  • 🇺🇦 Ukrainian (uk)

You can add translations for other languages using Payload's i18n configuration:

import { buildConfig } from 'payload'

export default buildConfig({
  i18n: {
    supportedLanguages: {
      //You can learn more about adding languages in the Payload docs
      en,
      uk,
      de,
      fr,
    },
    translations: {
      de: {
        cmdkPlugin: {
          loading: 'Lädt...',
          navigate: 'zum Navigieren',
          noResults: 'Keine Ergebnisse gefunden',
          open: 'zum Öffnen',
          search: 'Sammlungen, Globals durchsuchen...',
          searchIn: 'Suchen in {{label}}',
          searchInCollection: 'in Sammlung suchen',
          searchShort: 'Suchen',
        },
      },
      fr: {
        cmdkPlugin: {
          loading: 'Chargement...',
          navigate: 'pour naviguer',
          noResults: 'Aucun résultat trouvé',
          open: 'pour ouvrir',
          search: 'Rechercher collections, globals...',
          searchIn: 'Rechercher dans {{label}}',
          searchInCollection: 'pour rechercher dans la collection',
          searchShort: 'Rechercher',
        },
      },
    },
  },
  plugins: [
    payloadCmdk({
      // Your config
    }),
  ],
})

Available Translation Keys

All translation keys are under the cmdkPlugin namespace:

KeyDescriptionExample (EN)
searchMain search placeholder"Search collections, globals..."
searchShortShort search label"Search"
searchInSubmenu search placeholder"Search in {{label}}"
loadingLoading state"Loading..."
noResultsNo results state"No results found"
navigateFooter hint for navigation"to navigate"
searchInCollectionFooter hint for collection search"to search in collection"
openFooter hint for opening documents"to open"
openInNewTabFooter hint for documentSearch results"to open in a new tab"
showAllResultsdocumentSearch link to all results"Show all results for “{{query}}”"
showDocumentsdocumentSearch.toggle checkbox label"Show documents"

Keyboard Shortcuts

Global Shortcuts

ShortcutAction
⌘K / Ctrl+KOpen/close command menu
EscClose menu or go back in submenu
↑ ↓Navigate items
EnterSelect item or navigate to collection
Shift+EnterSearch within collection (default)
⌘Enter / Ctrl+EnterOpen the selected documentSearch result in a new tab

In Submenu

ShortcutAction
EscGo back to main menu
EnterOpen selected document

Examples

Minimal Setup

export default buildConfig({
  plugins: [payloadCmdk()],
})

Custom Shortcuts Only

export default buildConfig({
  plugins: [
    payloadCmdk({
      shortcut: ['meta+/', 'ctrl+/'],
      searchButton: false, // Hide button, only use keyboard
    }),
  ],
})

With Custom Actions

export default buildConfig({
  plugins: [
    payloadCmdk({
      customItems: [
        {
          type: 'item',
          slug: 'documentation',
          label: 'View Documentation',
          icon: 'BookOpen',
          action: {
            type: 'link',
            href: 'https://docs.your-site.com',
          },
        },
      ],
    }),
  ],
})

Full Custom Theme

export default buildConfig({
  plugins: [
    payloadCmdk({
      icons: {
        collections: {
          posts: 'Newspaper',
          pages: 'FileText',
          media: 'Image',
          categories: 'FolderTree',
          tags: 'Tag',
          users: 'UserCircle',
          comments: 'MessageCircle',
        },
        globals: {
          header: 'LayoutTemplate',
          footer: 'Layout',
          settings: 'Settings',
          navigation: 'Menu',
          seo: 'Search',
        },
      },
      submenu: {
        enabled: true,
        icons: {
          posts: 'FileText',
          pages: 'File',
          media: 'Image',
        },
      },
    }),
  ],
})

Troubleshooting

  • Objects are not valid as a React child error: Ensure your admin.useAsTitle field is a string and not an object. Currently, plugin doesn't have any safeguards for non-string title fields.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Issues

Found a bug or have a feature request? Please open an issue on GitHub.

License

MIT © VeiaG

More plugins and payload resources at PayloadCMS Extensions

Star History Chart

Similar plugins