Skip to content

Page scrolls when clicking a toolbar input #342

Description

@johannesmutter

What happens

Select some text, then click an input in the toolbar (for example the link URL field). The page scrolls, even though nothing should move.

Why

When the canvas loses focus to the input, Svedit re-renders the current selection. At the end of that, it scrolls the selected element into view:

// src/lib/Svedit.svelte (render_selection)
const selected_element = focus_node.parentElement;
setTimeout(() => {
	if (selected_element?.isConnected) {
		selected_element.scrollIntoView({ block: 'nearest', inline: 'nearest' });
	}
}, 0);

The comment above this code already mentions the case "app UI focuses an external input" — but the check only asks whether the element still exists, not whether the user has moved on to a toolbar input. So the scroll fires anyway.

On iOS this stacks with Safari's own behavior of scrolling the page to bring a focused input above the keyboard, which makes the jump worse.

Suggested fix

  • In the delayed scroll above, do nothing when the canvas is no longer focused: the user is interacting with app UI, so nothing should move.
  • Where the app focuses a toolbar input from code, use input.focus({ preventScroll: true }).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions