docs: FAQ about dropdownRender (#37906)

This commit is contained in:
二货爱吃白萝卜 2022-10-09 17:47:43 +08:00 committed by GitHub
parent f7d9398d0b
commit 91586f5dcd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 0 deletions

View File

@ -115,6 +115,25 @@ It's caused by option with different `label` and `value`. You can use `optionFil
You can control it by `open` prop: [codesandbox](https://codesandbox.io/s/ji-ben-shi-yong-antd-4-21-7-forked-gnp4cy?file=/demo.js).
### I don't want dropdown close when click inside `dropdownRender`?
Select will close when it lose focus. You can prevent event to handle this:
```jsx
<Select
dropdownRender={() => (
<div
onMouseDown={e => {
e.preventDefault();
e.stopPropagation();
}}
>
Some Content
</div>
)}
/>
```
### Why sometime customize Option cause scroll break?
Virtual scroll internal set item height as `32px`. You need to adjust `listItemHeight` when your option height is less and `listHeight` config list container height:

View File

@ -116,6 +116,25 @@ cover: https://gw.alipayobjects.com/zos/alicdn/_0XzgOis7/Select.svg
你可以使用受控模式,手动设置 `open` 属性:[codesandbox](https://codesandbox.io/s/ji-ben-shi-yong-antd-4-21-7-forked-gnp4cy?file=/demo.js)。
### 反过来希望点击 `dropdownRender` 里元素不消失该怎么办?
Select 当失去焦点时会关闭下拉框,如果你可以通过阻止默认行为避免丢失焦点导致的关闭:
```jsx
<Select
dropdownRender={() => (
<div
onMouseDown={e => {
e.preventDefault();
e.stopPropagation();
}}
>
Some Content
</div>
)}
/>
```
### 自定义 Option 样式导致滚动异常怎么办?
这是由于虚拟滚动默认选项高度为 `32px`,如果你的选项高度小于该值则需要通过 `listItemHeight` 属性调整,而 `listHeight` 用于设置滚动容器高度: