Skip to content

Commit

Permalink
avoid vertical scrollbar appear when scroll.x is true
Browse files Browse the repository at this point in the history
  • Loading branch information
afc163 committed Mar 5, 2020
1 parent 3896695 commit 9b0f790
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
6 changes: 6 additions & 0 deletions src/Table.tsx
Expand Up @@ -356,6 +356,12 @@ function Table<RecordType extends DefaultRecordType>(props: TableProps<RecordTyp

if (fixColumn) {
scrollXStyle = { overflowX: 'scroll' };
// When no vertical scrollbar, should hide it
// https://github.com/ant-design/ant-design/pull/20705
// https://github.com/ant-design/ant-design/issues/21879
if (!fixHeader) {
scrollYStyle = { overflowY: 'hidden' };
}
scrollTableStyle = {
width: scroll.x === true ? 'auto' : scroll.x,
minWidth: '100%',
Expand Down
8 changes: 8 additions & 0 deletions tests/Scroll.spec.js
Expand Up @@ -15,6 +15,8 @@ describe('Table.Scroll', () => {
it('renders scroll.x is true', () => {
const wrapper = mount(createTable({ scroll: { x: true } }));
expect(wrapper.find('table').props().style.width).toEqual('auto');
expect(wrapper.find('.rc-table-content').props().style.overflowX).toEqual('scroll');
expect(wrapper.find('.rc-table-content').props().style.overflowY).toEqual('hidden');
});

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

it('renders scroll.x and scroll.y are both true', () => {
const wrapper = mount(createTable({ scroll: { x: true, y: 200 } }));
expect(wrapper.find('.rc-table-body').props().style.overflowX).toEqual('scroll');
expect(wrapper.find('.rc-table-body').props().style.overflowY).toEqual('scroll');
});

it('fire scroll event', () => {
jest.useFakeTimers();
let scrollLeft = 0;
Expand Down
2 changes: 1 addition & 1 deletion tests/__snapshots__/ExpandRow.spec.js.snap
Expand Up @@ -113,7 +113,7 @@ exports[`Table.Expand renders fixed column correctly work 1`] = `
>
<div
class="rc-table-content"
style="overflow-x: scroll;"
style="overflow-x: scroll; overflow-y: hidden;"
>
<table
style="width: 903px; min-width: 100%; table-layout: fixed;"
Expand Down
6 changes: 3 additions & 3 deletions tests/__snapshots__/FixedColumn.spec.js.snap
Expand Up @@ -9,7 +9,7 @@ exports[`Table.FixedColumn renders correctly scrollX - with data 1`] = `
>
<div
class="rc-table-content"
style="overflow-x: scroll;"
style="overflow-x: scroll; overflow-y: hidden;"
>
<table
style="width: 1200px; min-width: 100%; table-layout: fixed;"
Expand Down Expand Up @@ -629,7 +629,7 @@ exports[`Table.FixedColumn renders correctly scrollX - without data 1`] = `
>
<div
class="rc-table-content"
style="overflow-x: scroll;"
style="overflow-x: scroll; overflow-y: hidden;"
>
<table
style="width: 1200px; min-width: 100%; table-layout: fixed;"
Expand Down Expand Up @@ -1448,7 +1448,7 @@ exports[`Table.FixedColumn renders correctly scrollXY - without data 1`] = `
>
<div
class="rc-table-content"
style="overflow-x: scroll;"
style="overflow-x: scroll; overflow-y: hidden;"
>
<table
style="width: 1200px; min-width: 100%; table-layout: fixed;"
Expand Down

1 comment on commit 9b0f790

@vercel
Copy link

@vercel vercel bot commented on 9b0f790 Mar 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.