Skip to content

fix: prevent page jump when clicking anchor links in editor#75579

Open
arpiiitver wants to merge 1 commit intoWordPress:trunkfrom
arpiiitver:fix/anchor-link-jump
Open

fix: prevent page jump when clicking anchor links in editor#75579
arpiiitver wants to merge 1 commit intoWordPress:trunkfrom
arpiiitver:fix/anchor-link-jump

Conversation

@arpiiitver
Copy link

Description

This PR fixes an issue where clicking an anchor link (e.g., href="#" or href="#section") inside the editor causes the page to scroll/jump unexpectedly.

Motivation

When a user tries to edit an existing anchor link, the browser's default behavior triggers a scroll event before the Link UI popover can be used effectively. This disrupts the editing flow and causes the user to lose their place in the document.

Fixes #72505.

Changes

  • Updated packages/format-library/src/link/index.js to include event.preventDefault() in the handleClick handler.
  • This ensures the editor intercepts the click event, preventing the browser's default navigation/scroll behavior while still opening the Link UI.

Testing Instructions

  1. Create a new Post.
  2. Add enough content to make the page scrollable.
  3. Select text near the bottom and add a link with href="#".
  4. Click the link text.
  5. Verify that the Link UI popover opens without the page jumping to the top.

@arpiiitver arpiiitver requested a review from ellatrix as a code owner February 16, 2026 16:54
@github-actions github-actions bot added the [Package] Format library /packages/format-library label Feb 16, 2026
@github-actions
Copy link

github-actions bot commented Feb 16, 2026

Warning: Type of PR label mismatch

To merge this PR, it requires exactly 1 label indicating the type of PR. Other labels are optional and not being checked here.

  • Required label: Any label starting with [Type].
  • Labels found: [Type] Bug, [Type] Enhancement, [Package] Format library, First-time Contributor.

Read more about Type labels in Gutenberg. Don't worry if you don't have the required permissions to add labels; the PR reviewer should be able to help with the task.

@github-actions
Copy link

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Unlinked Accounts

The following contributors have not linked their GitHub and WordPress.org accounts: @arpiiitver, @Lahari-v, @smerriman.

Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Unlinked contributors: arpiiitver, Lahari-v, smerriman.

Co-authored-by: ellatrix <ellatrix@git.wordpress.org>
Co-authored-by: SirLouen <sirlouen@git.wordpress.org>
Co-authored-by: ozgursar <ozgursar@git.wordpress.org>
Co-authored-by: JosVelasco <josvelasco@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@github-actions github-actions bot added the First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository label Feb 16, 2026
@github-actions
Copy link

👋 Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @arpiiitver! In case you missed it, we'd love to have you join us in our Slack community.

If you want to learn more about WordPress development in general, check out the Core Handbook full of helpful information.

@Mamaduka Mamaduka added [Type] Bug An existing feature does not function as intended [Type] Enhancement A suggestion for improvement. labels Feb 17, 2026
@Mamaduka Mamaduka requested review from getdave and jeryj February 17, 2026 08:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository [Package] Format library /packages/format-library [Type] Bug An existing feature does not function as intended [Type] Enhancement A suggestion for improvement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Page jumps away when trying to edit an anchor link

2 participants