From b863a698c9e0a06552c12099599eb0bc8e5f34bb Mon Sep 17 00:00:00 2001 From: Schero94 <64200582+Schero94@users.noreply.github.com> Date: Fri, 20 Nov 2026 15:09:45 +0100 Subject: [PATCH 1/4] fix(admin): focus, names and states in the field panels Re-audit minors (field panels, side panel, AI dialogs): - Grammar panel takes focus when it opens; Escape closes the grammar and quality panels (not inside an open listbox, menu or dialog). - Cancel/Escape on the template "replace" and version "restore" confirms returns focus to the button that asked. - Comments: focus back on Reply after sending or cancelling a reply and on Edit after saving or cancelling an edit; a failed first load shows the error with Try again and no zero counts or read-only text. - Focus stays in the find panel after Replace all, returns to "Check links" after the check, and the suggestions panel takes lost focus after a reviewer sent suggestions. - Presence join/leave is announced once per entry, not once per field. - Contextual names for Edit/Delete/Reply/Resolve/Reopen and Accept/Reject/Withdraw/Show block. - Side panel "Check"/"Show" are DS buttons (size S) instead of text buttons. - "No links were checked." instead of "no problems" when every link was skipped. - AI dialogs: shared messages for UNREACHABLE, BAD_RESPONSE, RESPONSE_TOO_LARGE, EMPTY and PROVIDER_ERROR. Docs read: DS 2.3.1 Button/IconButton types, @strapi/admin 5.63 ConfirmDialog, Radix Dialog onOpenChange (focus restore), React hooks rules (react.dev purity). Co-Authored-By: Claude Opus 5.5 --- admin/src/components/EditorField/AiDialog.jsx | 13 +- .../components/EditorField/BlockAiDialog.jsx | 11 +- .../components/EditorField/CommentThread.jsx | 104 ++++- .../components/EditorField/CommentsPanel.jsx | 61 +-- .../components/EditorField/FieldAiDialog.jsx | 11 +- .../EditorField/FindReplacePanel.jsx | 28 +- .../components/EditorField/GrammarPanel.jsx | 8 +- .../components/EditorField/HistoryModal.jsx | 20 +- .../components/EditorField/QualityPanel.jsx | 31 +- .../EditorField/SuggestionsPanel.jsx | 60 ++- .../components/EditorField/TemplateDialog.jsx | 7 +- .../components/EditorField/usePanelFocus.js | 73 ++++ .../EditorField/usePresenceAnnouncements.js | 32 +- admin/src/components/EntryPanel/sections.jsx | 11 +- admin/src/editor/ai-errors.mjs | 32 ++ admin/src/editor/presence-announce.mjs | 52 +++ tests/admin/panels-a11y.test.jsx | 356 ++++++++++++++++++ tests/ai-errors.test.mjs | 25 ++ tests/presence-announce.test.mjs | 26 ++ 19 files changed, 862 insertions(+), 99 deletions(-) create mode 100644 admin/src/editor/ai-errors.mjs create mode 100644 admin/src/editor/presence-announce.mjs create mode 100644 tests/admin/panels-a11y.test.jsx create mode 100644 tests/ai-errors.test.mjs create mode 100644 tests/presence-announce.test.mjs diff --git a/admin/src/components/EditorField/AiDialog.jsx b/admin/src/components/EditorField/AiDialog.jsx index 4a1c794..c9258dd 100644 --- a/admin/src/components/EditorField/AiDialog.jsx +++ b/admin/src/components/EditorField/AiDialog.jsx @@ -14,6 +14,7 @@ import { useFetchClient } from '../../utils/fetch-client'; import { API, readApiError } from '../../utils/api'; import { changeViews } from '../../../../shared/ai-blocks.mjs'; import { TextOps } from './VersionDiff'; +import { aiErrorEntry } from '../../editor/ai-errors.mjs'; /** * AI assistant dialog: the admin picks an action for the selected text, the @@ -45,16 +46,6 @@ const TONE_LABELS = { persuasive: ['editor.ai.tone.persuasive', 'Persuasive'], }; -const ERROR_MESSAGES = { - DISABLED: ['editor.ai.error.disabled', 'The AI assistant is turned off.'], - NOT_CONFIGURED: ['editor.ai.error.notConfigured', 'The AI assistant is not configured yet.'], - NO_API_KEY: ['editor.ai.error.noKey', 'The AI provider key is missing.'], - AUTH_FAILED: ['editor.ai.error.auth', 'The AI provider rejected the key.'], - PROVIDER_RATE_LIMIT: ['editor.ai.error.busy', 'The AI provider is busy. Try again later.'], - TIMEOUT: ['editor.ai.error.timeout', 'The AI provider did not answer in time.'], - REFUSED: ['editor.ai.error.refused', 'The AI provider declined this request.'], -}; - /** * Plain text of an HTML snippet (inert parsing). * @param {string} html - HTML. @@ -103,7 +94,7 @@ export const AiDialog = ({ t, request, config, target, onApply, onClose, returnF if (abort.current && abort.current.signal.aborted) return; const info = readApiError(error); const [key, text] = - ERROR_MESSAGES[info.code] || + aiErrorEntry(info.code) || (info.status === 429 ? ['editor.ai.error.rateLimit', 'You sent many requests. Try again in a minute.'] : info.status === 413 diff --git a/admin/src/components/EditorField/BlockAiDialog.jsx b/admin/src/components/EditorField/BlockAiDialog.jsx index cd9d77e..b1a31fa 100644 --- a/admin/src/components/EditorField/BlockAiDialog.jsx +++ b/admin/src/components/EditorField/BlockAiDialog.jsx @@ -18,6 +18,7 @@ import { sanitizeInline } from '../../editor/sanitize'; import { segmentPlainText } from '../../../../shared/ai-fields.mjs'; import { applyBlockResult, blockSegments, changeViews } from '../../../../shared/ai-blocks.mjs'; import { TextOps } from './VersionDiff'; +import { aiErrorEntry } from '../../editor/ai-errors.mjs'; /** * Block-aware AI actions (2.4): rewrite, shorten, translate or change the @@ -44,14 +45,8 @@ const TONE_LABELS = { persuasive: ['editor.ai.tone.persuasive', 'Persuasive'], }; +/** Codes this dialog words differently from the shared AI messages (`editor/ai-errors.mjs`). */ const ERROR_MESSAGES = { - DISABLED: ['editor.ai.error.disabled', 'The AI assistant is turned off.'], - NOT_CONFIGURED: ['editor.ai.error.notConfigured', 'The AI assistant is not configured yet.'], - NO_API_KEY: ['editor.ai.error.noKey', 'The AI provider key is missing.'], - AUTH_FAILED: ['editor.ai.error.auth', 'The AI provider rejected the key.'], - PROVIDER_RATE_LIMIT: ['editor.ai.error.busy', 'The AI provider is busy. Try again later.'], - TIMEOUT: ['editor.ai.error.timeout', 'The AI provider did not answer in time.'], - REFUSED: ['editor.ai.error.refused', 'The AI provider declined this request.'], BAD_RESPONSE: ['editor.aiField.error.format', 'The answer had an unexpected format. Nothing changed.'], }; @@ -164,7 +159,7 @@ export const BlockAiDialog = ({ if (abort.current && abort.current.signal.aborted) return; const info = error && error.mismatch ? { code: 'BAD_RESPONSE' } : readApiError(error); const [key, text] = - ERROR_MESSAGES[info.code] || + aiErrorEntry(info.code, ERROR_MESSAGES) || (info.status === 429 ? ['editor.ai.error.rateLimit', 'You sent many requests. Try again in a minute.'] : info.status === 413 diff --git a/admin/src/components/EditorField/CommentThread.jsx b/admin/src/components/EditorField/CommentThread.jsx index b006a36..c6deea6 100644 --- a/admin/src/components/EditorField/CommentThread.jsx +++ b/admin/src/components/EditorField/CommentThread.jsx @@ -1,9 +1,10 @@ -import { forwardRef, useState } from 'react'; +import { forwardRef, useRef, useState } from 'react'; import { useIntl } from 'react-intl'; import { Badge, Box, Button, Flex, Typography } from '@strapi/design-system'; import styled from 'styled-components'; import { ConfirmAction } from '../ui/ConfirmAction'; import { MentionTextarea } from './MentionTextarea'; +import { refocusLater } from './usePanelFocus'; import { normalizeExcerpt, relativeTimeParts } from '../../../../shared/comments.mjs'; import { mentionSegments } from '../../../../shared/comment-mentions.mjs'; @@ -87,6 +88,30 @@ const List = styled.ol` gap: ${({ theme }) => theme.spaces[3]}; `; +/** Characters of a comment or quote in an action's accessible name (2.7.8). */ +const NAME_EXCERPT = 40; + +/** + * Short excerpt for accessible names of repeated actions ("Edit comment by Ben M.: First words…"). + * @param {string|null|undefined} text - Comment body or quote. + * @returns {string} Excerpt. + */ +export const nameExcerpt = (text) => { + const plain = normalizeExcerpt(String(text || '').replace(/<[^>]*>/g, ' ')); + return plain.length > NAME_EXCERPT ? `${plain.slice(0, NAME_EXCERPT - 1)}…` : plain; +}; + +/** + * Display name of a comment author. + * @param {object} comment - Comment. + * @param {Function} t - Translator. + * @returns {string} Name. + */ +const authorOf = (comment, t) => + comment.author.deleted + ? t('editor.comments.deletedUser', 'Deleted user') + : comment.author.name || t('editor.comments.deletedUser', 'Deleted user'); + /** * Author name, relative time (absolute time as tooltip) and "edited". * @param {object} props - Props. @@ -96,9 +121,7 @@ const List = styled.ol` */ const CommentMeta = ({ comment, t }) => { const { formatRelativeTime, formatDate } = useIntl(); - const name = comment.author.deleted - ? t('editor.comments.deletedUser', 'Deleted user') - : comment.author.name || t('editor.comments.deletedUser', 'Deleted user'); + const name = authorOf(comment, t); const { value, unit } = relativeTimeParts(comment.createdAt); const absolute = formatDate(comment.createdAt, { dateStyle: 'medium', timeStyle: 'short' }); return ( @@ -162,6 +185,9 @@ export const CommentThread = forwardRef(function CommentThread( const [replyMentions, setReplyMentions] = useState([]); const [editing, setEditing] = useState(null); const [busy, setBusy] = useState(null); + // 2.7.8: focus targets after a reply is sent or cancelled and after an edit is saved or cancelled. + const replyButtonRef = useRef(null); + const editButtonsRef = useRef(new Map()); const resolved = thread.status === 'resolved'; // 2.4: a thread written under a positional path before 2.4 that belongs to no single entry (read-only). const positional = Boolean(thread.positional); @@ -198,6 +224,7 @@ export const CommentThread = forwardRef(function CommentThread( setReply(''); setReplyMentions([]); setReplying(false); + refocusLater(replyButtonRef); announce(t('editor.comments.announce.replied', 'Reply added')); } catch (error) { fail(errorMessage(error)); @@ -211,7 +238,7 @@ export const CommentThread = forwardRef(function CommentThread( setBusy(`edit:${editing.id}`); try { reportDropped(await actions.edit(editing.id, editing.value, editing.mentions)); - setEditing(null); + stopEditing(editing.id); announce(t('editor.comments.announce.saved', 'Comment saved')); } catch (error) { fail(errorMessage(error)); @@ -220,6 +247,24 @@ export const CommentThread = forwardRef(function CommentThread( } }; + /** Leaves the edit box and puts focus back on the comment's Edit button. */ + const stopEditing = (id) => { + setEditing(null); + refocusLater(() => editButtonsRef.current.get(id) || null); + }; + + /** Closes the reply box and puts focus back on Reply. */ + const stopReplying = () => { + setReplying(false); + refocusLater(replyButtonRef); + }; + + const first = thread.comments[0] || null; + const threadName = { + name: first ? authorOf(first, t) : '', + excerpt: nameExcerpt(quote || (first ? first.body : '') || excerpt), + }; + const toggleResolved = async () => { if (busy) return; setBusy('resolve'); @@ -377,7 +422,7 @@ export const CommentThread = forwardRef(function CommentThread( onMentionsChange={(next) => setEditing((current) => ({ ...current, mentions: next }))} search={searchMentions} onSubmit={saveEdit} - onCancel={() => setEditing(null)} + onCancel={() => stopEditing(comment.id)} t={t} autoFocus /> @@ -390,7 +435,7 @@ export const CommentThread = forwardRef(function CommentThread( > {t('editor.comments.save', 'Save')} - @@ -406,6 +451,14 @@ export const CommentThread = forwardRef(function CommentThread( } @@ -474,7 +538,7 @@ export const CommentThread = forwardRef(function CommentThread( onMentionsChange={setReplyMentions} search={searchMentions} onSubmit={sendReply} - onCancel={() => setReplying(false)} + onCancel={stopReplying} t={t} autoFocus /> @@ -482,17 +546,33 @@ export const CommentThread = forwardRef(function CommentThread( - ) : ( - - diff --git a/admin/src/components/EditorField/CommentsPanel.jsx b/admin/src/components/EditorField/CommentsPanel.jsx index 0ad46e9..0b75738 100644 --- a/admin/src/components/EditorField/CommentsPanel.jsx +++ b/admin/src/components/EditorField/CommentsPanel.jsx @@ -361,13 +361,15 @@ export const CommentsPanel = ({ {t('editor.comments.title', 'Comments')} - - {t( - 'editor.comments.summary', - '{open, plural, one {# open thread} other {# open threads}} · {resolved} resolved', - { open: counts.open, resolved: counts.resolved } - )} - + {loaded ? ( + + {t( + 'editor.comments.summary', + '{open, plural, one {# open thread} other {# open threads}} · {resolved} resolved', + { open: counts.open, resolved: counts.resolved } + )} + + ) : null} @@ -411,27 +413,30 @@ export const CommentsPanel = ({ ) : null} - - {canWrite ? ( - - ) : ( - - {t('editor.comments.readOnly', 'You can read comments but not add any.')} - - )} - setShowResolved(value === true)}> - {t('editor.comments.showResolved', 'Show resolved threads')} - - + {/* 2.7.8: before the first load (or when it failed) nothing is known about counts or rights. */} + {loaded ? ( + + {canWrite ? ( + + ) : ( + + {t('editor.comments.readOnly', 'You can read comments but not add any.')} + + )} + setShowResolved(value === true)}> + {t('editor.comments.showResolved', 'Show resolved threads')} + + + ) : null} {canWrite && blocks.length === 0 ? ( diff --git a/admin/src/components/EditorField/FieldAiDialog.jsx b/admin/src/components/EditorField/FieldAiDialog.jsx index f4ebffd..76c2e77 100644 --- a/admin/src/components/EditorField/FieldAiDialog.jsx +++ b/admin/src/components/EditorField/FieldAiDialog.jsx @@ -21,6 +21,7 @@ import { readSegment, segmentPlainText, } from '../../../../shared/ai-fields.mjs'; +import { aiErrorEntry } from '../../editor/ai-errors.mjs'; /** * Whole-field AI actions (2.3): translate every text of the field or @@ -32,15 +33,9 @@ import { * paragraph. */ +/** Codes this dialog words differently from the shared AI messages (`editor/ai-errors.mjs`). */ const ERROR_MESSAGES = { - DISABLED: ['editor.ai.error.disabled', 'The AI assistant is turned off.'], FIELD_ACTIONS_DISABLED: ['editor.aiField.error.off', 'Whole-field AI actions are turned off.'], - NOT_CONFIGURED: ['editor.ai.error.notConfigured', 'The AI assistant is not configured yet.'], - NO_API_KEY: ['editor.ai.error.noKey', 'The AI provider key is missing.'], - AUTH_FAILED: ['editor.ai.error.auth', 'The AI provider rejected the key.'], - PROVIDER_RATE_LIMIT: ['editor.ai.error.busy', 'The AI provider is busy. Try again later.'], - TIMEOUT: ['editor.ai.error.timeout', 'The AI provider did not answer in time.'], - REFUSED: ['editor.ai.error.refused', 'The AI provider declined this request.'], BAD_RESPONSE: ['editor.aiField.error.format', 'The answer had an unexpected format. Nothing changed.'], }; @@ -152,7 +147,7 @@ export const FieldAiDialog = ({ if (abort.current && abort.current.signal.aborted) return; const info = error && error.mismatch ? { code: 'BAD_RESPONSE' } : readApiError(error); const [key, text] = - ERROR_MESSAGES[info.code] || + aiErrorEntry(info.code, ERROR_MESSAGES) || (info.status === 429 ? ['editor.ai.error.rateLimit', 'You sent many requests. Try again in a minute.'] : info.status === 413 diff --git a/admin/src/components/EditorField/FindReplacePanel.jsx b/admin/src/components/EditorField/FindReplacePanel.jsx index 91c3387..ca7955c 100644 --- a/admin/src/components/EditorField/FindReplacePanel.jsx +++ b/admin/src/components/EditorField/FindReplacePanel.jsx @@ -45,6 +45,9 @@ export const FindReplacePanel = ({ t, getData, onApply, onSelect, onClose, readO const [status, setStatus] = useState(''); const findRef = useRef(null); const busyRef = useRef(false); + const panelRef = useRef(null); + const replaceRef = useRef(null); + const replaceAllRef = useRef(null); useEffect(() => { if (findRef.current) findRef.current.focus(); @@ -98,9 +101,29 @@ export const FindReplacePanel = ({ t, getData, onApply, onSelect, onClose, readO await search(); } finally { busyRef.current = false; + // 2.7.8: after Replace all the replace buttons are disabled (no matches left) and the editor + // may have taken focus: focus stays in the panel, on the button used or the Find input. + keepFocusInPanel(all ? replaceAllRef : replaceRef); } }; + /** + * Keeps focus in the panel after a replace. + * @param {{ current: HTMLElement|null }} preferred - Button that was used. + * @returns {void} + */ + const keepFocusInPanel = (preferred) => { + window.requestAnimationFrame(() => + window.requestAnimationFrame(() => { + const panel = panelRef.current; + if (!panel || panel.contains(document.activeElement)) return; + const button = preferred.current; + const target = button && !button.disabled && button.isConnected ? button : findRef.current; + if (target) target.focus(); + }) + ); + }; + const onFindKey = (event) => { if (event.key === 'Enter') { event.preventDefault(); @@ -123,6 +146,7 @@ export const FindReplacePanel = ({ t, getData, onApply, onSelect, onClose, readO return ( {readOnly ? null : ( <> - - diff --git a/admin/src/components/EditorField/GrammarPanel.jsx b/admin/src/components/EditorField/GrammarPanel.jsx index bd53d52..907ca84 100644 --- a/admin/src/components/EditorField/GrammarPanel.jsx +++ b/admin/src/components/EditorField/GrammarPanel.jsx @@ -11,6 +11,7 @@ import { } from '@strapi/design-system'; import { Cross } from '@strapi/icons'; import styled from 'styled-components'; +import { closeOnEscape, usePanelAutoFocus } from './usePanelFocus'; import { API, readApiError } from '../../utils/api'; import { collectSegments, @@ -143,6 +144,7 @@ export const afterReplacement = (matches, applied, replacement) => { * @param {(match: object|null, occurrence?: number) => void} props.onSelect - Highlights a match (null clears). * @param {() => void} props.onClose - Closes the panel. * @param {boolean} [props.readOnly] - No "Apply" buttons. + * @param {boolean} [props.autoFocus=true] - 2.7.8: the panel opens from More tools; its heading takes focus. * @returns {JSX.Element} Panel. */ export const GrammarPanel = ({ @@ -154,12 +156,15 @@ export const GrammarPanel = ({ onSelect, onClose, readOnly = false, + autoFocus = true, }) => { const [state, setState] = useState({ status: 'idle', matches: [], parts: [], truncated: false, error: '' }); const [current, setCurrent] = useState(null); const [announcement, setAnnouncement] = useState(''); const [notice, setNotice] = useState(''); const abortRef = useRef(null); + const headingRef = useRef(null); + usePanelAutoFocus(autoFocus, headingRef); useEffect( () => () => { @@ -298,11 +303,12 @@ export const GrammarPanel = ({ hasRadius minWidth={0} data-testid="mex-grammar-panel" + onKeyDown={(event) => closeOnEscape(event, onClose)} > - + {t('editor.grammar.title', 'Grammar check')} diff --git a/admin/src/components/EditorField/HistoryModal.jsx b/admin/src/components/EditorField/HistoryModal.jsx index 09d777e..fa2c7f5 100644 --- a/admin/src/components/EditorField/HistoryModal.jsx +++ b/admin/src/components/EditorField/HistoryModal.jsx @@ -16,6 +16,7 @@ import { } from '@strapi/design-system'; import { ArrowClockwise, Eye, Pencil } from '@strapi/icons'; import { ConfirmDialog, useNotification } from '@strapi/strapi/admin'; +import { refocusLater } from './usePanelFocus'; import { useFetchClient } from '../../utils/fetch-client'; import styled from 'styled-components'; import { API, readApiError } from '../../utils/api'; @@ -108,6 +109,7 @@ export const HistoryModal = ({ const [saving, setSaving] = useState(false); const [preview, setPreview] = useState(null); const [confirm, setConfirm] = useState(null); + const restoreOpenerRef = useRef(null); const [restoring, setRestoring] = useState(false); const [label, setLabel] = useState(''); const [renaming, setRenaming] = useState(null); @@ -372,7 +374,13 @@ export const HistoryModal = ({ ) : null} {canWrite && item.restorable && !locked ? ( - ) : null} @@ -609,7 +617,15 @@ export const HistoryModal = ({ ) : null} - !open && !restoring && setConfirm(null)}> + { + if (open || restoring) return; + setConfirm(null); + // 2.7.8: Cancel or Escape returns focus to the Restore button that asked. + refocusLater(restoreOpenerRef.current); + }} + > {confirm ? ( extractLinks(data), [data]); const linkCount = links.internal.length + links.external.length + links.media.length; @@ -263,18 +264,21 @@ export const QualityPanel = ({ external: [], }; if (!externalEnabled) result.external = links.external.map(({ url }) => ({ url, status: 'skipped' })); - const problems = [...result.internal, ...result.media, ...result.external].filter((item) => - PROBLEMS.has(item.status) - ).length; + const all = [...result.internal, ...result.media, ...result.external]; + const problems = all.filter((item) => PROBLEMS.has(item.status)).length; + // 2.7.8: "no problems" only when something was checked (external links may all be skipped). + const checked = all.filter((item) => item.status !== 'skipped').length; setCheck({ state: 'done', result, message: '' }); setAnnouncement( - t( - 'editor.quality.links.done', - 'Link check finished: {count, plural, =0 {no problems} one {# problem} other {# problems}}', - { - count: problems, - } - ) + checked === 0 + ? t('editor.quality.links.noneChecked', 'No links were checked.') + : t( + 'editor.quality.links.done', + 'Link check finished: {count, plural, =0 {no problems} one {# problem} other {# problems}}', + { + count: problems, + } + ) ); } catch (error) { if (requestRef.current !== id) return; @@ -285,6 +289,9 @@ export const QualityPanel = ({ : t('editor.quality.links.failed', 'The links could not be checked.'); setCheck({ state: 'error', result: null, message }); setAnnouncement(message); + } finally { + // 2.7.8: the button is disabled while it loads, which dropped focus to the page body. + if (requestRef.current === id) refocusIfLost(checkButtonRef); } }, [externalEnabled, fetchClient, links, t]); @@ -489,6 +496,7 @@ export const QualityPanel = ({ borderColor="neutral200" hasRadius minWidth={0} + onKeyDown={onClose ? (event) => closeOnEscape(event, onClose) : undefined} > @@ -593,6 +601,7 @@ export const QualityPanel = ({ {t('editor.quality.links.title', 'Links and media')} } @@ -499,6 +529,11 @@ export const SuggestionsPanel = ({ loading={busy === suggestion.id} disabled={working} data-testid="mex-suggestion-accept" + aria-label={t( + 'editor.suggestions.acceptNamed', + 'Accept suggestion by {name}: {op}, {excerpt}', + named + )} > {t('editor.suggestions.accept', 'Accept')} @@ -510,6 +545,11 @@ export const SuggestionsPanel = ({ onClick={() => reject(item)} disabled={working} data-testid="mex-suggestion-reject" + aria-label={t( + 'editor.suggestions.rejectNamed', + 'Reject suggestion by {name}: {op}, {excerpt}', + named + )} > {t('editor.suggestions.reject', 'Reject')} @@ -517,7 +557,16 @@ export const SuggestionsPanel = ({ {suggestion.author.own ? ( + } @@ -535,6 +584,11 @@ export const SuggestionsPanel = ({ ); @@ -298,7 +301,7 @@ const SummaryStatus = ({ t, summary }) => { if (summary.status === 'error' && !summary.data) return ( - + {t('entryPanel.error', 'Comments and quality could not be loaded.')} +
+ `; + await settle(); + const buttons = holder.querySelectorAll('button'); + assert.equal(buttons[0].getAttribute('aria-label'), 'Bold'); + assert.equal(buttons[1].getAttribute('aria-label'), 'Marker'); + assert.equal(buttons[2].getAttribute('aria-label'), 'Mention an entry', 'own names stay'); + stop(); + holder.remove(); +}); + +test('inlineToolbarItems lists enabled, rendered items (jsdom: rects stubbed)', () => { + const holder = document.createElement('div'); + holder.innerHTML = `
`; + document.body.append(holder); + for (const button of holder.querySelectorAll('button')) button.getClientRects = () => [{}]; + assert.deepEqual( + inlineToolbarItems(holder).map((element) => element.id), + ['a'] + ); + holder.remove(); +}); + +test('insertedBlockControl: a video block gets its Choose button, a paragraph nothing', () => { + const visible = () => true; + const wrap = document.createElement('div'); + wrap.innerHTML = `
+
Text
`; + assert.equal(insertedBlockControl(wrap.querySelector('#v'), visible).id, 'choose'); + assert.equal(insertedBlockControl(wrap.querySelector('#p'), visible), null); + assert.equal(insertedBlockControl(document.createTextNode('x'), visible), null); +}); From c586eae5399ce0b46431d5b2c96cc977550d0e10 Mon Sep 17 00:00:00 2001 From: Schero94 <64200582+Schero94@users.noreply.github.com> Date: Fri, 20 Nov 2026 15:43:44 +0100 Subject: [PATCH 3/4] fix(admin): attachment "Select a file" is a keyboard button and gets focus after insert @editorjs/attaches 1.3 renders the button as a clickable div. It gets role=button, a tab stop and Enter/Space, so Tab reaches it and the field focuses it after the block is inserted. Co-Authored-By: Claude Opus 5.5 --- admin/src/components/EditorField/index.jsx | 3 ++ admin/src/editor/toolbar-a11y.mjs | 35 ++++++++++++++++++++++ tests/admin/inline-toolbar.test.jsx | 22 ++++++++++++++ 3 files changed, 60 insertions(+) diff --git a/admin/src/components/EditorField/index.jsx b/admin/src/components/EditorField/index.jsx index 1f00b96..ed13687 100644 --- a/admin/src/components/EditorField/index.jsx +++ b/admin/src/components/EditorField/index.jsx @@ -162,6 +162,7 @@ import { skippedControl, } from '../../editor/block-tab-stops.mjs'; import { + decorateDivButtons, decorateToolbar, inlineToolbarItems, labelInlineToolbar, @@ -2304,6 +2305,7 @@ const EditorFieldBody = ({ const holder = holderRef.current; if (!ready || !holder) return undefined; const stopLabels = labelInlineToolbar(holder, (name) => toolTitlesRef.current[name]); + const stopDivButtons = decorateDivButtons(holder); let insertedAt = 0; const onToolbox = (event) => { if (event.target && event.target.closest && event.target.closest('.ce-toolbox, .ce-popover')) @@ -2326,6 +2328,7 @@ const EditorFieldBody = ({ holder.addEventListener('keydown', onToolbox, true); return () => { stopLabels(); + stopDivButtons(); observer.disconnect(); holder.removeEventListener('click', onToolbox, true); holder.removeEventListener('keydown', onToolbox, true); diff --git a/admin/src/editor/toolbar-a11y.mjs b/admin/src/editor/toolbar-a11y.mjs index 804acb5..edaffda 100644 --- a/admin/src/editor/toolbar-a11y.mjs +++ b/admin/src/editor/toolbar-a11y.mjs @@ -112,3 +112,38 @@ export const inlineToolbarItems = (holder) => { (element) => !element.hasAttribute('disabled') && element.getClientRects().length > 0 ); }; + +/** Package controls that are clickable `div`s (2.7.8): @editorjs/attaches' "Select a file". */ +const DIV_BUTTONS = '.cdx-attaches__button'; + +/** + * Makes clickable `div`s of package tools keyboard buttons (role, tab stop, Enter/Space), now and + * for blocks added later. Their visible text names them. + * @param {Element|null} holder - Editor holder. + * @returns {() => void} Cleanup. + */ +export const decorateDivButtons = (holder) => { + if (!holder) return () => {}; + const decorate = () => { + for (const node of holder.querySelectorAll(`${DIV_BUTTONS}:not([role])`)) { + node.setAttribute('role', 'button'); + node.setAttribute('tabindex', '0'); + } + }; + const onKeyDown = (event) => { + const node = event.target && event.target.closest ? event.target.closest(DIV_BUTTONS) : null; + if (!node || (event.key !== 'Enter' && event.key !== ' ')) return; + event.preventDefault(); + event.stopPropagation(); + node.click(); + }; + decorate(); + const View = holder.ownerDocument.defaultView; + const observer = new View.MutationObserver(decorate); + observer.observe(holder, { childList: true, subtree: true }); + holder.addEventListener('keydown', onKeyDown); + return () => { + observer.disconnect(); + holder.removeEventListener('keydown', onKeyDown); + }; +}; diff --git a/tests/admin/inline-toolbar.test.jsx b/tests/admin/inline-toolbar.test.jsx index 102887d..ecd23d4 100644 --- a/tests/admin/inline-toolbar.test.jsx +++ b/tests/admin/inline-toolbar.test.jsx @@ -64,3 +64,25 @@ test('insertedBlockControl: a video block gets its Choose button, a paragraph no assert.equal(insertedBlockControl(wrap.querySelector('#p'), visible), null); assert.equal(insertedBlockControl(document.createTextNode('x'), visible), null); }); + +test('attachment "Select a file" (a div in @editorjs/attaches) becomes a keyboard button', async () => { + const { decorateDivButtons } = await import('../../admin/src/editor/toolbar-a11y.mjs'); + const holder = document.createElement('div'); + document.body.append(holder); + const stop = decorateDivButtons(holder); + holder.innerHTML = '
Select a file
'; + await settle(); + const button = holder.querySelector('.cdx-attaches__button'); + assert.equal(button.getAttribute('role'), 'button'); + assert.equal(button.getAttribute('tabindex'), '0'); + let clicks = 0; + button.addEventListener('click', () => (clicks += 1)); + button.dispatchEvent(new KeyboardEvent('keydown', { key: 'Enter', bubbles: true })); + assert.equal(clicks, 1); + assert.equal( + insertedBlockControl(holder.querySelector('.ce-block'), () => true), + button + ); + stop(); + holder.remove(); +}); From 570af2e2c344ccbf7bb05ef4a2c8a53340d41ae9 Mon Sep 17 00:00:00 2001 From: Schero94 <64200582+Schero94@users.noreply.github.com> Date: Fri, 20 Nov 2026 16:12:37 +0100 Subject: [PATCH 4/4] docs: keep the editor-field fixes under [Unreleased] after 2.8.2 Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7908cf5..03891e2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,18 @@ # Changelog +## [Unreleased] + +### Fixed (editor field: names, focus, panels, translations) + +- **Names.** The editor of a field is a group named by the field label (as Strapi's Blocks field). Inline toolbar buttons are named after their tool, the component block switch after its attribute, and the repeated Accept, Reject, Edit, Reply, Resolve and Reopen buttons say whose comment or suggestion and which text they act on. +- **Inline toolbar by keyboard.** With text selected, Alt+F10 moves focus into the inline toolbar (as in the table and column tools), the arrow keys move between its buttons, and Escape goes back to the selected text. Escape in the link input returns to the text too. The shortcut timing (Ctrl/Cmd+I, U, Shift+M, K pressed within about 150 ms of selecting) is Editor.js behaviour: its inline tool shortcuts work only once the inline toolbar was built after the debounced selection change (Editor.js 2.31 `InlineToolbar.enableShortcuts`); it is left as is. +- **Focus.** After inserting a video, audio or attachment block, focus is on its Choose button. After the Media Library dialog (Confirm, Escape or Close), the caret is in the inserted image or back where the block was inserted. After posting a reply or cancelling an edit, after sending suggestions, after Replace and Replace all, after Check links and after a grammar check or fix, focus stays on a defined control. Cancel or Escape in the template replace and version restore confirmations returns to the button that opened them. The grammar panel takes focus, and Escape closes the quality, grammar, comments and suggestions panels also when the focused button shows its tooltip. +- **States.** A comments load error shows the error with Try again instead of read-only with zero counts. "No links were checked." replaces "Link check finished: no problems" when nothing was checked. The AI dialogs show their own messages for `UNREACHABLE`, `BAD_RESPONSE`, `RESPONSE_TOO_LARGE`, `EMPTY` and `PROVIDER_ERROR`. +- **Suggest mode.** More tools offers only the entries that work while suggesting (keyboard shortcuts); the others acted on the hidden field. +- **Presence.** Joining and leaving the entry is announced once per entry, not once per field. +- **Layout and dark mode.** A blocked person photo shows its Content Security Policy notice in its own row instead of the 72 px circle. Below 650 px the **+** and block menu handles use the DS surface and border (they were white in dark mode) and 32 px targets on phones; the bottom sheet's backdrop uses the DS overlay colour. The side panel's Check is a DS button. Native checkboxes, selects and inputs in blocks follow the admin theme (`color-scheme`), and the attachment download hover, the image tool, the loader and "Nothing found" no longer show Editor.js' light colours in dark mode. +- **Translations.** The indent block tune, the embed caption and attachment title placeholders and the code languages "Plain text" and "HTML and XML" are translated in all five admin languages. + ## [2.8.2](https://github.com/Schero94/Magic-Editor-X/compare/v2.8.1...v2.8.2) (2026-11-20) @@ -16,16 +29,6 @@ - **Bold from Word was lost on paste.** Word writes `` and the check for Google Docs' `` wrapper matched the text `font-weight:normal` inside the other property. Inline styles are now read by exact property name, everywhere in the HTML import. - **"Discard changes" in the live session notice removed other people's text without asking.** It now asks first in a Strapi confirmation that says it affects everyone editing the field, then shows a notice with **Undo** (focused) that puts the previous text back for everyone. People in the same session get a notice that the field went back to the saved content, with **Restore my text**. -### Fixed (editor field: names, focus, panels, translations) - -- **Names.** The editor of a field is a group named by the field label (as Strapi's Blocks field). Inline toolbar buttons are named after their tool, the component block switch after its attribute, and the repeated Accept, Reject, Edit, Reply, Resolve and Reopen buttons say whose comment or suggestion and which text they act on. -- **Inline toolbar by keyboard.** With text selected, Alt+F10 moves focus into the inline toolbar (as in the table and column tools), the arrow keys move between its buttons, and Escape goes back to the selected text. Escape in the link input returns to the text too. The shortcut timing (Ctrl/Cmd+I, U, Shift+M, K pressed within about 150 ms of selecting) is Editor.js behaviour: its inline tool shortcuts work only once the inline toolbar was built after the debounced selection change (Editor.js 2.31 `InlineToolbar.enableShortcuts`); it is left as is. -- **Focus.** After inserting a video, audio or attachment block, focus is on its Choose button. After the Media Library dialog (Confirm, Escape or Close), the caret is in the inserted image or back where the block was inserted. After posting a reply or cancelling an edit, after sending suggestions, after Replace and Replace all, after Check links and after a grammar check or fix, focus stays on a defined control. Cancel or Escape in the template replace and version restore confirmations returns to the button that opened them. The grammar panel takes focus, and Escape closes the quality, grammar, comments and suggestions panels also when the focused button shows its tooltip. -- **States.** A comments load error shows the error with Try again instead of read-only with zero counts. "No links were checked." replaces "Link check finished: no problems" when nothing was checked. The AI dialogs show their own messages for `UNREACHABLE`, `BAD_RESPONSE`, `RESPONSE_TOO_LARGE`, `EMPTY` and `PROVIDER_ERROR`. -- **Suggest mode.** More tools offers only the entries that work while suggesting (keyboard shortcuts); the others acted on the hidden field. -- **Presence.** Joining and leaving the entry is announced once per entry, not once per field. -- **Layout and dark mode.** A blocked person photo shows its Content Security Policy notice in its own row instead of the 72 px circle. Below 650 px the **+** and block menu handles use the DS surface and border (they were white in dark mode) and 32 px targets on phones; the bottom sheet's backdrop uses the DS overlay colour. The side panel's Check is a DS button. Native checkboxes, selects and inputs in blocks follow the admin theme (`color-scheme`), and the attachment download hover, the image tool, the loader and "Nothing found" no longer show Editor.js' light colours in dark mode. -- **Translations.** The indent block tune, the embed caption and attachment title placeholders and the code languages "Plain text" and "HTML and XML" are translated in all five admin languages. ## [2.8.1](https://github.com/Schero94/Magic-Editor-X/compare/v2.8.0...v2.8.1) (2026-11-20)