diff --git a/packages/components/scrollbar/__tests__/scrollbar.test.tsx b/packages/components/scrollbar/__tests__/scrollbar.test.tsx index 9d4aa24eb8..a313f95c7d 100644 --- a/packages/components/scrollbar/__tests__/scrollbar.test.tsx +++ b/packages/components/scrollbar/__tests__/scrollbar.test.tsx @@ -30,11 +30,11 @@ describe('ScrollBar', () => { await makeScroll(scrollDom, 'scrollTop', 100) expect(wrapper.find('.is-vertical div').attributes('style')).toContain( - 'height: 80px; transform: translateY(50%);' + 'transform: translateY(50%); height: 80px;' ) await makeScroll(scrollDom, 'scrollTop', 300) expect(wrapper.find('.is-vertical div').attributes('style')).toContain( - 'height: 80px; transform: translateY(150%);' + 'transform: translateY(150%); height: 80px;' ) offsetHeightRestore() scrollHeightRestore() @@ -64,11 +64,11 @@ describe('ScrollBar', () => { await makeScroll(scrollDom, 'scrollLeft', 100) expect(wrapper.find('.is-horizontal div').attributes('style')).toContain( - 'width: 80px; transform: translateX(50%);' + 'transform: translateX(50%); width: 80px;' ) await makeScroll(scrollDom, 'scrollLeft', 300) expect(wrapper.find('.is-horizontal div').attributes('style')).toContain( - 'width: 80px; transform: translateX(150%);' + 'transform: translateX(150%); width: 80px;' ) offsetWidthRestore() scrollWidthRestore() @@ -111,18 +111,18 @@ describe('ScrollBar', () => { await makeScroll(scrollDom, 'scrollTop', 100) await makeScroll(scrollDom, 'scrollLeft', 100) expect(wrapper.find('.is-vertical div').attributes('style')).toContain( - 'height: 80px; transform: translateY(50%);' + 'transform: translateY(50%); height: 80px;' ) expect(wrapper.find('.is-horizontal div').attributes('style')).toContain( - 'width: 80px; transform: translateX(50%);' + 'transform: translateX(50%); width: 80px;' ) await makeScroll(scrollDom, 'scrollTop', 300) await makeScroll(scrollDom, 'scrollLeft', 300) expect(wrapper.find('.is-vertical div').attributes('style')).toContain( - 'height: 80px; transform: translateY(150%);' + 'transform: translateY(150%); height: 80px;' ) expect(wrapper.find('.is-horizontal div').attributes('style')).toContain( - 'width: 80px; transform: translateX(150%);' + 'transform: translateX(150%); width: 80px;' ) offsetHeightRestore() @@ -221,10 +221,10 @@ describe('ScrollBar', () => { scrollbar.setScrollLeft(100) await nextTick() expect(wrapper.find('.is-vertical div').attributes('style')).toContain( - 'height: 80px; transform: translateY(0%);' + 'transform: translateY(0%); height: 80px;' ) expect(wrapper.find('.is-horizontal div').attributes('style')).toContain( - 'width: 80px; transform: translateX(0%);' + 'transform: translateX(0%); width: 80px;' ) offsetHeightRestore() @@ -257,7 +257,7 @@ describe('ScrollBar', () => { await makeScroll(scrollDom, 'scrollTop', 0) expect(wrapper.find('.is-vertical div').attributes('style')).toContain( - 'height: 20px; transform: translateY(0%);' + 'transform: translateY(0%); height: 20px;' ) offsetHeightRestore() scrollHeightRestore() diff --git a/packages/components/scrollbar/src/bar.ts b/packages/components/scrollbar/src/bar.ts index f0d1d4a1b8..4307a0680d 100644 --- a/packages/components/scrollbar/src/bar.ts +++ b/packages/components/scrollbar/src/bar.ts @@ -7,15 +7,9 @@ export const barProps = buildProps({ type: Boolean, default: true, }, - width: String, - height: String, - ratioX: { + minSize: { type: Number, - default: 1, - }, - ratioY: { - type: Number, - default: 1, + required: true, }, } as const) export type BarProps = ExtractPropTypes diff --git a/packages/components/scrollbar/src/bar.vue b/packages/components/scrollbar/src/bar.vue index b673996b01..b5509efde4 100644 --- a/packages/components/scrollbar/src/bar.vue +++ b/packages/components/scrollbar/src/bar.vue @@ -1,35 +1,67 @@ diff --git a/packages/components/scrollbar/src/scrollbar.vue b/packages/components/scrollbar/src/scrollbar.vue index be91ca8943..1a9b261d71 100644 --- a/packages/components/scrollbar/src/scrollbar.vue +++ b/packages/components/scrollbar/src/scrollbar.vue @@ -20,14 +20,7 @@ @@ -45,7 +38,6 @@ import { import { useEventListener, useResizeObserver } from '@vueuse/core' import { addUnit, debugWarn, isNumber, isObject } from '@element-plus/utils' import { useNamespace } from '@element-plus/hooks' -import { GAP } from './util' import Bar from './bar.vue' import { scrollbarContextKey } from './constants' import { scrollbarEmits, scrollbarProps } from './scrollbar' @@ -69,12 +61,7 @@ let stopResizeListener: (() => void) | undefined = undefined const scrollbarRef = ref() const wrapRef = ref() const resizeRef = ref() - -const sizeWidth = ref('0') -const sizeHeight = ref('0') const barRef = ref() -const ratioY = ref(1) -const ratioX = ref(1) const wrapStyle = computed(() => { const style: CSSProperties = {} @@ -135,26 +122,7 @@ const setScrollLeft = (value: number) => { } const update = () => { - if (!wrapRef.value) return - const offsetHeight = wrapRef.value.offsetHeight - GAP - const offsetWidth = wrapRef.value.offsetWidth - GAP - - const originalHeight = offsetHeight ** 2 / wrapRef.value.scrollHeight - const originalWidth = offsetWidth ** 2 / wrapRef.value.scrollWidth - const height = Math.max(originalHeight, props.minSize) - const width = Math.max(originalWidth, props.minSize) - - ratioY.value = - originalHeight / - (offsetHeight - originalHeight) / - (height / (offsetHeight - height)) - ratioX.value = - originalWidth / - (offsetWidth - originalWidth) / - (width / (offsetWidth - width)) - - sizeHeight.value = height + GAP < offsetHeight ? `${height}px` : '' - sizeWidth.value = width + GAP < offsetWidth ? `${width}px` : '' + barRef.value?.update() } watch(