[TextField] Cursor jumps to beginning when clicking outside the default line-height area

Open
#44,395 4 comments 0 reactions 1 assignee View on GitHub

@siriwatknp is already working on this.

Since Nov 14, 2024.

Assessment

This issue has not been assessed yet.

Description

browser: Safari external dependency scope: text field
Steps to reproduce

Link to live example: (required)
Go to the TextField demo page on MUI’s website.

Steps:

  1. Type some text into any TextField component.
  2. Click above the input area, especially outside the text’s line-height area (e.g., towards the top of the field).

https://github.com/user-attachments/assets/b8534f17-d429-49e1-9c82-951db7292223

3 .Observe the cursor behavior—it should ideally position itself where you clicked but instead jumps to the beginning of the text. Unless you click in the small native input line height.

Current behavior

When using the TextField component, clicking within the input area but outside the default line-height (e.g., in the top half of the input area) causes the cursor to jump to the beginning of the text instead of positioning where the click occurred. This behavior causes the input field to respond in an unexpected and inconsistent way for users.

Expected behavior

The cursor should appear at the exact location where the user clicks within the input area, aligning with standard input field behavior and enhancing user experience.

Context

This issue affects the user experience by causing unexpected cursor jumps within the input area. It occurs even with the default TextField styling, making it a general issue in applications that use MUI’s TextField component.

Your environment
npx @mui/envinfo
  System:
    OS: macOS 14.6.1
  Binaries:
    Node: 20.16.0 - /opt/homebrew/opt/node@20/bin/node
    npm: 10.8.1 - /opt/homebrew/opt/node@20/bin/npm
    pnpm: Not Found
  Browsers:
    Chrome: 130.0.6723.117
    Edge: Not Found
    Safari: 17.6
  npmPackages:
    @emotion/react: ^11.11.3 => 11.11.3 
    @emotion/styled: ^11.11.0 => 11.11.0 
    @mui/base: 5.0.0-beta.61 
    @mui/core-downloads-tracker: 6.1.6 
    @mui/icons-material: ^6.1.6 => 6.1.6 
    @mui/lab: ^6.0.0-beta.14 => 6.0.0-beta.14 
    @mui/material: ^6.1.6 => 6.1.6 
    @mui/private-theming: 6.1.6 
    @mui/styled-engine: 6.1.6 
    @mui/system: ^6.1.6 => 6.1.6 
    @mui/types: 7.2.19 
    @mui/utils: 5.15.9 
    @mui/x-charts: ^6.18.7 => 6.18.7 
    @mui/x-data-grid: ^6.18.4 => 6.18.6 
    @types/react: 18.3.12 
    react: ^18.2.0 => 18.2.0 
    react-dom: ^18.2.0 => 18.2.0 
    typescript: 4.9.5 

Search keywords: TextField cursor placement , TextField line-height issue, TextField cursor misalignment, MUI TextField cursor jump

Dominant language
JavaScript
Stars
99.1k
Forks
32.5k
Avg merge
2d 17h
Merged PRs (30d)
106

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from mui/material-ui

All issues in mui/material-ui

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.