Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(auto-complete): add dropdown scroll event #2635

Merged
merged 1 commit into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions packages/web-vue/components/auto-complete/README.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ description: The auto-complete function of the input.

@import ./__demo__/footer.md

@import ./__demo__/scroll.md

## API


Expand All @@ -39,6 +41,9 @@ description: The auto-complete function of the input.
|search|Emitted when the user searches|value: `string`||
|select|Emitted when an option is selected|value: `string`||
|clear|Triggered when the user clicks the clear button|ev: `Event`|2.23.0|
|dropdown-scroll|Triggered when the drop-down scrolls|ev: `Event`|2.51.0|
|dropdown-reach-bottom|Triggered when the drop-down menu is scrolled to the bottom|ev: `Event`|2.51.0|

### `<auto-complete>` Methods

|Method|Description|Parameters|Return|version|
Expand All @@ -51,5 +56,3 @@ description: The auto-complete function of the input.
|---|---|---|:---|
|option|Display content of options|data: `OptionInfo`|2.13.0|
|footer|The footer of the popup menu box|-||


7 changes: 5 additions & 2 deletions packages/web-vue/components/auto-complete/README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ description: 输入框的自动补全功能。

@import ./__demo__/footer.md

@import ./__demo__/scroll.md

## API


Expand All @@ -37,6 +39,9 @@ description: 输入框的自动补全功能。
|search|用户搜索时触发|value: `string`||
|select|选择选项时触发|value: `string`||
|clear|用户点击清除按钮时触发|ev: `Event`|2.23.0|
|dropdown-scroll|下拉菜单发生滚动时触发|ev: `Event`|2.51.0|
|dropdown-reach-bottom|下拉菜单滚动到底部时触发|ev: `Event`|2.51.0|

### `<auto-complete>` Methods

|方法名|描述|参数|返回值|版本|
Expand All @@ -49,5 +54,3 @@ description: 输入框的自动补全功能。
|---|:---:|---|:---|
|option|选项内容|data: `OptionInfo`|2.13.0|
|footer|弹出框的页脚|-||


52 changes: 52 additions & 0 deletions packages/web-vue/components/auto-complete/__demo__/scroll.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
```yaml
title:
zh-CN: 下拉菜单滚动
en-US: Dropdown Scroll
```

## zh-CN

可以通过 `dropdown-scroll` 监听下拉菜单的滚动事件。或者通过 `dropdown-reach-bottom` 监听下拉菜单滚动到底部的事件。

---

## en-US

You can monitor the scroll event of the drop-down menu through `dropdown-scroll`. Or use `dropdown-reach-bottom` to monitor the event of the drop-down menu scrolling to the bottom.

---

```vue
<template>
<a-auto-complete
:data="data"
:style="{ width: '360px' }"
placeholder="please enter something"
@dropdown-scroll="handleScroll"
@dropdown-reach-bottom="handleReachBottom"
/>
</template>

<script>
import { ref } from 'vue'

export default {
setup() {
const data = ref([...Array(100)].map((_, index) => `option-${index}`))

const handleScroll = (ev) => {
console.log('scroll', ev)
}
const handleReachBottom = (ev) => {
console.log('reach the bottom', ev)
}

return {
data,
handleScroll,
handleReachBottom
}
},
}
</script>
```
24 changes: 24 additions & 0 deletions packages/web-vue/components/auto-complete/auto-complete.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,20 @@ export default defineComponent({
* @version 2.23.0
*/
'clear': (ev: Event) => true,
/**
* @zh 下拉菜单发生滚动时触发
* @en Triggered when the drop-down scrolls
* @param {Event} ev
* @version 2.51.0
*/
'dropdownScroll': (ev: Event) => true,
/**
* @zh 下拉菜单滚动到底部时触发
* @en Triggered when the drop-down menu is scrolled to the bottom
* @param {Event} ev
* @version 2.51.0
*/
'dropdownReachBottom': (ev: Event) => true,
},
/**
* @zh 弹出框的页脚
Expand Down Expand Up @@ -240,6 +254,14 @@ export default defineComponent({
handleChange(value);
};

const handleDropdownScroll = (e: Event) => {
emit('dropdownScroll', e);
};

const handleDropdownReachBottom = (e: Event) => {
emit('dropdownReachBottom', e);
};

const { validOptions, optionInfoMap, validOptionInfos, handleKeyDown } =
useSelect({
options: data,
Expand Down Expand Up @@ -308,6 +330,8 @@ export default defineComponent({
'footer': slots.footer,
}}
virtualList={Boolean(props.virtualListProps)}
onScroll={handleDropdownScroll}
onReachBottom={handleDropdownReachBottom}
/>
);
};
Expand Down
Loading