mirror of
https://github.com/element-plus/element-plus.git
synced 2026-03-13 07:51:17 +08:00
fix(components): [table-v2] keep scrollToRow from changing horiz offset (#22930)
* fix(components): [table-v2] Rebase merge dev branch closed #22928 * feat(components): [table-v2] keep scrollToRow from changing horiz offset closed #22928 --------- Co-authored-by: alex.yang <alex.yang@hytechc.com> Co-authored-by: 云游君 <me@yunyoujun.cn>
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
import { h, nextTick, ref } from 'vue'
|
||||
import { mount } from '@vue/test-utils'
|
||||
import { describe, expect, test } from 'vitest'
|
||||
import TableV2 from '../src/table-v2'
|
||||
import TableV2, { type TableV2Instance } from '../src/table-v2'
|
||||
import { TableV2SortOrder } from '../index'
|
||||
|
||||
import type { ScrollPos } from '../src/composables/use-scrollbar'
|
||||
import type {
|
||||
TableV2HeaderRowCellRendererParams,
|
||||
TableV2RowCellRenderParam,
|
||||
@@ -261,6 +262,38 @@ describe('TableV2.vue', () => {
|
||||
expect(cell.find('div [style^=margin-inline-star]').exists()).toBe(false)
|
||||
})
|
||||
|
||||
test('scrollToRow keeps horizontal offset unchanged', async () => {
|
||||
const columns = ref(generateColumns(10))
|
||||
const data = ref(generateData(columns.value, 200))
|
||||
const scrollLogs: ScrollPos[] = []
|
||||
const wrapper = mount(() => (
|
||||
<TableV2
|
||||
fixed
|
||||
columns={columns.value}
|
||||
data={data.value}
|
||||
width={400}
|
||||
height={400}
|
||||
onScroll={(pos: ScrollPos) => scrollLogs.push({ ...pos })}
|
||||
/>
|
||||
))
|
||||
|
||||
const tableVm = wrapper.findComponent(TableV2).vm.$
|
||||
.exposed as TableV2Instance
|
||||
tableVm.scrollToLeft(150)
|
||||
await nextTick()
|
||||
await nextTick()
|
||||
|
||||
const prevScrollLeft = scrollLogs[scrollLogs.length - 1]?.scrollLeft ?? 0
|
||||
expect(prevScrollLeft).toBeGreaterThan(0)
|
||||
|
||||
tableVm.scrollToRow(50)
|
||||
await nextTick()
|
||||
await nextTick()
|
||||
|
||||
const lastScrollLeft = scrollLogs[scrollLogs.length - 1]?.scrollLeft ?? 0
|
||||
expect(lastScrollLeft).toBe(prevScrollLeft)
|
||||
})
|
||||
|
||||
describe('a11y', () => {
|
||||
test('expand button', async () => {
|
||||
const columns = generateColumns(10)
|
||||
|
||||
@@ -114,7 +114,18 @@ const useTableGrid = (props: TableV2GridProps) => {
|
||||
}
|
||||
|
||||
function scrollToRow(row: number, strategy: ScrollStrategy) {
|
||||
unref(bodyRef)?.scrollToItem(row, 1, strategy)
|
||||
const body = unref(bodyRef)
|
||||
if (!body) return
|
||||
|
||||
const prevScrollLeft = scrollLeft.value
|
||||
|
||||
body.scrollToItem(row, 0, strategy)
|
||||
|
||||
if (prevScrollLeft) {
|
||||
scrollTo({
|
||||
scrollLeft: prevScrollLeft,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
function forceUpdate() {
|
||||
|
||||
Reference in New Issue
Block a user