Repository navigation
feat(admin): add an image toolbar and inline captions to the editor - #3657
Conversation
Selecting an image in a Portable Text field now shows one floating toolbar above it: Replace, Alt text, alignment (None, Left, Center, Right), Link, Image settings and Delete. It replaces the three corner buttons, the quick alt text overlay and the link-only text bubble, which is text-only again. The toolbar hides when focus leaves it for another field, stays put while the Replace picker is open so focus can return to the button, and is reachable from a selected image with Tab. The settings panel now closes when the image changes outside it or is removed, so Apply can no longer write stale values back.
An image's caption is now a field directly under it, with the placeholder "Type caption for image (optional)" while empty, and saves to the existing caption attribute. Enter starts a new paragraph after the image. Tab moves from a selected image to its caption and then the toolbar; Shift+Tab and Escape move back. Read-only editors show the caption as text only. The selection ring moves from the block to the image, and text dropped on a caption stays in the caption instead of landing in the document.
The toolbar's alt text button reads "Add alt text", with a warning dot, when an image has no description or, for a Media Library image, only its file name. The file name comes from the media item the image already loads, so no extra request is made. Documents the image toolbar and inline captions, and adds the changeset for the whole capability.
On phones and narrow windows the toolbar was wider than the screen and scrolled sideways, hiding Link, Settings and Delete. Below 640px, Replace and Alt text now show only their icons (their names stay available to screen readers), and below 480px the controls wrap onto two centered rows: Replace, Alt text and alignment, then Link, Settings and Delete. The alt text and link fields shrink to fit.
Hovering or focusing "Add alt text" now shows "This image has no description for screen readers". Hints on the image toolbar open after a 200 ms rest instead of Base UI's 600 ms default, open at once when moving between buttons, and close when the toolbar hides instead of staying behind in the corner of the page.
The link row had only an Apply button, drawn with an "open in new tab" arrow, so there was no visible way to back out. It now ends with Cancel and a check-mark Apply link, like the alt text row. Remove link still shows when the image has a link.
The toolbar now fades and scales in from the edge nearest the image each time it appears, with the same 150 ms entrance as Kumo tooltips. It is skipped when the system asks for reduced motion.
Switching straight from one image to another kept the toolbar attached, so the entrance never replayed there, and the 10% scale-up felt slow on a toolbar this wide. The toolbar now fades and scales in from 97% over 150 ms with a strong ease-out whenever it appears or moves to another image. Edits to the same image, such as alignment, don't replay it. Reduced motion keeps only the fade.
The alt text button switched between "Alt text" and "Add alt text" with a yellow dot, so the toolbar changed width from one image to the next and re-centered mid-entrance, making Replace and the alt text icon jump. The button now always reads "Alt text" and is highlighted once the image has a description, like Link when a link is set. Hovering it shows the description, or "No description yet". Escape in the toolbar now returns to the editor even when a button's hint is open; the hint used to swallow the key.
ProseMirror keeps an image selected after focus moves elsewhere, so its ring stayed on while the author typed in another field. The ring now shows only while focus is inside the editor, including its captions and toolbar, matching when the image toolbar is visible.
… keyboard Pressing Enter on Alt text or Add link swapped the focused button out, and the focus gate read the lost focus as leaving the editor, so the toolbar hid before the input could take focus. Focus now waits on the toolbar while the row changes.
…lves A pick disables the link input until its URL resolves, which moves focus to the page. The focus gate hid the toolbar and remounted the row, so an entry without a URL yet lost its error message. The gate now ignores that focus loss, hides once focus lands anywhere outside the editor, and skips the work when the toolbar is already hidden.
Firefox can't drag-select text inside a draggable element, and the image node view is draggable. The node view stops being draggable while a mouse pointer is over the caption.
The media picker can park focus on its own dialog while it closes, before returning focus to Replace or the editor. The focus gate treated that focus, and the focus loss when the dialog unmounted, as leaving the editor and hid the toolbar, so focus had nowhere to return. While the picker is closing, focus in its dialog no longer ends the pause; focus anywhere else outside the editor still hides the toolbar.
…ge-toolbar # Conflicts: # packages/admin/src/components/PortableTextEditor.tsx
🦋 Changeset detectedLatest commit: 4c19870 The changes in this PR will be included in the next version bump. This PR includes changesets to release 12 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| ✅ Deployment successful! View logs |
docs | 7c166db | Sep 29 2026, 07:34 PM |
Scope checkThis PR changes 1,728 lines across 11 files. Large PRs are harder to review and more likely to be closed without review. If this scope is intentional, no action needed. A maintainer will review it. If not, please consider splitting this into smaller PRs. See CONTRIBUTING.md for contribution guidelines. |
🚀 Deploying Preview to Cloudflare 🚀Preview URL: https://noah-editor-media-image-toolbar.try.emdashcms.com, https://noah-editor-media-image-toolbar-emdash-playground.emdash-cms.workers.dev (commit 4c19870)This URL reflects your latest Preview deploymentPreview Deployments by commit
|
@emdash-cms/admin
@emdash-cms/auth
@emdash-cms/auth-atproto
@emdash-cms/blocks
@emdash-cms/cloudflare
@emdash-cms/contentful-to-portable-text
emdash
create-emdash
@emdash-cms/gutenberg-to-portable-text
@emdash-cms/plugin-cli
@emdash-cms/plugin-test
@emdash-cms/plugin-types
@emdash-cms/registry-client
@emdash-cms/registry-lexicons
@emdash-cms/registry-loader
@emdash-cms/registry-moderation
@emdash-cms/registry-verification
@emdash-cms/sandbox-workerd
@emdash-cms/x402
@emdash-cms/plugin-ai-moderation
@emdash-cms/plugin-atproto
@emdash-cms/plugin-audit-log
@emdash-cms/plugin-color
@emdash-cms/plugin-embeds
@emdash-cms/plugin-field-kit
@emdash-cms/plugin-forms
@emdash-cms/plugin-webhook-notifier
commit: |
There was a problem hiding this comment.
This is a reasonable, well-scoped admin UX improvement: it consolidates scattered image controls into one discoverable toolbar, keeps captions editable inline, and fixes the stale-settings-panel problem by closing the panel when the node changes outside it. The implementation follows existing TipTap/Kumo patterns, the new tests cover the key interactions, and the docs prose is updated to match.
The main concern is procedural: AGENTS.md/CONTRIBUTING requires a prior maintainer-approved Discussion for a new feature, and the PR body explicitly says “no Discussion link yet.” That should be resolved before merge.
I also found one real correctness bug: the Alt text highlight decides whether a local image is “described” by comparing the alt text to the fetched media filename, but the toolbar’s media query is enabled: false, so when the cache hasn’t loaded yet the comparison treats a filename-only alt as a description. The current unit test pre-warms the cache, so it doesn’t catch this race. Details and a fix are in the line comment.
Changeset: the description is accurate but is one long paragraph; splitting it would make the CHANGELOG entry easier to scan. Not blocking.
The Alt text button compared the alt text with the Media Library file name from the node view's cached media item. Until that item loaded, a file-name alt counted as a description, so the button lit up and then turned off, most visibly right after Replace. A Media Library image now counts as described only once its media item has loaded, and Replace seeds the cache with the picked item so the state is right straight away.
A bullet list is easier to scan in the CHANGELOG than one paragraph.
There was a problem hiding this comment.
This is a reasonable, well-scoped admin UX improvement. The previous needs_fixing bug is fixed: the Alt-text highlight now waits for a cached media item before deciding whether a local image's alt matches the Media Library file name, so it no longer treats a filename-only alt as a real description while the item is loading. The new regression test explicitly exercises that loading gap, and the expanded test suite covers keyboard focus, replacement, link editing, settings-panel staleness, captions, and responsive layout.
Code quality is solid: the toolbar follows existing BubbleMenu patterns, the caption node view keeps WYSIWYG parity with the published renderer, RTL-safe logical Tailwind classes are used, all UI strings go through Lingui, and the changeset and docs prose have been updated and split into helpful bullets.
The one unresolved procedural concern from the prior review is still the missing maintainer-approved Discussion link. CONTRIBUTING.md § Contribution Policy requires one for feature PRs, and the PR template checkbox for it is still unchecked. That should be resolved before merge.
So: the implementation looks correct and the tests pass structurally; once the Discussion link is added/verified, this is ready for approval.
What does this PR do?
Replaces the selected-image controls in the Portable Text editor with one floating toolbar, and lets authors type captions directly under images.
captionattribute. An empty caption shows a placeholder, and Enter starts a new paragraph after the image. A read-only editor shows the caption as text only when it isn't empty.Stored Portable Text is unchanged. Wide and Full alignment stay hidden (#2931). The settings panel keeps every advanced field.
There is no linked issue.
Type of change
Checklist
pnpm typecheckpassespnpm lintpassespnpm testpasses (or targeted tests for my change)pnpm formathas been runmessages.pochanges except in translation PRs — a workflow extracts catalogs on merge tomain.AI-generated code disclosure
Screenshots / test output
The selected image with its toolbar and caption. The Alt text button is highlighted because the image has a description.
Alt text edited in the toolbar, with Cancel and Save.
The link row, with Cancel and Apply.
On a phone (iPhone 13 emulation) the controls show only their icons and wrap onto two rows. Here the toolbar sits below the image because there is no room above it.
In Arabic the toolbar mirrors, with Replace at the start.
Test output:
packages/adminvitest (Chromium): 207 files, 2829 tests passede2e/tests/editor-image-toolbar.spec.ts: 1 passed (caption and alt text persist through save and reload)pnpm build,pnpm typecheck,pnpm lint:quickandpnpm lint:json(0 diagnostics) pass