Skip to content

fix(readonly): restore autofocus when switching to editable mode - #3059

Open
Anurag-S1ngh wants to merge 6 commits into
codex-team:nextfrom
Anurag-S1ngh:fix/2316-autofocus-after-readonly
Open

Anurag-S1ngh wants to merge 6 commits into
codex-team:nextfrom
Anurag-S1ngh:fix/2316-autofocus-after-readonly

Conversation

@Anurag-S1ngh

Copy link
Copy Markdown
Contributor

Summary

When the editor is initialized with readOnly: true and autofocus: true, switching back to editable mode re-renders the blocks but never places the caret, so keyboard input does not reach the editor.

Changes

  • After the read-only toggle finishes re-rendering, set the caret to the first block when the editor just became editable and autofocus is enabled.
  • Add a Cypress test covering the read-only to editable transition with autofocus.

Testing

  • Reproduced on next with a custom block tool: before the change document.activeElement stayed BODY after enabling editing. After the change the first block's contenteditable is focused and the selection is inside the editor.
  • Verified that toggling back to read-only does not move focus.
  • eslint passes with 0 errors. The Cypress suite was not run locally because the Cypress binary was not installed.

Closes #2316

When the editor starts in read-only mode with autofocus enabled, switching back to editable mode re-renders the blocks but never sets the caret, so keyboard input does not reach the editor. Set the caret to the first block after rendering.

Fixes codex-team#2316

@neSpecc neSpecc left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please add a Fix line to docs/CHANGELOG.md under 2.32.0.

Comment thread src/components/modules/readonly.ts Resolved
Comment thread test/cypress/tests/readOnly.cy.ts Resolved
@Anurag-S1ngh

Copy link
Copy Markdown
Contributor Author

Added to docs/CHANGELOG.md under 2.32.0.

…after-readonly

# Conflicts:
#	docs/CHANGELOG.md
@neSpecc

neSpecc commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

The main issue is still not fixed: #3059 (comment)

and this #3059 (comment)

@Anurag-S1ngh

Copy link
Copy Markdown
Contributor Author

Autofocus is now one-shot: when the editor starts read-only it is recorded and applied on the first switch to editable, then cleared. Added tests for autofocus disabled, switching back to read-only, and an editor that started editable. All Cypress specs pass.

@Anurag-S1ngh

Copy link
Copy Markdown
Contributor Author

Cypress fails at copy-paste.cy.ts with * is not a valid URL on all browsers. The same failure shows up on other PRs, so it does not look related to this change. Locally all 381 specs pass and ESLint is green.

@neSpecc

neSpecc commented Nov 29, 2026

Copy link
Copy Markdown
Member

@Anurag-S1ngh I've fixes Cypress, please update a branch

@Anurag-S1ngh

Copy link
Copy Markdown
Contributor Author

Merged upstream/next into the branch and resolved the conflicts in readonly.ts and readOnly.cy.ts. Cypress passes on chrome, edge and firefox now.

This branch has not been deployed

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

defaultBlock, autoFocus does not work when the editor is initialized as readOnly

2 participants