-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Table] scrollToRegion instance method (#1496)
* Delete commented code * Add method stub * Initial implementation * [TEMPORARY?] Add instance to the window object * Make auto-scrolling work; fix syncViewportPosition bug * Handling for frozen rows/columns * Fix scroll-correction logic * Add instance method to TableQuadrantStack * Refactor logic into new scrollUtils.ts * Create new common/internal folder * Fix scroll misalignment bug * Don't correct if scroll is disabled * Prevent programmatic scrolling when scrolling disabled * Remove need for Grid in scrollUtils file * Fix off-by-one bug * Add scrollTo controls to the table example * Fix lint * Delete animated param for now * Delete window instance * Delete console.logs * Revert changes RE: prereqStateKeyValue * Delete unintentional cnewline * Write tests for scrollUtils * Fix lint again * Write tests in table too * Added docs, new 'Instance methods' section * Update stuff per CR feedback * Oops, revert changes to table example * Fix stuff per bdwyer CR
- Loading branch information
Showing
9 changed files
with
705 additions
and
69 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/** | ||
* Copyright 2017 Palantir Technologies, Inc. All rights reserved. | ||
* Licensed under the BSD-3 License as modified (the “License”); you may obtain a copy | ||
* of the license at https://github.com/palantir/blueprint/blob/master/LICENSE | ||
* and https://github.com/palantir/blueprint/blob/master/PATENTS | ||
*/ | ||
|
||
import { IRegion, RegionCardinality, Regions } from "../../regions"; | ||
|
||
export function getScrollPositionForRegion( | ||
region: IRegion, | ||
currScrollLeft: number, | ||
currScrollTop: number, | ||
getLeftOffset: (columnIndex: number) => number, | ||
getTopOffset: (rowIndex: number) => number, | ||
numFrozenRows: number = 0, | ||
numFrozenColumns: number = 0, | ||
) { | ||
const cardinality = Regions.getRegionCardinality(region); | ||
|
||
let scrollTop = currScrollTop; | ||
let scrollLeft = currScrollLeft; | ||
|
||
// if these were max-frozen-index values, we would have added 1 before passing to the get*Offset | ||
// functions, but the counts are already 1-indexed, so we can just pass those. | ||
const frozenColumnsCumulativeWidth = getLeftOffset(numFrozenColumns); | ||
const frozenRowsCumulativeHeight = getTopOffset(numFrozenRows); | ||
|
||
switch (cardinality) { | ||
case RegionCardinality.CELLS: { | ||
// scroll to the top-left corner of the block of cells | ||
const topOffset = getTopOffset(region.rows[0]); | ||
const leftOffset = getLeftOffset(region.cols[0]); | ||
scrollTop = getClampedScrollPosition(topOffset, frozenRowsCumulativeHeight); | ||
scrollLeft = getClampedScrollPosition(leftOffset, frozenColumnsCumulativeWidth); | ||
break; | ||
} | ||
case RegionCardinality.FULL_ROWS: { | ||
// scroll to the top of the row block | ||
const topOffset = getTopOffset(region.rows[0]); | ||
scrollTop = getClampedScrollPosition(topOffset, frozenRowsCumulativeHeight); | ||
break; | ||
} | ||
case RegionCardinality.FULL_COLUMNS: { | ||
// scroll to the left side of the column block | ||
const leftOffset = getLeftOffset(region.cols[0]); | ||
scrollLeft = getClampedScrollPosition(leftOffset, frozenColumnsCumulativeWidth); | ||
break; | ||
} | ||
default: { | ||
// if it's a FULL_TABLE region, scroll back to the top-left cell of the table | ||
scrollTop = 0; | ||
scrollLeft = 0; | ||
break; | ||
} | ||
} | ||
|
||
return { scrollLeft, scrollTop }; | ||
} | ||
|
||
/** | ||
* Adjust the scroll position to align content just beyond the frozen region, if necessary. | ||
*/ | ||
function getClampedScrollPosition(scrollOffset: number, frozenRegionCumulativeSize: number) { | ||
// if the new scroll offset falls within the frozen region, clamp it to 0 | ||
return Math.max(scrollOffset - frozenRegionCumulativeSize, 0); | ||
} |
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
Oops, something went wrong.
95d431d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Table] scrollToRegion instance method (#1496)
Preview: documentation
Coverage: core | datetime