Skip to content

Commit

Permalink
fix(back-top): add window as default value of target
Browse files Browse the repository at this point in the history
  • Loading branch information
BeADre committed May 19, 2021
1 parent 80f2ad8 commit f293a94
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 18 deletions.
6 changes: 2 additions & 4 deletions packages/varlet-ui/src/back-top/BackTop.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default defineComponent({
},
props,
setup(props) {
const element: Ref<Element | null> = ref(null)
const element: Ref<Element | Window> = ref(window)
const show: Ref<boolean> = ref(false)
const click = () => {
Expand Down Expand Up @@ -57,13 +57,11 @@ export default defineComponent({
}
onMounted(() => {
element.value = getElement()
if (!element.value) return
if (props.target) element.value = getElement()
element.value.addEventListener('scroll', throttleScroll)
})
onBeforeUnmount(() => {
if (!element.value) return
element.value.removeEventListener('scroll', throttleScroll)
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`test backTop example 1`] = `
"<div class=\\"var-back-top__example\\">
"<div>
<div class=\\"var-cell\\">
<!--v-if-->
<div class=\\"var-cell__content\\">
Expand Down
1 change: 1 addition & 0 deletions packages/varlet-ui/src/back-top/__tests__/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,6 @@ test('test backTop props', async () => {

expect(clickHandle).toHaveBeenCalledTimes(1)


wrapper.unmount()
})
4 changes: 2 additions & 2 deletions packages/varlet-ui/src/back-top/docs/en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ createApp().use(BackTop)
### Basic Usage

```html
<div class="var-back-top__example">
<div>
<var-cell v-for="list in lists" :key="list">Scroll to bottom {{ list }}</var-cell>
<var-back-top target=".var-back-top__example" :duration="300" />
<var-back-top :duration="300" />
</div>
```
```javascript
Expand Down
4 changes: 2 additions & 2 deletions packages/varlet-ui/src/back-top/docs/zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ createApp().use(BackTop)
### 基本使用

```html
<div class="var-back-top__example">
<div>
<var-cell v-for="list in lists" :key="list">Scroll to bottom {{ list }}</var-cell>
<var-back-top target=".var-back-top__example" :duration="300" />
<var-back-top :duration="300" />
</div>
```
```javascript
Expand Down
11 changes: 2 additions & 9 deletions packages/varlet-ui/src/back-top/example/index.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<div class="var-back-top__example">
<div>
<var-cell v-for="list in lists" :key="list">Scroll to bottom {{ list }}</var-cell>
<var-back-top target=".var-back-top__example" :duration="300" />
<var-back-top :duration="300" />
</div>
</template>

Expand All @@ -24,10 +24,3 @@ export default {
},
}
</script>

<style scoped>
.var-back-top__example {
height: calc(100vh - 40px);
overflow: auto;
}
</style>

0 comments on commit f293a94

Please sign in to comment.