简体   繁体   English

MUI自动完成从容器中生长出来 - React

[英]MUI Autocomplete growing out of container - React

I am using MUI Autocomplete and I want it to stay within the container bounds.我正在使用 MUI 自动完成,我希望它保持在容器范围内。 I am using AutoComplete inside a with the limitTags option set.我在 a 中使用 AutoComplete 并设置了 limitTags 选项。 When I click on the autocomplete, it extends out of the container.当我单击自动完成时,它会延伸到容器之外。 Is there a way to force it to be inside and just expand vertically instead of horizontally?有没有办法强制它在里面并且只是垂直扩展而不是水平扩展?

This is my code.这是我的代码。

import * as React from "react";
import Autocomplete from "@mui/material/Autocomplete";
import Grid from "@mui/material/Grid";
import TextField from "@mui/material/TextField";

export default function LimitTags() {
  return (
    <Grid container>
      <Grid item md={2}>
        <Autocomplete
          multiple
          limitTags={2}
          id="multiple-limit-tags"
          options={top100Films}
          getOptionLabel={(option) => option.title}
          defaultValue={[top100Films[13], top100Films[12], top100Films[11]]}
          renderInput={(params) => (
            <TextField {...params} label="limitTags" placeholder="Favorites" />
          )}
        />
      </Grid>
    </Grid>
  );
}

This is my codesandbox link: https://codesandbox.io/s/exciting-glade-shmjfk?file=/demo.tsx这是我的代码框链接: https://codesandbox.io/s/exciting-glade-shmjfk?file=/demo.tsx

Please advice.请指教。

I checked you codesandbox and its working as you expect on 32 inch screen, but not on small devices and this is due to the <Grid/> compoent我检查了您的代码框及其在 32 英寸屏幕上的工作方式,但在小型设备上却没有,这是由于<Grid/>组件

You can check: https://mui.com/material-ui/react-grid/您可以查看: https://mui.com/material-ui/react-grid/

Here is an example that work on both sizes:这是一个适用于两种尺寸的示例:


export default function LimitTags() {
  return (
    <Grid container>
      <Grid item  xs={3.8} md={2}>
        <Autocomplete
          multiple
          limitTags={2}
          id="multiple-limit-tags"
          options={top100Films}
          getOptionLabel={(option) => option.title}
          defaultValue={[top100Films[13], top100Films[12], top100Films[11]]}
          renderInput={(params) => (
            <TextField {...params} label="limitTags" placeholder="Favorites" />
          )}
        />
      </Grid>
    </Grid>
  );
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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