Skip to content

Commit 9b0f790

Browse files
committed
avoid vertical scrollbar appear when scroll.x is true
close ant-design/ant-design#20705
1 parent 3896695 commit 9b0f790

File tree

4 files changed

+18
-4
lines changed

4 files changed

+18
-4
lines changed

src/Table.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,12 @@ function Table<RecordType extends DefaultRecordType>(props: TableProps<RecordTyp
356356

357357
if (fixColumn) {
358358
scrollXStyle = { overflowX: 'scroll' };
359+
// When no vertical scrollbar, should hide it
360+
// https://github.com/ant-design/ant-design/pull/20705
361+
// https://github.com/ant-design/ant-design/issues/21879
362+
if (!fixHeader) {
363+
scrollYStyle = { overflowY: 'hidden' };
364+
}
359365
scrollTableStyle = {
360366
width: scroll.x === true ? 'auto' : scroll.x,
361367
minWidth: '100%',

tests/Scroll.spec.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ describe('Table.Scroll', () => {
1515
it('renders scroll.x is true', () => {
1616
const wrapper = mount(createTable({ scroll: { x: true } }));
1717
expect(wrapper.find('table').props().style.width).toEqual('auto');
18+
expect(wrapper.find('.rc-table-content').props().style.overflowX).toEqual('scroll');
19+
expect(wrapper.find('.rc-table-content').props().style.overflowY).toEqual('hidden');
1820
});
1921

2022
it('renders scroll.x is a number', () => {
@@ -27,6 +29,12 @@ describe('Table.Scroll', () => {
2729
expect(wrapper.find('.rc-table-body').props().style.maxHeight).toEqual(200);
2830
});
2931

32+
it('renders scroll.x and scroll.y are both true', () => {
33+
const wrapper = mount(createTable({ scroll: { x: true, y: 200 } }));
34+
expect(wrapper.find('.rc-table-body').props().style.overflowX).toEqual('scroll');
35+
expect(wrapper.find('.rc-table-body').props().style.overflowY).toEqual('scroll');
36+
});
37+
3038
it('fire scroll event', () => {
3139
jest.useFakeTimers();
3240
let scrollLeft = 0;

tests/__snapshots__/ExpandRow.spec.js.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ exports[`Table.Expand renders fixed column correctly work 1`] = `
113113
>
114114
<div
115115
class="rc-table-content"
116-
style="overflow-x: scroll;"
116+
style="overflow-x: scroll; overflow-y: hidden;"
117117
>
118118
<table
119119
style="width: 903px; min-width: 100%; table-layout: fixed;"

tests/__snapshots__/FixedColumn.spec.js.snap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ exports[`Table.FixedColumn renders correctly scrollX - with data 1`] = `
99
>
1010
<div
1111
class="rc-table-content"
12-
style="overflow-x: scroll;"
12+
style="overflow-x: scroll; overflow-y: hidden;"
1313
>
1414
<table
1515
style="width: 1200px; min-width: 100%; table-layout: fixed;"
@@ -629,7 +629,7 @@ exports[`Table.FixedColumn renders correctly scrollX - without data 1`] = `
629629
>
630630
<div
631631
class="rc-table-content"
632-
style="overflow-x: scroll;"
632+
style="overflow-x: scroll; overflow-y: hidden;"
633633
>
634634
<table
635635
style="width: 1200px; min-width: 100%; table-layout: fixed;"
@@ -1448,7 +1448,7 @@ exports[`Table.FixedColumn renders correctly scrollXY - without data 1`] = `
14481448
>
14491449
<div
14501450
class="rc-table-content"
1451-
style="overflow-x: scroll;"
1451+
style="overflow-x: scroll; overflow-y: hidden;"
14521452
>
14531453
<table
14541454
style="width: 1200px; min-width: 100%; table-layout: fixed;"

0 commit comments

Comments
 (0)