MUI 5自动完成的残疾港口支柱不起作用

发布于 2025-01-22 13:07:31 字数 1005 浏览 4 评论 0原文

我正在使用以前的MUI版本4.11.4,其中包括自动完成组件,并且一切都与DisablePortal Prop效果很好。

但是,我现在正在使用MUI 5,并且自动完成下拉列表有时在顶部显示,而不是总是按照我想要的。

<Autocomplete
      disablePortal={true}
      id='controlled-demo'
      ref={idRef}
      name={id.current}
      onChange={(e, value) => {
        const id = idRef.current.getAttribute('name');
        handleOptionChange(e, value, id);
      }}
      options={getExercisesByCategoryAndMusclegroup(exercise)}
      getOptionLabel={(option) => `${option.title}`}
      isOptionEqualToValue={(option, value) => option.title === value.title}
      renderInput={(params) => (
        <TextField
          {...params}
          name='exercise'
          // onChange={(e, value) => handleOptionChange(e, value)}
          label='Search exercise...'
          variant='outlined'
          size={isMatched ? 'small' : 'medium'}
        />
      )}
/>

我尝试使用自定义的Popper组件,因为我在另一篇文章上看到了“底部”的位置,但这无法解决我的问题。

新V5有错误吗?还有其他人正在经历这个吗?

I was using previous Mui version 4.11.4 with the Autocomplete component and everything worked well with the disablePortal prop.

However, i am using Mui 5 now and the autocomplete dropdown list sometimes show on top instead of always being on the bottom as what i wanted.

<Autocomplete
      disablePortal={true}
      id='controlled-demo'
      ref={idRef}
      name={id.current}
      onChange={(e, value) => {
        const id = idRef.current.getAttribute('name');
        handleOptionChange(e, value, id);
      }}
      options={getExercisesByCategoryAndMusclegroup(exercise)}
      getOptionLabel={(option) => `${option.title}`}
      isOptionEqualToValue={(option, value) => option.title === value.title}
      renderInput={(params) => (
        <TextField
          {...params}
          name='exercise'
          // onChange={(e, value) => handleOptionChange(e, value)}
          label='Search exercise...'
          variant='outlined'
          size={isMatched ? 'small' : 'medium'}
        />
      )}
/>

I've tried using a custom Popper component as i saw on another post setting the placement to 'bottom' but that didnt resolve my issue.

Is there a bug to the new v5? Anyone else is experiencing this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

段念尘 2025-01-29 13:07:31

我不知道这是否是MUI V5中的错误,但是对我有用的是简单地删除disableportal prop,它会自动将下拉列表的位置设置在底部的任何数字列表中的元素。

I don't know if this is a bug in MUI v5, but what worked for me is to simply remove the disablePortal prop, which automatically set the placement of the dropdown list to the bottom for any number of elements in the list.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文