Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
thenick775 opened this issue Mar 14, 2024 · 1 comment
Assignees
Labels
component: text field This is the name of the generic UI component, not the React module! enhancement This is not a bug, nor a new feature package: material-ui Specific to @mui/material

Comments

@thenick775
Copy link

thenick775 commented Mar 14, 2024

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

@thenick775 thenick775 added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Mar 14, 2024
@zannager zannager added the component: text field This is the name of the generic UI component, not the React module! label Mar 14, 2024
@danilo-leal danilo-leal changed the title multiline TextField cannot be made to scroll horizontally [material-ui][Text Field] Multiline variant cannot be made to scroll horizontally Mar 14, 2024
@danilo-leal danilo-leal added the package: material-ui Specific to @mui/material label Mar 14, 2024
thenick775 added a commit to thenick775/gbajs3 that referenced this issue Mar 16, 2024
- see: mui/material-ui#41490

- TODO: remove !important if there ends up being another way to accomplish this through css or other configuration methods
thenick775 added a commit to thenick775/gbajs3 that referenced this issue Mar 16, 2024
- see: mui/material-ui#41490

- TODO: remove !important if there ends up being another way to accomplish this through css or other configuration methods
@ZeeshanTamboli ZeeshanTamboli added bug 🐛 Something doesn't work enhancement This is not a bug, nor a new feature and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer bug 🐛 Something doesn't work labels Mar 18, 2024
@ZeeshanTamboli
Copy link
Member

ZeeshanTamboli commented Mar 18, 2024

I believe the addition of the overflow: hidden property is meant to hide the scrollbar when the content is less than the maxRows and to not show scrollbar when the browser window is resized, potentially addressing issue #9277. However, applying this style through inline CSS may not be the optimal solution. I'll label this as an enhancement rather than a bug. If you have any suggestions, please feel free to comment or submit a pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: text field This is the name of the generic UI component, not the React module! enhancement This is not a bug, nor a new feature package: material-ui Specific to @mui/material
Projects
None yet
Development

No branches or pull requests

5 participants