简体   繁体   中英

How can I make the child of a Material UI TableCell Component fill the cell's height?

I'm using MUI v5 for a table. The table has two columns where cells contain multiline TextFields. I want the TextFields to completely fill the cell area. The problem is that once you start entering lines into the text field in one column, the height of the textfield in the other column remains the same, it doesn't fill out the table cell. Image: 在此处输入图片说明

Red is the backgroundColor of the TableCell, yellow is the backgroundColor of the TextField. I don't want to see any red, I want the textfield in the left column to increase its height as data in the right textfield is added.

I've tried different CSS combinations with height 100% and positions. I also can't use flexbox on the TableCell and flexGrow on the Input because that breaks the TableCell and stops it from filling up the height of the row.

Code example: https://codesandbox.io/s/mui-playground-forked-xst8h?file=/src/containers/app.js

import React from "react";
import * as material from "@material-ui/core";

const App = () => (
  <material.TableContainer component={material.Paper}>
    <material.Table aria-label="simple table" stickyHeader={true} size="small">
      <material.TableBody>
        <material.TableRow>
          <material.TableCell
            align="center"
            style={{
              backgroundColor: "red",
              padding: 0,
              height: "100%"
            }}
          >
            <material.TextField
              multiline
              variant="outlined"
              style={{
                flexGrow: 1,
                height: "100%",
                width: "100%",
                backgroundColor: "yellow"
              }}
            />
          </material.TableCell>

          <material.TableCell
            align="center"
            style={{
              backgroundColor: "red",
              padding: 0
            }}
          >
            <material.TextField
              multiline
              variant="outlined"
              style={{
                height: "100%",
                width: "100%",
                backgroundColor: "yellow"
              }}
            />
          </material.TableCell>
        </material.TableRow>
      </material.TableBody>
    </material.Table>
  </material.TableContainer>
);
export default App;

You need to set height: 0 to the td element and then set height: 100% to the textarea element. Also need to set for .MuiOutlinedInput-inputMultiline class height: 100%

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM