Search keywords
TextField, autoFocus, NextJs, App Router
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.
- The
TextField is not focused upon the initial page load or when the page is refreshed.
- 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:
- On the initial page load.
- When the page is refreshed.
- When navigating between pages within the app.
- 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
Search keywords
TextField,autoFocus,NextJs,App RouterLatest version
Steps to reproduce
Link to live example: https://codesandbox.io/p/devbox/ecstatic-boyd-js7l82
Current behavior
When using the
TextFieldcomponent with theautoFocusprop in a Next.JS App Router project, the autofocus feature does not work as expected.TextFieldis not focused upon the initial page load or when the page is refreshed.autoFocusfeature 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
TextFieldwith theautoFocusprop to consistently focus on the input element under the following scenarios: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