mui / mui/material-ui

[material-ui][Text Field] Multiline variant cannot be made to scroll horizontally

Open
#41,490 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

scope: text field type: enhancement waiting for 👍
Dominant language
JavaScript
Stars
99.1k
Forks
32.5k
Avg merge
2d 17h
Merged PRs (30d)
106

Description

Summary

The TextareaAutosize when rendered by a TextField with multiline applies overflow: hidden to the resulting textarea dom element as an inline style in the current implementation.

This prevents the usecase I have, which is a textarea form input element that can grow vertically based on the size of the text contents, while also respecting whitespace and scrolling in the horizontal direction.

The fix should be as simple as splitting the overflow into overflow-x and overflow-y and applying these as css instead of inline styles so they can be overwritten.

Examples

https://github.com/mui/material-ui/blob/master/packages/mui-base/src/TextareaAutosize/TextareaAutosize.tsx#L135 (existing implementation)

import { TextField } from '@mui/material';

...
<TextField
  error={!!errors?.someInput}
  label="Some label"
  InputLabelProps={{
    shrink: true
  }}
  multiline
  fullWidth
  minRows={6}
  variant="outlined"
  InputProps={{
    sx: {
      ['textarea']: {
        whiteSpace: 'pre',
        overflowX: 'auto' // requires !important, cannot be accessed or overwritten otherwise
      }
    }
  }}
  helperText={errors?.someInput?.message}
  {...register('someInput')}
/>
...

Desired configurable behavior in in mp4 format:
Desired behavior

Motivation

I am trying to make aTextfield that renders as a textarea, while allowing me to scroll horizontally while respecting whitespace. Preserving the behavior of: expanding vertically dynamically based on the users input, as many lines as necessary without restriction (the same as the current TextareaAutosize implementation).

I know I could assign a max number of rows. But I think there is a valid usecase with the want to expand vertically in an unlimited fashion within a scroll container, while also being able to override the inline overflow style.

Search keywords: textfield textarea mui core

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.

Research direction

Start at packages/mui-base/src/TextareaAutosize/TextareaAutosize.tsx around line 135, where the textarea's overflow style is applied. Verify how the TextField multiline variant derives this element's styles, then confirm that horizontal overflow can be configured without !important while vertical autosizing and whitespace preservation remain intact.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, react
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.