-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(module:table): fix table scrollbar bug (#3801)
close #3796
- Loading branch information
Showing
12 changed files
with
81 additions
and
102 deletions.
There are no files selected for viewing
12 changes: 0 additions & 12 deletions
12
components/core/services/nz-measure-scrollbar.service.module.ts
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/** | ||
* @license | ||
* Copyright Alibaba.com All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE | ||
*/ | ||
|
||
export function measureScrollbar(direction: 'vertical' | 'horizontal' = 'vertical', prefix: string = 'ant'): number { | ||
let scrollbarVerticalSize; | ||
let scrollbarHorizontalSize; | ||
|
||
// Measure scrollbar width for padding body during modal show/hide | ||
const scrollbarMeasure = { | ||
position: 'absolute', | ||
top: '-9999px', | ||
width: '50px', | ||
height: '50px' | ||
}; | ||
if (typeof document === 'undefined' || typeof window === 'undefined') { | ||
return 0; | ||
} | ||
const isVertical = direction === 'vertical'; | ||
if (isVertical && scrollbarVerticalSize) { | ||
return scrollbarVerticalSize; | ||
} else if (!isVertical && scrollbarHorizontalSize) { | ||
return scrollbarHorizontalSize; | ||
} | ||
const scrollDiv = document.createElement('div'); | ||
Object.keys(scrollbarMeasure).forEach(scrollProp => { | ||
// @ts-ignore | ||
scrollDiv.style[scrollProp] = scrollbarMeasure[scrollProp]; | ||
}); | ||
// apply hide scrollbar className ahead | ||
scrollDiv.className = `${prefix}-hide-scrollbar scroll-div-append-to-body`; | ||
// Append related overflow style | ||
if (isVertical) { | ||
scrollDiv.style.overflowY = 'scroll'; | ||
} else { | ||
scrollDiv.style.overflowX = 'scroll'; | ||
} | ||
document.body.appendChild(scrollDiv); | ||
let size = 0; | ||
if (isVertical) { | ||
size = scrollDiv.offsetWidth - scrollDiv.clientWidth; | ||
scrollbarVerticalSize = size; | ||
} else { | ||
size = scrollDiv.offsetHeight - scrollDiv.clientHeight; | ||
scrollbarHorizontalSize = size; | ||
} | ||
|
||
document.body.removeChild(scrollDiv); | ||
return size; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters