Skip to content

Fix autofocus behavior to prevent unwanted scrolling when disabled#6864

Closed
Copilot wants to merge 1 commit intodevelopfrom
copilot/fix-79fe7e5d-bdc9-4e7a-b802-63625e2fd1cc
Closed

Fix autofocus behavior to prevent unwanted scrolling when disabled#6864
Copilot wants to merge 1 commit intodevelopfrom
copilot/fix-79fe7e5d-bdc9-4e7a-b802-63625e2fd1cc

Conversation

Copy link

Copilot AI commented Aug 23, 2025

Fixes issue #4235 where setting autofocus: false or autofocus: null still caused the page to scroll to the editor on mount.

Problem

The editor was unconditionally calling the focus command during initialization, even when autofocus was explicitly disabled:

// In Editor.ts mount() method
window.setTimeout(() => {
  this.commands.focus(this.options.autofocus) // Called regardless of autofocus value
  this.emit('create', { editor: this })
}, 0)

This caused unwanted scrolling behavior when editors were positioned below the fold, particularly problematic in modals or long forms where users didn't want the page to jump to the editor.

Solution

Added a conditional check to only call the focus command when autofocus should actually focus the editor:

// Only focus if autofocus is truthy and not false
if (this.options.autofocus !== false && this.options.autofocus !== null) {
  this.commands.focus(this.options.autofocus)
}

This ensures:

  • autofocus: false - No focus/scroll behavior ✅
  • autofocus: null - No focus/scroll behavior ✅
  • autofocus: true - Focuses at start (existing behavior) ✅
  • autofocus: 'start' - Focuses at start ✅
  • autofocus: 'end' - Focuses at end ✅
  • autofocus: number - Focuses at position ✅

Testing

  • Verified existing demos continue to work with autofocus: true
  • Created comprehensive test demo at demos/src/Extensions/AutofocusTest/React/
  • Built and tested core and React packages successfully

The fix is minimal and surgical, addressing the exact issue without breaking any existing functionality.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • download.cypress.io
    • Triggering command: node index.js --exec install (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@changeset-bot
Copy link

changeset-bot bot commented Aug 23, 2025

⚠️ No Changeset found

Latest commit: 94ef703

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@netlify
Copy link

netlify bot commented Aug 23, 2025

Deploy Preview for tiptap-embed ready!

Name Link
🔨 Latest commit 94ef703
🔍 Latest deploy log https://app.netlify.com/projects/tiptap-embed/deploys/68a9e51ccb6b110008a9fc0d
😎 Deploy Preview https://deploy-preview-6864--tiptap-embed.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@bdbch bdbch closed this Aug 23, 2025
Copilot AI changed the title [WIP] I want to work on issue @ueberdosis/tiptap/issues/4235 Fix autofocus behavior to prevent unwanted scrolling when disabled Aug 23, 2025
Copilot AI requested a review from bdbch August 23, 2025 16:08
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.

2 participants