fix(scrollbar): doesn't support scrollTo, closes #1346

This commit is contained in:
07akioni 2021-10-14 03:38:45 +08:00
parent e3ef366a3a
commit f471c9bd04
5 changed files with 37 additions and 4 deletions

View File

@ -6,6 +6,7 @@
- Fix `n-data-table` fixed style does not work in group header tablecloses [#1341](https://github.com/TuSimple/naive-ui/issues/1341).
- Fix `n-data-table` has duplicate right border when it has multiple level headers.
- Fix `n-scrollbar` doesn't support `scrollTo`, closes [#1346](https://github.com/TuSimple/naive-ui/issues/1346).
### Feats

View File

@ -6,6 +6,7 @@
- 修复 `n-data-table` `fixed` 样式在表头分组不生效的问题,关闭 [#1341](https://github.com/TuSimple/naive-ui/issues/1341)
- 修复 `n-data-table` 多级表头右侧边框重复
- 修复 `n-scrollbar` 不支持 `scrollTo`,关闭 [#1346](https://github.com/TuSimple/naive-ui/issues/1346)
### Feats

View File

@ -22,3 +22,9 @@ x
| Name | Parameters | Description |
| ------- | ---------- | --------------- |
| default | `()` | Scroll content. |
### Scrollbar Methods
| Name | Type | Description |
| --- | --- | --- |
| scrollTo | `(options: { left?: number, top?: number, behavior?: ScrollBehavior }): void & (x: number, y: number) => void` | Scrolling content. |

View File

@ -22,3 +22,9 @@ x
| 名称 | 参数 | 说明 |
| ------- | ---- | -------- |
| default | `()` | 滚动内容 |
### Scrollbar Methods
| 名称 | 类型 | 说明 |
| --- | --- | --- |
| scrollTo | `(options: { left?: number, top?: number, behavior?: ScrollBehavior }): void & (x: number, y: number) => void` | 滚动内容 |

View File

@ -1,10 +1,13 @@
import { h, defineComponent, PropType } from 'vue'
import { h, defineComponent, PropType, ref } from 'vue'
import { NScrollbar } from '../../_internal'
import { ScrollbarTheme } from '../../_internal/scrollbar/styles'
import { useTheme, ThemeProps } from '../../_mixins'
import type { ExtractPublicPropTypes } from '../../_utils'
export type ScrollTo = (x: number, y: number) => void
export interface ScrollTo {
(x: number, y: number): void
(options: { left?: number, top?: number, behavior?: ScrollBehavior }): void
}
export interface ScrollbarInst {
scrollTo: ScrollTo
@ -21,8 +24,24 @@ export type ScrollbarProps = ExtractPublicPropTypes<typeof scrollbarProps>
const Scrollbar = defineComponent({
name: 'Scrollbar',
props: scrollbarProps,
setup (props, { slots }) {
return () => h(NScrollbar, props, slots)
setup () {
const scrollbarInstRef = ref<ScrollbarInst | null>(null)
const exposedMethods: ScrollbarInst = {
scrollTo: (...args: any[]) => {
scrollbarInstRef.value?.scrollTo(args[0], args[1])
}
}
return {
...exposedMethods,
scrollbarInstRef
}
},
render () {
return (
<NScrollbar ref="scrollbarInstRef" {...this.$props}>
{this.$slots}
</NScrollbar>
)
}
})