Repository navigation
Button: Add content controls for content-only editing - #84854
Conversation
🤖 PR meta 🤖🎉 PropsIf you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. Updated as activity occurs, without notifying anyone named here. Add the 📦 Bundle sizeSize Change: +4.23 kB (+0.05%) Total Size: 9.06 MB 📦 View Changed
⚡ PerformanceShow the resultsClient side metrics exclude the server response time. front-end-block-theme
front-end-classic-theme
media-processing
media-upload
post-editor
site-editor
🏁 Flaky testsSome tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information. Regression: updating a specific option will only change its value and will not corrupt others in
|
daddb4a to
e4dfe48
Compare
mikachan
left a comment
There was a problem hiding this comment.
Really like the direction here, and keeping a separate panel per block instead of one shared, tangled one seems like a good plan. I've left a couple of other comments.
| resetAll={ () => | ||
| setAttributes( { | ||
| text: '', | ||
| url: undefined, | ||
| linkTarget: undefined, | ||
| rel: undefined, | ||
| } ) | ||
| } |
There was a problem hiding this comment.
resetAll always clears url, linkTarget and rel, even when isLinkEditable is false. When url is bound to a source, the user can't edit it (via lockUrlControls), but setBoundAttributes still sends the change to source.setValues, or onto the attribute itself if the source has no setValues. So "Reset all" can clear a link the panel deliberately hides. It also clears a custom rel that the user may have set in the Advanced panel. Maybe we could only reset the fields this panel renders:
| resetAll={ () => | |
| setAttributes( { | |
| text: '', | |
| url: undefined, | |
| linkTarget: undefined, | |
| rel: undefined, | |
| } ) | |
| } | |
| resetAll={ () => | |
| setAttributes( { | |
| text: '', | |
| ...( isLinkEditable && { url: undefined, linkTarget: undefined, rel: undefined } ), | |
| } ) | |
| } |
| // Hash links and relative paths other than site-root paths can't be | ||
| // opened on their own. | ||
| const isViewableUrl = | ||
| !! url && | ||
| ( ! isHashLink( url ) || | ||
| ( isRelativePath( url ) && ! url.startsWith( '/' ) ) ); |
There was a problem hiding this comment.
It looks like this comment is out of date. It says relative paths other than site-root paths can't be opened, but the check only excludes hash links. And then the second clause can't be reached, as a hash link never starts with ./. So ./foo or ../foo get a View button that opens relative to wp-admin. I think this was copied from navigation-link/shared/controls.jsx:144. Here's a version that matches the comment:
| // Hash links and relative paths other than site-root paths can't be | |
| // opened on their own. | |
| const isViewableUrl = | |
| !! url && | |
| ( ! isHashLink( url ) || | |
| ( isRelativePath( url ) && ! url.startsWith( '/' ) ) ); | |
| // Hash links and relative paths other than site-root paths can't be | |
| // opened on their own. | |
| const isViewableUrl = | |
| !! url && | |
| ! isHashLink( url ) && | |
| ( ! isRelativePath( url ) || url.startsWith( '/' ) ); |
There was a problem hiding this comment.
Things like this is why I'm hesitant to wholesale duplicate it. This also exists in the Navigation Link block, so it would need to get updated there. Maybe we can refactor it into base utility components, but not have the entire panel one big component.
There was a problem hiding this comment.
Refactoring into base utility components sounds good. I think this would be fine as a follow-up since it needs to be changed in the Navigation Link block too.
There was a problem hiding this comment.
Maybe it means putting isViewableUrl into link-control/is-url-like.ts with the other isHashLink and isRelativePath, or even moving all of link-control/is-url-like.ts into a utility in the block editor or even base wordpress/url.
There was a problem hiding this comment.
I'm refactoring this into a hook and component. The View button is getting used now in several places:
- navigation link edit popover
- button edit popover
- in Social Icon: Edit the link from the inspector #84860, it will be added to the social icons too.
This logic would need to get duplicated in each spot, so I'm refactoring it here instead.
e4dfe48 to
22af406
Compare
mikachan
left a comment
There was a problem hiding this comment.
Thanks for the updates! I found two small questions/comments, but this is looking close to landing 🙌
…rch (#85122) Some blocks, like Social Icons and Button Blocks are not able to be edited or added from the site editor sidebar. This is being worked on in #84866, #84860, and #84854. Those won't make the 7.2 cutoff, so we should exclude those blocks from the site editor block search rather than offer an incomplete experience. --------- Co-authored-by: jeryj <jeryj@git.wordpress.org> Co-authored-by: mikachan <mikachan@git.wordpress.org> Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
a095f81 to
6467c7d
Compare
In a content-only section the Button block had no content controls, so selecting it in the List View opened nothing, unlike a Navigation Link. Add a content ToolsPanel with Text, Link to, Open in new tab, and View, rendered only when the block's editing mode is contentOnly so the regular inspector is unchanged. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01E1o9yTAtStCTHxjhPHeg8P
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01E1o9yTAtStCTHxjhPHeg8P
Every other item in a menu edits from a Settings panel in the sidebar, so a Button there gets the panel too, not only in content-only editing. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01E1o9yTAtStCTHxjhPHeg8P
Extract the Text, Link to, Open in new tab and View controls into LinkContentControls, a presentational panel that takes values and callbacks. The Navigation Link keeps its entity logic and passes in its Edit button and extra items; the Button maps its own attributes onto the same props. The panel is TypeScript, so the ToolsPanel dropdown props hook moves to its own typed file, re-exported from utils/hooks, and the upload hook's JSDoc marks its arguments optional to match its default. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01E1o9yTAtStCTHxjhPHeg8P
…ton" This reverts commit 8c0d60b. The shared panel tied the Button's controls to the Navigation Link's, so the Button keeps its own inline Settings panel instead. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01YY39mts89XNBXysaFcLtoa
Pass the navigation link's suggestions query so the picker lists pages before anything is typed and prefers them in search results. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01E1o9yTAtStCTHxjhPHeg8P
Both blocks copied the same check for whether a link can be opened, and the copy had drifted: the comment said relative paths other than site-root paths can't be opened, but the code only excluded hash links, so `./page` got a View button that opened relative to wp-admin. `useResolvedUrl` now resolves the link against the site's home URL the way a browser resolves an `href`, so hash links and relative paths open too, and a site-root path on a subdirectory install resolves against the origin as it does on the front end. It only subscribes to the site data when the link is relative. `ViewLinkButton` renders the button over it, and both blocks use the component. The new files are TypeScript, so block-library's TypeScript config is split into a build project and a dev project for its tests, following the layout in packages/README.md. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017N6SBnzQbqs3yXsiyVbAPh
The Button block reached into the Navigation Link directory for `useLinkPreview` and `getSuggestionsQuery`, the two helpers a block needs around the block editor's `LinkPicker`. Both now live together in `utils/link-picker.ts`, typed, and Navigation Link, its Link UI, and Button import them from there. Their tests move with them and drop out of the lint suppressions. Two `computeDisplayUrl` tests passed a bare string where the function takes an options object, so they asserted nothing; they now pass the object. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017N6SBnzQbqs3yXsiyVbAPh
The two tests that put a Button inside a Navigation block are about how the menu edits its items, so they belong in the Navigation block's spec. The test that checks a Button outside a menu keeps its usual inspector stays with the Button tests. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017N6SBnzQbqs3yXsiyVbAPh
The block inspector animates between a Navigation block and the menu items it lists, but only for the block names in the `blockInspectorAnimation` setting. A Buttons block and its Button were missing, so their panels appeared without the slide the other menu items get. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017N6SBnzQbqs3yXsiyVbAPh
…nd panel Review follow-ups on the content controls: - Resolve relative links against the home URL as a directory, so a subdirectory install keeps `./page` inside the subdirectory. - Define `setText`, `setLink`, and `unlink` once in `ButtonEdit` and use them from the canvas `RichText`, the link popover, and the content panel, so the three can't drift. The panel's Text field now strips a nested anchor tag like the canvas does. - Disable the panel's Text field when `text` is bound to a source the user can't edit, matching the read-only canvas. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DaQQeap7U6o932CHso3b4C
Trunk split these packages into a build project and a dev project, so the block-library build project must reference their tsconfig.build.json or declaration emit fails with TS6310. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DaQQeap7U6o932CHso3b4C
Trunk published block-editor 19.0.0 and block-library 12.0.0 after the rebase, which left this PR's entries under those versions. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DaQQeap7U6o932CHso3b4C
Without a link, checking the box stored an empty URL with a `_blank` target and `noopener` rel. Match the toolbar link popover and render the checkbox only when a URL is set. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DaQQeap7U6o932CHso3b4C
286a2c5 to
048296b
Compare
Trunk now publishes the block editor's type declarations (#85036), so the `@ts-expect-error` on its import is unused and fails the type check. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DaQQeap7U6o932CHso3b4C
# Conflicts: # packages/block-editor/CHANGELOG.md
Selecting a Button from its parent Buttons block's List View tab opens the inspector on the Content tab, and edits to Text and Link to there reach the block and the canvas. Keep the merged #84854 changelog entry and give this PR its own. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01S1u1vgir2YJpmNhb7h3ESd
Closes #85151
What?
Bring UX for content only Button editing inline with Navigation Link editing.
Why?
Currently, clicking a contentOnly button in the sidebar only selects the button on the canvas, while clicking a navigation item opens a popover to give you the relevant things to edit.
For contentOnly editing, Navigation and Buttons should be the same experience. You edit the same information:
How?
packages/block-library/src/button/edit.jsx: aContentControlsToolsPanel rendered inInspectorControls group="content", mirroring the Navigation Link panel.useLinkPreviewnow live together inpackages/block-library/src/utils/link-picker.ts, since Button was importing them from the Navigation Link directory.ViewLinkButtoninpackages/block-library/src/utils/, over auseResolvedUrlhook that resolves the link against the home URL the way a browser resolves anhref. Hash and relative links get a View button too, and a site-root path on a subdirectory install resolves against the origin, as on the front end. The Navigation Link uses the same component, which fixes the./pagecase from review.packages/README.md.getBlockParentsByBlockNamecheck the Search block uses) or when its editing mode iscontentOnly. A Button in post content keeps its usual inspector. Opening the panel up everywhere is a follow-up discussion.blockInspectorAnimationsetting, so their inspector slides in inside a Navigation block like the other menu items.Screenshots
Unchanged: Default editing Button Block click
Clicking a non-contentOnly button shows this state.
ContentOnly List View Click
When clicking a contentOnly list view for a button, you see the popover to edit the fields.

Button within a Navigation List View (not content only)
Clicking a button within a Navigation offers the same experience as clicking a navigation item in the list view.

Testing Instructions
In a menu
In a content-only List View
<!-- wp:group {"templateLock":"contentOnly"} -->around one in the code editor).Testing Instructions for Keyboard
Same as above. Tab into the List View, arrow to the Button row, and press Enter to open the popover. Escape closes it and returns focus to the row.
🤖 Generated with Claude Code
https://claude.ai/code/session_01E1o9yTAtStCTHxjhPHeg8P