Skip to content

Conversation

@Mayank-Tripathi32
Copy link
Contributor

What?

Closes #70595

Adds "create" as a keyword for post/page commands in Command Palette to improve user experience and searchability.

Why?

Currently, when users open the Command Palette (⌘ + K) and type "create post" or "create page", no matching commands are shown. However, typing "add post" or "add page" works as expected. Many end users naturally think of "creating" content rather than "adding" it, so it would be more intuitive if "create" were recognized as an alias or keyword for the existing "Add Post" and "Add Page" commands.

This PR addresses the issue described in #70595 by adding comprehensive keywords support to both static and dynamic commands in the Command Palette.

How?

Core Implementation

  1. Fixed useCommand hook - Added keywords: command.keywords to registerCommand call for static commands
  2. Updated commands reducer - Added keywords: action.keywords to store keywords in state
  3. Enhanced TypeScript definitions - Added @property {string[]=} keywords to WPCommandConfig typedef
  4. Leveraged cmdk library's built-in keywords support - Used proper keywords prop on Command.Item components

Command Updates

  • "Add new post" command - Added keywords: ['post', 'new', 'post new', 'add new post', 'create post', 'create new post', 'create']
  • "Add new page" command - Added keywords: ['page', 'new', 'page new', 'add new page', 'create page', 'create new page', 'create']

Documentation

  • Updated README.md to document keywords support

Testing Instructions

  1. Open the WordPress site/post editor
  2. Press ⌘ + K (or Ctrl + K on Windows/Linux) to open the Command Palette
  3. Type "create post" and verify that "Add new post" command appears
  4. Type "create page" and verify that "Add new page" command appears
  5. Type "add post" and verify that "Add new post" command still appears (existing functionality preserved)
  6. Type "add page" and verify that "Add new page" command still appears (existing functionality preserved)
  7. Test partial matches like "create", "post", "page" to ensure they all work

Testing Instructions for Keyboard

  1. Navigate to the WordPress admin using keyboard only (Tab, Enter, Arrow keys)
  2. Press ⌘ + K to open Command Palette
  3. Type "create post" using keyboard
  4. Use Arrow keys to navigate through results
  5. Press Enter to select "Add new post" command
  6. Verify the command executes correctly
  7. Repeat with "create page" and other variations
  8. Test with screen reader to ensure proper announcement of command options

Screenshots or screencast

Before After
Before: "create post" returns no results After: "create post" shows "Add new post" command

Note: The implementation ensures backward compatibility - all existing search terms continue to work while adding the new "create" keyword functionality.

@github-actions
Copy link

github-actions bot commented Jul 6, 2025

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: Mayank-Tripathi32 <[email protected]>
Co-authored-by: ramonjd <[email protected]>
Co-authored-by: t-hamano <[email protected]>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Copy link
Member

@ramonjd ramonjd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for getting this PR up!

I think it's a good change. Are there any blockers or prerequisites to getting it in?

<Command.Item
key={ command.name }
value={ command.searchLabel ?? command.label }
keywords={ command.keywords }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see this is built-in behaviour in https://www.npmjs.com/package/cmdk

Nice!

callback: addNewPage,
keywords: [
__( 'page' ),
__( 'new' ),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I expect there are languages in which "new" might not feature in the translation for "Add new page" so it seems safe to duplicate, at least in English.

@Mayank-Tripathi32
Copy link
Contributor Author

Are there any blockers or prerequisites to getting it in?

None. The CMDK package is already used and we are just extending the implementation using it.

Copy link
Member

@ramonjd ramonjd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this PR, and for the tests 🙇🏻

@ramonjd ramonjd merged commit 1a51bf9 into WordPress:trunk Aug 21, 2025
68 checks passed
@github-actions github-actions bot added this to the Gutenberg 21.6 milestone Aug 21, 2025
@Mamaduka
Copy link
Member

I think this needs some more work. I expect (and e2e tests did as well) that keyword combos would work during the search, but they return no results. Try "create page" or "new page".

Discovered while debugging related test failures - #71293.

@ramonjd
Copy link
Member

ramonjd commented Aug 21, 2025

Oh thanks for catching that @Mamaduka I got lured in by locally passing tests before the merge 🙃

I wonder if it should be used in conjunction with the filter function? @Mayank-Tripathi32 what do you think?

See https://github.com/pacocoursey/cmdk#command-cmdk-root

A third argument, keywords, can also be provided to the filter function. Keywords act as aliases for the item value, and can also affect the rank of the item. Keywords are trimmed.

<Command
  filter={(value, search, keywords) => {
    const extendValue = value + ' ' + keywords.join(' ')
    if (extendValue.includes(search)) return 1
    return 0
  }}
/>

@Mamaduka
Copy link
Member

Happens all the time when branches get out of sync 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Package] Commands /packages/commands [Type] Enhancement A suggestion for improvement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add “create” as a keyword for post/page commands in Command Palette

4 participants