Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Table): Hide header extra scrollbar #333

Merged
merged 3 commits into from
Jun 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions assets/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,19 @@
}

&-fixed-header &-scroll &-header {
overflow-x: scroll;
padding-bottom: 20px;
margin-bottom: -20px;
overflow-y: scroll;
overflow: scroll;
box-sizing: border-box;
}

&-hide-scrollbar {
scrollbar-color: transparent transparent;
&::-webkit-scrollbar {
background-color: transparent;
}
}

// https://github.com/ant-design/ant-design/issues/10828
&-fixed-columns-in-body {
visibility: hidden;
Expand Down
2 changes: 1 addition & 1 deletion src/BodyTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export default function BodyTable(props, { table }) {
useFixedHeader = true;

// Add negative margin bottom for scroll bar overflow bug
const scrollbarWidth = measureScrollbar();
const scrollbarWidth = measureScrollbar({ direction: 'horizontal', prefixCls });
if (scrollbarWidth > 0 && fixed) {
bodyStyle.marginBottom = `-${scrollbarWidth}px`;
bodyStyle.paddingBottom = '0px';
Expand Down
4 changes: 2 additions & 2 deletions src/HeadTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default function HeadTable(props, { table }) {
if (scroll.y) {
useFixedHeader = true;
// Add negative margin bottom for scroll bar overflow bug
const scrollbarWidth = measureScrollbar('horizontal');
const scrollbarWidth = measureScrollbar({ direction: 'horizontal', prefixCls });
if (scrollbarWidth > 0 && !fixed) {
headStyle.marginBottom = `-${scrollbarWidth}px`;
headStyle.paddingBottom = '0px';
Expand All @@ -28,7 +28,7 @@ export default function HeadTable(props, { table }) {
<div
key="headTable"
ref={fixed ? null : saveRef('headTable')}
className={`${prefixCls}-header`}
className={`${prefixCls}-header ${prefixCls}-hide-scrollbar`}
style={headStyle}
onScroll={handleBodyScrollLeft}
>
Expand Down
4 changes: 3 additions & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const scrollbarMeasure = {
// This const is used for colgroup.col internal props. And should not provides to user.
export const INTERNAL_COL_DEFINE = 'RC_TABLE_INTERNAL_COL_DEFINE';

export function measureScrollbar(direction = 'vertical') {
export function measureScrollbar({ direction = 'vertical', prefixCls }) {
if (typeof document === 'undefined' || typeof window === 'undefined') {
return 0;
}
Expand All @@ -28,6 +28,8 @@ export function measureScrollbar(direction = 'vertical') {
Object.keys(scrollbarMeasure).forEach(scrollProp => {
scrollDiv.style[scrollProp] = scrollbarMeasure[scrollProp];
});
// apply hide scrollbar className ahead
scrollDiv.className = `${prefixCls}-hide-scrollbar scroll-div-append-to-body`;
// Append related overflow style
if (isVertical) {
scrollDiv.style.overflowY = 'scroll';
Expand Down
10 changes: 5 additions & 5 deletions tests/__snapshots__/Table.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ exports[`Table custom components renders fixed column and header correctly 1`] =
class="rc-table-scroll"
>
<div
class="rc-table-header"
class="rc-table-header rc-table-hide-scrollbar"
>
<table
class=""
Expand Down Expand Up @@ -338,7 +338,7 @@ exports[`Table custom components renders fixed column and header correctly 1`] =
class="rc-table-fixed-left"
>
<div
class="rc-table-header"
class="rc-table-header rc-table-hide-scrollbar"
>
<table
class="rc-table-fixed"
Expand Down Expand Up @@ -407,7 +407,7 @@ exports[`Table custom components renders fixed column and header correctly 1`] =
class="rc-table-fixed-right"
>
<div
class="rc-table-header"
class="rc-table-header rc-table-hide-scrollbar"
>
<table
class="rc-table-fixed"
Expand Down Expand Up @@ -1213,7 +1213,7 @@ exports[`Table renders fixed header correctly 1`] = `
class="rc-table-content"
>
<div
class="rc-table-header"
class="rc-table-header rc-table-hide-scrollbar"
>
<table
class=""
Expand Down Expand Up @@ -1823,7 +1823,7 @@ exports[`Table scroll renders scroll.y is a number 1`] = `
class="rc-table-scroll"
>
<div
class="rc-table-header"
class="rc-table-header rc-table-hide-scrollbar"
>
<table
class=""
Expand Down