Skip to content

Add command palette trigger button to admin bar (Left-aligned search bar version)#11108

Open
t-hamano wants to merge 2 commits intoWordPress:trunkfrom
t-hamano:64672-command-palette-admin-bar-searchbar
Open

Add command palette trigger button to admin bar (Left-aligned search bar version)#11108
t-hamano wants to merge 2 commits intoWordPress:trunkfrom
t-hamano:64672-command-palette-admin-bar-searchbar

Conversation

@t-hamano
Copy link
Contributor

@t-hamano t-hamano commented Mar 2, 2026

Trac ticket: https://core.trac.wordpress.org/ticket/64672

Use of AI Tools

None


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

command-palette-bar-schemes

@t-hamano t-hamano marked this pull request as ready for review March 2, 2026 10:41
@github-actions
Copy link

github-actions bot commented Mar 2, 2026

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.

Core Committers: Use this line as a base for the props when committing in SVN:

Props wildworks, mcsf, joedolson, ellatrix.

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

@github-actions
Copy link

github-actions bot commented Mar 2, 2026

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

@ellatrix
Copy link
Member

ellatrix commented Mar 3, 2026

In my opinion, we should move ahead with whatever we have now for Beta 3, even if there's still design changes needed. We can always do some CSS tweaks in follow-ups and have people attempt to centre it, and at least the main functionality is in.

@t-hamano
Copy link
Contributor Author

t-hamano commented Mar 4, 2026

In my opinion, we should move ahead with whatever we have now for Beta 3, even if there's still design changes needed. We can always do some CSS tweaks in follow-ups and have people attempt to centre it, and at least the main functionality is in.

I agree. If we start small, I think a button would have less impact than a search bar. What do you think?

#11063

'href' => '#',
'meta' => array(
'class' => 'hide-if-no-js',
'onclick' => 'wp.data.dispatch( "core/commands" ).open(); return false;',
Copy link
Contributor

Choose a reason for hiding this comment

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

I assume return false is the preventDefault signal. If so, can we comment to make it clear?

Copy link
Contributor

Choose a reason for hiding this comment

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

A behaviour I'm noticing:

  • Go to a WP-Admin that's taller than the viewport (e.g. Themes, User > Profile)
  • Click on the element to bring up the search bar/dialog
  • Click anywhere else to dismiss it
  • Observed: browser scrolls to bottom

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  • Go to a WP-Admin that's taller than the viewport (e.g. Themes, User > Profile)
  • Click on the element to bring up the search bar/dialog
  • Click anywhere else to dismiss it
  • Observed: browser scrolls to bottom

I can't confirm this behavior in my environment 🤔

c68bdd8b9d2a1e020d1f748df8cbefd3.mp4

return;
}

$is_apple_os = (bool) preg_match( '/Macintosh|Mac OS X|Mac_PowerPC/i', $_SERVER['HTTP_USER_AGENT'] ?? '' );
Copy link
Contributor

Choose a reason for hiding this comment

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

Where was this pattern sourced? From WP itself? I'm trying to determine how reliable it is and whether the source should be cited.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Neither WordPress nor Gutenberg has any code to detect the OS on the server side. I used this source as a reference to come up with the logic. There may be a better approach.

}

#wpadminbar #wp-admin-bar-command-palette .ab-item {
width: 200px;
Copy link
Contributor

Choose a reason for hiding this comment

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

Given the layout constraints (use of floats, etc.) of the admin bar, what would it take to achieve a button that tries to take up 443px unless there isn't enough room for other items?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To achieve this, we'll probably need to flex the entire admin bar.

Copy link
Contributor

Choose a reason for hiding this comment

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

I suspect that shifting the admin bar to a fully flex layout would cause a lot of extender issues. Feels pretty risky this late.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's true, switching to flex layout now is risky and requires more careful discussion. Related discussions can be found here: https://core.trac.wordpress.org/ticket/28983

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, Flex was my instinct too, and I share all those concerns.

@t-hamano
Copy link
Contributor Author

t-hamano commented Mar 5, 2026

One concern with this PR approach might be the duplication of the search bar that triggers the command palette when the editor is opened.

duplicate-search-bar

/* translators: Hidden accessibility text. */
__( 'Open command palette' ),
);
$wp_admin_bar->add_node(
Copy link
Member

Choose a reason for hiding this comment

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

Posted this comment on the wrong PR:

Rather than adding this as a new node, maybe it should be added natively to the wp admin bar as something fundamentally different than a node? That way it's not constrained to the current structure and maybe makes it easier to centre with CSS.

You say that's difficult, but why? I'm saying that this could be a built-in feature of the admin bar rather than having to be constrained to the current API.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe all the core menus are added via WP_Admin_Bar::add_menus(). Is there a way to add controls to the admin bar without using this API?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants