From e61d08ed291f9a433166df87f25f9d5a7a79c75b Mon Sep 17 00:00:00 2001 From: kooriookami <38392315+kooriookami@users.noreply.github.com> Date: Mon, 5 Jul 2021 09:10:50 +0800 Subject: [PATCH] feat(scrollbar): add always show props and control scrollbar methods (#2428) * feat(scrollbar): add always show props and control scrollbar methods re #1751 #2004 * feat: update for review --- .../scrollbar/__tests__/scrollbar.spec.ts | 46 ++++++++++++++++ packages/scrollbar/src/bar.vue | 3 +- packages/scrollbar/src/index.vue | 40 ++++++++++++-- website/demo-styles/scrollbar.scss | 6 ++- website/docs/en-US/scrollbar.md | 54 ++++++++++++++++++- website/docs/es/scrollbar.md | 54 ++++++++++++++++++- website/docs/fr-FR/scrollbar.md | 54 ++++++++++++++++++- website/docs/jp/scrollbar.md | 54 ++++++++++++++++++- website/docs/zh-CN/scrollbar.md | 54 ++++++++++++++++++- 9 files changed, 355 insertions(+), 10 deletions(-) diff --git a/packages/scrollbar/__tests__/scrollbar.spec.ts b/packages/scrollbar/__tests__/scrollbar.spec.ts index 30c928d8e1..e6e65ae2f4 100644 --- a/packages/scrollbar/__tests__/scrollbar.spec.ts +++ b/packages/scrollbar/__tests__/scrollbar.spec.ts @@ -1,3 +1,4 @@ +import { nextTick } from 'vue' import { mount } from '@vue/test-utils' import { defineGetter, makeScroll } from '@element-plus/test-utils' import Scrollbar from '../src/index.vue' @@ -110,4 +111,49 @@ describe('ScrollBar', () => { expect(wrapper.find('.el-scrollbar__wrap').attributes('style')).toContain('max-height: 200px;') }) + + test('should render always props', async () => { + const outerHeight = 200 + const innerHeight = 500 + const wrapper = _mount(` + +
+
+ `) + + expect(wrapper.find('.el-scrollbar__bar').attributes('style')).toBeFalsy() + }) + + test('set scrollTop & scrollLeft', async () => { + const outerHeight = 200 + const innerHeight = 500 + const outerWidth = 200 + const innerWidth = 500 + const wrapper = _mount(` + +
+
+ `) + + const scrollbar = wrapper.vm.$refs.scrollbar as any + const scrollDom = wrapper.find('.el-scrollbar__wrap').element + + const clientHeightRestore = defineGetter(scrollDom, 'clientHeight', outerHeight) + const scrollHeightRestore = defineGetter(scrollDom, 'scrollHeight', innerHeight) + const clientWidthRestore = defineGetter(scrollDom, 'clientWidth', outerWidth) + const scrollWidthRestore = defineGetter(scrollDom, 'scrollWidth', innerWidth) + + scrollbar.setScrollTop(100) + await nextTick() + scrollbar.setScrollLeft(100) + await nextTick() + + expect(wrapper.find('.is-vertical div').attributes('style')).toContain('height: 40%; transform: translateY(0%); webkit-transform: translateY(0%);') + expect(wrapper.find('.is-horizontal div').attributes('style')).toContain('width: 40%; transform: translateX(0%); webkit-transform: translateX(0%);') + + clientHeightRestore() + scrollHeightRestore() + clientWidthRestore() + scrollWidthRestore() + }) }) diff --git a/packages/scrollbar/src/bar.vue b/packages/scrollbar/src/bar.vue index ca62112571..96b71cec0f 100644 --- a/packages/scrollbar/src/bar.vue +++ b/packages/scrollbar/src/bar.vue @@ -1,7 +1,7 @@ +``` + +::: + ### Scrollbar Attributes | Attribute | Description | Type | Accepted Values | Default | @@ -77,9 +121,17 @@ Used to replace the browser's native scrollbar. | view-class | class of view | string | — | — | | noresize | do not respond to container size changes, if the container size does not change, it is better to set it to optimize performance | boolean | — | false | | tag | element tag of the view | string | — | div | +| always | always show scrollbar | boolean | — | false | -### Events +### Scrollbar Events | Event Name | Description | Parameters | |---------- |-------- |---------- | | scroll | triggers when scrolling | distance of scrolling { scrollLeft, scrollTop }| + +### Scrollbar Methods + +| Method | Description | Parameters | +| ---- | ---- | ---- | +| setScrollTop | Set distance to scroll top | (scrollTop: number) +| setScrollLeft | Set distance to scroll left | (scrollLeft: number) diff --git a/website/docs/es/scrollbar.md b/website/docs/es/scrollbar.md index 52e26045d4..f628af892a 100644 --- a/website/docs/es/scrollbar.md +++ b/website/docs/es/scrollbar.md @@ -7,6 +7,7 @@ Used to replace the browser's native scrollbar. :::demo Use `height` property to set the height of the scrollbar, or if not set, it adapts according to the parent container height. ```html +

{{ item }}

@@ -19,6 +20,7 @@ Used to replace the browser's native scrollbar. :::demo When the element width is greater than the scrollbar width, the horizontal scrollbar is displayed. ```html +

{{ item }}

@@ -33,6 +35,7 @@ Used to replace the browser's native scrollbar. :::demo The scrollbar is displayed only when the element height exceeds the max height. ```html +