Skip to content

[Text Field] autoFocus prop not working consistently in Next.js #40397

@aayush-makwana

Description

@aayush-makwana

Search keywords

TextField, autoFocus, NextJs, App Router

Latest version

  • I have tested the latest version

Steps to reproduce

Link to live example: https://codesandbox.io/p/devbox/ecstatic-boyd-js7l82

Current behavior

When using the TextField component with the autoFocus prop in a Next.JS App Router project, the autofocus feature does not work as expected.

  1. The TextField is not focused upon the initial page load or when the page is refreshed.
  2. However, the autoFocus feature works correctly when there is a tab change in the browser window or when navigating between pages within the app.

Expected behavior

We expect the TextField with the autoFocus prop to consistently focus on the input element under the following scenarios:

  1. On the initial page load.
  2. When the page is refreshed.
  3. When navigating between pages within the app.
  4. When there is a tab change in the browser window.

This consistency in autofocus behavior is crucial for a smoother user experience in our Next.JS App Router project.

Context

No response

Your environment

npx @mui/envinfo
  System:
    OS: Windows 10 10.0.19045
  Binaries:
    Node: 20.9.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.19 - ~\AppData\Roaming\npm\yarn.CMD 
    npm: 10.1.0 - C:\Program Files\nodejs\npm.CMD  
  Browsers:
    Chrome: Not Found
    Edge: Chromium (120.0.2210.91)
  npmPackages:
    @emotion/react: latest => 11.11.3
    @emotion/styled: latest => 11.11.0
    @mui/base:  5.0.0-beta.29
    @mui/core-downloads-tracker:  5.15.2
    @mui/icons-material: latest => 5.15.2
    @mui/material: latest => 5.15.2
    @mui/private-theming:  5.15.2
    @mui/styled-engine:  5.15.2
    @mui/system:  5.15.2
    @mui/types:  7.2.11
    @mui/utils:  5.15.2
    @types/react: latest => 18.2.46
    react: latest => 18.2.0
    react-dom: latest => 18.2.0
    typescript: latest => 5.3.3

Metadata

Metadata

Assignees

Labels

scope: text fieldChanges related to the text field.type: bugIt doesn't behave as expected.
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions