Skip to content

Commit

Permalink
Merge pull request Tencent#82 from realyuyanan/develop
Browse files Browse the repository at this point in the history
fix(table): 固定表头与内容没有对齐的问题 Tencent#15
  • Loading branch information
chaishi committed Dec 24, 2021
2 parents bdb4dd2 + a91e32f commit b565cfe
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
11 changes: 6 additions & 5 deletions src/table/base-table/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ export default mixins(getConfigReceiverMixins<Vue, TableConfig>('table')).extend
];
return classes;
},
usePadding(): boolean {
return this.scrollableToRight || this.scrollableToLeft;
},
},
methods: {
// 检查是否还可以向左或者向右滚动
Expand Down Expand Up @@ -214,6 +217,7 @@ export default mixins(getConfigReceiverMixins<Vue, TableConfig>('table')).extend
scrollBarWidth,
hasFixedColumns,
tableHeight,
usePadding,
} = this;
// handle scroll
const handleScroll = throttle((e: Event) => {
Expand All @@ -224,12 +228,9 @@ export default mixins(getConfigReceiverMixins<Vue, TableConfig>('table')).extend
}, 10);
// fixed table header
const paddingRight = `${scrollBarWidth}px`;
const headerContainerStyle = columns.length > 1 && usePadding ? { paddingRight } : {};
fixedTable.push(
<div
class={`${prefix}-table__header`}
style={{ paddingRight: columns.length > 1 ? paddingRight : '' }}
ref="scrollHeader"
>
<div class={`${prefix}-table__header`} style={headerContainerStyle} ref="scrollHeader">
<table style={{ tableLayout, paddingRight }}>
<TableColGroup columns={columns} />
{this.renderHeader()}
Expand Down
10 changes: 5 additions & 5 deletions test/ssr/__snapshots__/ssr.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -10977,7 +10977,7 @@ exports[`ssr snapshot test renders ./examples/table/demos/fixed-header.vue corre
<div class="t-table t-table__header--fixed">
<div class="t-loading__parent">
<div class="t-table__content">
<div class="t-table__header" style="padding-right:0px;">
<div class="t-table__header">
<table style="table-layout:fixed;padding-right:0px;">
<colgroup>
<col style="width:100px;">
Expand Down Expand Up @@ -11205,7 +11205,7 @@ exports[`ssr snapshot test renders ./examples/table/demos/fixed-header-col.vue c
<div class="t-table t-table--bordered t-table__cell--fixed t-table--has-fixed t-table__header--fixed">
<div class="t-loading__parent">
<div class="t-table__content">
<div class="t-table__header" style="padding-right:0px;">
<div class="t-table__header">
<table style="table-layout:fixed;padding-right:0px;">
<colgroup>
<col style="width:100px;">
Expand Down Expand Up @@ -11458,7 +11458,7 @@ exports[`ssr snapshot test renders ./examples/table/demos/loading.vue correctly
<div class="t-table t-size-s t-table__header--fixed">
<div class="t-loading__parent">
<div class="t-table__content">
<div class="t-table__header" style="padding-right:0px;">
<div class="t-table__header">
<table style="table-layout:fixed;padding-right:0px;">
<colgroup>
<col style="width:100px;min-width:100px;">
Expand Down Expand Up @@ -11509,7 +11509,7 @@ exports[`ssr snapshot test renders ./examples/table/demos/loading.vue correctly
<div class="t-table t-size-s t-table__header--fixed">
<div class="t-loading__parent">
<div class="t-table__content">
<div class="t-table__header" style="padding-right:0px;">
<div class="t-table__header">
<table style="table-layout:fixed;padding-right:0px;">
<colgroup>
<col style="width:100px;min-width:100px;">
Expand Down Expand Up @@ -11562,7 +11562,7 @@ exports[`ssr snapshot test renders ./examples/table/demos/loading.vue correctly
<div class="t-table t-size-s t-table__header--fixed">
<div class="t-loading__parent">
<div class="t-table__content">
<div class="t-table__header" style="padding-right:0px;">
<div class="t-table__header">
<table style="table-layout:fixed;padding-right:0px;">
<colgroup>
<col style="width:100px;min-width:100px;">
Expand Down
1 change: 0 additions & 1 deletion test/unit/table/__snapshots__/demo.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2571,7 +2571,6 @@ exports[`Table fixedHeader demo works fine 1`] = `
>
<div
class="t-table__header"
style="padding-right: 0px;"
>
<table
style="table-layout: fixed; padding-right: 0px;"
Expand Down
2 changes: 1 addition & 1 deletion test/unit/table/__snapshots__/index.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ exports[`Table :props :props.bordered, :props:hover, :props.stripe, :props.size,
<div class="t-table t-table__header--fixed">
<div class="t-loading__parent">
<div class="t-table__content">
<div class="t-table__header" style="padding-right: 0px;">
<div class="t-table__header">
<table style="table-layout: fixed; padding-right: 0px;">
<colgroup>
<col>
Expand Down

0 comments on commit b565cfe

Please sign in to comment.