MUI多选组件下拉框跳转问题与悬停打开功能实现咨询
Material UI 多选组件使用问题求助
我在使用Material UI的multiple select多选组件时遇到两个无法解决的问题,恳请各位开发者提供指导方向:
- 选中下拉项时下拉框会出现跳动移位的情况,我已经尝试过添加
MenuProps={{ variant: "menu", getContentAnchorEl: null }}这类方案(可参考下方代码),仍未解决问题; - 我需要实现鼠标悬停时自动展开下拉框的效果,查阅了Select API和Menu Props API相关文档,都没有找到对应的实现方案。
我的代码示例
<FormControl id={title} className={classes.formControl} variant="filled" size="small" > <InputLabel id={title}> {title} </InputLabel> <Select MenuProps={ PaperProps: { style: { maxHeight: ITEM_HEIGHT * 4 + ITEM_PADDING_TOP, width: 270, }, }, variant: "menu", getContentAnchorEl: null, } disableUnderline labelId={title} id={includes} multiple value={selectedValues} input={<Input />} renderValue={(selected) => ( <div> {selected.map((value) => ( <Chip key={value} label={value}/> ))} </div> )} > <MenuItem key={filter.categoryNameWebsite} value={filter.categoryNameWebsite} > //some logic </MenuItem> </Select> </FormControl>
补充说明
- 问题1后续通过NearHuscarl的帮助定位到,该问题与Material UI无关:选中下拉项时会修改URL路径,我所使用的Next.js的useRouter默认scroll配置为true,将其修改为false后,跳动移位问题已解决。
- 问题2可参考NearHuscarl提供的解决方案。
内容的提问来源于stack exchange,提问作者Ewax_Du
相关产品推荐
相关产品推荐

