最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How can I disable underline in Material-UI without removing the selection in Autocomplete? - Stack Overflow

programmeradmin1浏览0评论

I want to create Autoplete with TextField ponent without underline. I have disabled underline using InputProps={{ disableUnderline: true }} in TextField props, it did its job, but it also removed the selection bar, so the question is, how can I acplish this without removing the select bar?

I want to create Autoplete with TextField ponent without underline. I have disabled underline using InputProps={{ disableUnderline: true }} in TextField props, it did its job, but it also removed the selection bar, so the question is, how can I acplish this without removing the select bar?

Share Improve this question edited Apr 18, 2021 at 8:27 NearHuscarl 82.2k24 gold badges320 silver badges283 bronze badges asked Apr 17, 2021 at 20:59 CrazyCatCZCrazyCatCZ 552 silver badges6 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 5

To enable the dropdown list again, you need to spread all provided props in the nested property too (InputProps). So replace this line

<TextField {...params} InputProps={{ disableUnderline: true }} />

With:

<TextField {...params} InputProps={{ ...params.InputProps, disableUnderline: true }} />

Full working code:

<Autoplete
  options={top100Films}
  getOptionLabel={(option) => option.title}
  style={{ width: 300 }}
  renderInput={(params) => (
    <TextField
      {...params}
      InputProps={{ ...params.InputProps, disableUnderline: true }}
      label="Combo box"
    />
  )}
/>

Live Demo

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论