DioxusLabs / DioxusLabs/dioxus

<textarea autofocus> places cursor at start if text is not empty

Open
#3,964 1 comment 0 reactions 0 assignees View on GitHub
html
Dominant language
Rust
Stars
39.1k
Forks
1.9k
Avg merge
4d 10h
Merged PRs (30d)
4

Description

**Problem**
When using a `` with the `autofocus` attribute, the element correctly receives focus upon mounting. However, if the text is already present (either via `initial_value` or a `Signal`), the cursor is always placed at the beginning of the text.

This behavior feels unintuitive for editable fields — typically, users expect the cursor to be at the end of the existing content, or at least to have control over where it goes.

**Steps To Reproduce**

Steps to reproduce the behavior:

- Create a `<textarea autofocus>` with a non-empty value.

- Run the app.

- Observe that the field gets focused, but the cursor is always at the beginning of the text.

**Expected behavior**

- Either the cursor should default to the end of the text when the field is auto-focused and non-empty.

- Or there should be a built-in way to specify cursor position (e.g. "start", "end", or a specific offset).

**Environment:**

- Dioxus version: 0.6.3
- Rust version: 1.85.1 (4eb161250 2025-03-15)
- OS info: Linux Mint 22.1
- `uname -srp`: Linux 6.8.0-56-generic x86_64
- App platform: desktop

**💡 Suggested Solution**

Ideally, this should be handled entirely within `Dioxus`, without relying on JavaScript or platform-specific workarounds. A declarative, renderer-agnostic solution would be ideal — one that works consistently across web, desktop, mobile, etc.

Thanks for the awesome work on Dioxus! 🙌

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.