Skip to content

Commit 0cd3db0

Browse files
committed
fix: auto hide table scrollbar #4484
close #4484
1 parent 08c3c9c commit 0cd3db0

File tree

3 files changed

+16
-81
lines changed

3 files changed

+16
-81
lines changed

components/vc-table/src/BaseTable.jsx

+2-5
Original file line numberDiff line numberDiff line change
@@ -132,16 +132,13 @@ const BaseTable = {
132132

133133
render() {
134134
const { sComponents: components, prefixCls, scroll, data } = this.table;
135-
const { expander, tableClassName, hasHead, hasBody, fixed, isAnyColumnsFixed } = this.$props;
135+
const { expander, tableClassName, hasHead, hasBody, fixed } = this.$props;
136136
const columns = this.getColumns();
137137
const tableStyle = {};
138138

139139
if (!fixed && scroll.x) {
140-
// 当有固定列时,width auto 会导致 body table 的宽度撑不开,从而固定列无法对齐
141-
// 详情见:https://github.com/ant-design/ant-design/issues/22160
142-
const tableWidthScrollX = isAnyColumnsFixed ? 'max-content' : 'auto';
143140
// not set width, then use content fixed width
144-
tableStyle.width = scroll.x === true ? tableWidthScrollX : scroll.x;
141+
tableStyle.width = scroll.x === true ? 'auto' : scroll.x;
145142
tableStyle.width =
146143
typeof tableStyle.width === 'number' ? `${tableStyle.width}px` : tableStyle.width;
147144
}

components/vc-table/src/BodyTable.jsx

+12-47
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
import { inject } from 'vue';
2-
import PropTypes, { withUndefined } from '../../_util/vue-types';
3-
import { measureScrollbar } from './utils';
2+
import PropTypes from '../../_util/vue-types';
43
import BaseTable from './BaseTable';
54

65
export default {
76
name: 'BodyTable',
87
inheritAttrs: false,
98
props: {
10-
fixed: withUndefined(PropTypes.oneOfType([PropTypes.string, PropTypes.looseBool])),
119
columns: PropTypes.array.isRequired,
1210
tableClassName: PropTypes.string.isRequired,
1311
handleBodyScroll: PropTypes.func.isRequired,
@@ -25,7 +23,6 @@ export default {
2523
const { prefixCls, scroll } = this.table;
2624
const {
2725
columns,
28-
fixed,
2926
tableClassName,
3027
getRowKey,
3128
handleBodyScroll,
@@ -35,34 +32,26 @@ export default {
3532
} = this;
3633
let { useFixedHeader, saveRef } = this.table;
3734
const bodyStyle = { ...this.table.bodyStyle };
38-
const innerBodyStyle = {};
39-
40-
if (scroll.x || fixed) {
41-
bodyStyle.overflowX = bodyStyle.overflowX || 'scroll';
42-
// Fix weired webkit render bug
43-
// https://github.com/ant-design/ant-design/issues/7783
44-
bodyStyle.WebkitTransform = 'translate3d (0, 0, 0)';
45-
}
4635

4736
if (scroll.y) {
4837
// maxHeight will make fixed-Table scrolling not working
4938
// so we only set maxHeight to body-Table here
5039
let maxHeight = bodyStyle.maxHeight || scroll.y;
5140
maxHeight = typeof maxHeight === 'number' ? `${maxHeight}px` : maxHeight;
52-
if (fixed) {
53-
innerBodyStyle.maxHeight = maxHeight;
54-
innerBodyStyle.overflowY = bodyStyle.overflowY || 'scroll';
55-
} else {
56-
bodyStyle.maxHeight = maxHeight;
57-
}
41+
42+
bodyStyle.maxHeight = maxHeight;
5843
bodyStyle.overflowY = bodyStyle.overflowY || 'scroll';
5944
useFixedHeader = true;
45+
}
6046

61-
// Add negative margin bottom for scroll bar overflow bug
62-
const scrollbarWidth = measureScrollbar({ direction: 'vertical' });
63-
if (scrollbarWidth > 0 && fixed) {
64-
bodyStyle.marginBottom = `-${scrollbarWidth}px`;
65-
bodyStyle.paddingBottom = '0px';
47+
if (scroll.x) {
48+
bodyStyle.overflowX = bodyStyle.overflowX || 'auto';
49+
// Fix weired webkit render bug
50+
// https://github.com/ant-design/ant-design/issues/7783
51+
bodyStyle.WebkitTransform = 'translate3d (0, 0, 0)';
52+
53+
if (!scroll.y) {
54+
bodyStyle.overflowY = 'hidden';
6655
}
6756
}
6857

@@ -71,37 +60,13 @@ export default {
7160
tableClassName={tableClassName}
7261
hasHead={!useFixedHeader}
7362
hasBody
74-
fixed={fixed}
7563
columns={columns}
7664
expander={expander}
7765
getRowKey={getRowKey}
7866
isAnyColumnsFixed={isAnyColumnsFixed}
7967
/>
8068
);
8169

82-
if (fixed && columns.length) {
83-
let refName;
84-
if (columns[0].fixed === 'left' || columns[0].fixed === true) {
85-
refName = 'fixedColumnsBodyLeft';
86-
} else if (columns[0].fixed === 'right') {
87-
refName = 'fixedColumnsBodyRight';
88-
}
89-
delete bodyStyle.overflowX;
90-
delete bodyStyle.overflowY;
91-
return (
92-
<div key="bodyTable" class={`${prefixCls}-body-outer`} style={{ ...bodyStyle }}>
93-
<div
94-
class={`${prefixCls}-body-inner`}
95-
style={innerBodyStyle}
96-
ref={saveRef(refName)}
97-
onWheel={handleWheel}
98-
onScroll={handleBodyScroll}
99-
>
100-
{baseTable}
101-
</div>
102-
</div>
103-
);
104-
}
10570
// Should provides `tabindex` if use scroll to enable keyboard scroll
10671
const useTabIndex = scroll && (scroll.x || scroll.y);
10772

components/vc-table/src/Table.jsx

+2-29
Original file line numberDiff line numberDiff line change
@@ -501,41 +501,15 @@ export default defineComponent({
501501
);
502502
},
503503

504-
renderLeftFixedTable() {
505-
const { prefixCls } = this;
506-
507-
return (
508-
<div key="left" class={`${prefixCls}-fixed-left`}>
509-
{this.renderTable({
510-
columns: this.columnManager.leftColumns.value,
511-
fixed: 'left',
512-
})}
513-
</div>
514-
);
515-
},
516-
renderRightFixedTable() {
517-
const { prefixCls } = this;
518-
519-
return (
520-
<div class={`${prefixCls}-fixed-right`}>
521-
{this.renderTable({
522-
columns: this.columnManager.rightColumns.value,
523-
fixed: 'right',
524-
})}
525-
</div>
526-
);
527-
},
528-
529504
renderTable(options) {
530-
const { columns, fixed, isAnyColumnsFixed } = options;
505+
const { columns, isAnyColumnsFixed } = options;
531506
const { prefixCls, scroll = {} } = this;
532-
const tableClassName = scroll.x || fixed ? `${prefixCls}-fixed` : '';
507+
const tableClassName = scroll.x ? `${prefixCls}-fixed` : '';
533508

534509
const headTable = (
535510
<HeadTable
536511
key="head"
537512
columns={columns}
538-
fixed={fixed}
539513
tableClassName={tableClassName}
540514
handleBodyScrollLeft={this.handleBodyScrollLeft}
541515
expander={this.expander}
@@ -546,7 +520,6 @@ export default defineComponent({
546520
<BodyTable
547521
key="body"
548522
columns={columns}
549-
fixed={fixed}
550523
tableClassName={tableClassName}
551524
getRowKey={this.getRowKey}
552525
handleWheel={this.handleWheel}

0 commit comments

Comments
 (0)