Skip to content

Commit 30e968d

Browse files
jevin98sleeprite
authored andcommitted
!486 fix(table): 存在多个 fixed 表头,固定表头偏移异常
* fix(table): 存在fixed表头,偏移异常
1 parent 3207303 commit 30e968d

File tree

3 files changed

+63
-5
lines changed

3 files changed

+63
-5
lines changed

packages/component/component/table/__tests__/table.test.tsx

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -823,4 +823,62 @@ describe("LayTable", () => {
823823

824824
expect((checkboxComponent as any).vm.modelValue).toBeFalsy();
825825
});
826+
827+
// https://gitee.com/layui-vue/layui-vue/issues/IC9S5Q
828+
test("一级表头存在两个fixed为left表头,第二个表头会覆盖第一列", async () => {
829+
const columns = [
830+
{ title: "用户", width: "80px", key: "name", fixed: "left" as const },
831+
{ title: "城市", width: "80px", key: "city", fixed: "left" as const },
832+
];
833+
834+
const dataSource = ref([]);
835+
836+
const wrapper = mount({
837+
setup() {
838+
return () => (
839+
<LayTable
840+
columns={columns}
841+
dataSource={dataSource.value}
842+
></LayTable>
843+
);
844+
},
845+
});
846+
847+
await nextTick()
848+
849+
const ths = wrapper.findAll(".layui-table-header .layui-table-header-wrapper tr th");
850+
851+
const style = ths[1].attributes().style
852+
853+
expect(style).toMatch(/left/)
854+
expect(style).toMatch(/80px/)
855+
});
856+
857+
test("一级表头存在两个fixed为left表头,存在 layui-table-fixed-left-last 类名", async () => {
858+
const columns = [
859+
{ title: "用户", width: "80px", key: "name", fixed: "left" as const },
860+
{ title: "城市", width: "80px", key: "city", fixed: "left" as const },
861+
];
862+
863+
const dataSource = ref([]);
864+
865+
const wrapper = mount({
866+
setup() {
867+
return () => (
868+
<LayTable
869+
columns={columns}
870+
dataSource={dataSource.value}
871+
></LayTable>
872+
);
873+
},
874+
});
875+
876+
await nextTick()
877+
878+
const ths = wrapper.findAll(".layui-table-header .layui-table-header-wrapper tr th");
879+
880+
const _class = ths[1].attributes().class
881+
882+
expect(_class).toMatch(/layui-table-fixed-left-last/)
883+
});
826884
});

packages/component/component/table/hooks/useTable.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
isReactive,
1212
reactive,
1313
ref,
14-
14+
toRaw,
1515
watch,
1616
watchEffect,
1717
} from "vue";
@@ -273,7 +273,7 @@ export function useTable(props: RequiredTableProps, emit: TableEmit) {
273273
const _columns = isLeft ? props.columns : [...props.columns].reverse();
274274

275275
let index
276-
= _columns.findIndex(column => isEqual(column, topColumn)) - 1;
276+
= _columns.findIndex(column => isEqual(column, toRaw(topColumn))) - 1;
277277
const fixedColumns = [];
278278

279279
while (index > -1) {
@@ -316,12 +316,12 @@ export function useTable(props: RequiredTableProps, emit: TableEmit) {
316316
column => column.fixed === "right",
317317
);
318318

319-
if (isEqual(topColumn, topLastLeft)) {
319+
if (isEqual(toRaw(topColumn), topLastLeft)) {
320320
loopJudge(topColumn, "left")
321321
&& (lastLeftClassName = lastLeftClassNameConstant);
322322
}
323323

324-
if (isEqual(topColumn, topFirstRight)) {
324+
if (isEqual(toRaw(topColumn), topFirstRight)) {
325325
loopJudge(topColumn, "right")
326326
&& (firstRightClassName = firstRightClassNameConstant);
327327
}

packages/component/component/table/typing.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ interface TableBaseColumn {
9696
}
9797

9898
export type TableColumn =
99-
(TableBaseColumn & { type: undefined; key: string }) |
99+
(TableBaseColumn & { type?: undefined; key: string }) |
100100
(TableBaseColumn & { type: string; key?: string });
101101

102102
export type FixedDirectionType =

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy