-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changed default overscan behavior for List and Table to ensure there'…
…s always at least 1 row overscanned in a given direction. This helps with a keyboard accessibility (TAB / TAB+SHIFT) problem reported in issue #625. Grid overscan behavior is not adjusted by default because I didn't want to impact performance too much.
- Loading branch information
Brian Vaughn
committed
Apr 5, 2017
1 parent
84064cd
commit e6656c1
Showing
12 changed files
with
218 additions
and
81 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,110 @@ | ||
import overscanIndicesGetter, { | ||
SCROLL_DIRECTION_BACKWARD, | ||
SCROLL_DIRECTION_FORWARD | ||
} from './accessibilityOverscanIndicesGetter' | ||
|
||
describe('overscanIndicesGetter', () => { | ||
function testHelper ({ | ||
cellCount, | ||
startIndex, | ||
stopIndex, | ||
overscanCellsCount, | ||
scrollDirection | ||
}) { | ||
return overscanIndicesGetter({ | ||
cellCount, | ||
overscanCellsCount, | ||
scrollDirection, | ||
startIndex, | ||
stopIndex | ||
}) | ||
} | ||
|
||
it('should still overscan by 1 (for keyboard accessibility) if :overscanCellsCount is 0', () => { | ||
expect( | ||
testHelper({ | ||
cellCount: 100, | ||
startIndex: 10, | ||
stopIndex: 20, | ||
overscanCellsCount: 0, | ||
scrollDirection: SCROLL_DIRECTION_BACKWARD | ||
}) | ||
).toEqual({ | ||
overscanStartIndex: 9, | ||
overscanStopIndex: 21 | ||
}) | ||
|
||
expect( | ||
testHelper({ | ||
cellCount: 100, | ||
startIndex: 10, | ||
stopIndex: 20, | ||
overscanCellsCount: 0, | ||
scrollDirection: SCROLL_DIRECTION_FORWARD | ||
}) | ||
).toEqual({ | ||
overscanStartIndex: 9, | ||
overscanStopIndex: 21 | ||
}) | ||
}) | ||
|
||
it('should overscan forward', () => { | ||
expect( | ||
testHelper({ | ||
cellCount: 100, | ||
startIndex: 20, | ||
stopIndex: 30, | ||
overscanCellsCount: 10, | ||
scrollDirection: SCROLL_DIRECTION_FORWARD | ||
}) | ||
).toEqual({ | ||
overscanStartIndex: 19, | ||
overscanStopIndex: 40 | ||
}) | ||
}) | ||
|
||
it('should overscan backward', () => { | ||
expect( | ||
testHelper({ | ||
cellCount: 100, | ||
startIndex: 20, | ||
stopIndex: 30, | ||
overscanCellsCount: 10, | ||
scrollDirection: SCROLL_DIRECTION_BACKWARD | ||
}) | ||
).toEqual({ | ||
overscanStartIndex: 10, | ||
overscanStopIndex: 31 | ||
}) | ||
}) | ||
|
||
it('should not overscan beyond the start of the list', () => { | ||
expect( | ||
testHelper({ | ||
cellCount: 100, | ||
startIndex: 5, | ||
stopIndex: 15, | ||
overscanCellsCount: 10, | ||
scrollDirection: SCROLL_DIRECTION_BACKWARD | ||
}) | ||
).toEqual({ | ||
overscanStartIndex: 0, | ||
overscanStopIndex: 16 | ||
}) | ||
}) | ||
|
||
it('should not overscan beyond the end of the list', () => { | ||
expect( | ||
testHelper({ | ||
cellCount: 25, | ||
startIndex: 10, | ||
stopIndex: 20, | ||
overscanCellsCount: 10, | ||
scrollDirection: SCROLL_DIRECTION_FORWARD | ||
}) | ||
).toEqual({ | ||
overscanStartIndex: 9, | ||
overscanStopIndex: 24 | ||
}) | ||
}) | ||
}) |
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,41 @@ | ||
export const SCROLL_DIRECTION_BACKWARD = -1 | ||
export const SCROLL_DIRECTION_FORWARD = 1 | ||
|
||
export const SCROLL_DIRECTION_HORIZONTAL = 'horizontal' | ||
export const SCROLL_DIRECTION_VERTICAL = 'vertical' | ||
/** | ||
* Calculates the number of cells to overscan before and after a specified range. | ||
* This function ensures that overscanning doesn't exceed the available cells. | ||
* | ||
* @param direction One of SCROLL_DIRECTION_HORIZONTAL or SCROLL_DIRECTION_VERTICAL | ||
* @param cellCount Number of rows or columns in the current axis | ||
* @param scrollDirection One of SCROLL_DIRECTION_BACKWARD or SCROLL_DIRECTION_FORWARD | ||
* @param overscanCellsCount Maximum number of cells to over-render in either direction | ||
* @param startIndex Begin of range of visible cells | ||
* @param stopIndex End of range of visible cells | ||
*/ | ||
export default function defaultOverscanIndicesGetter ({ direction, cellCount, overscanCellsCount, scrollDirection, startIndex, stopIndex }) { | ||
let overscanStartIndex | ||
let overscanStopIndex | ||
|
||
// Make sure we render at least 1 cell extra before and after (except near boundaries) | ||
// This is necessary in order to support keyboard navigation (TAB/SHIFT+TAB) in some cases | ||
// For more info see issues #625 | ||
overscanCellsCount = Math.max(1, overscanCellsCount) | ||
|
||
switch (scrollDirection) { | ||
case SCROLL_DIRECTION_FORWARD: | ||
overscanStartIndex = startIndex - 1 | ||
overscanStopIndex = stopIndex + overscanCellsCount | ||
break | ||
case SCROLL_DIRECTION_BACKWARD: | ||
overscanStartIndex = startIndex - overscanCellsCount | ||
overscanStopIndex = stopIndex + 1 | ||
break | ||
} | ||
|
||
return { | ||
overscanStartIndex: Math.max(0, overscanStartIndex), | ||
overscanStopIndex: Math.min(cellCount - 1, overscanStopIndex) | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
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 |
---|---|---|
@@ -1,4 +1,6 @@ | ||
/** @flow */ | ||
export default from './Grid' | ||
export Grid from './Grid' | ||
export accessibilityOverscanIndicesGetter from './accessibilityOverscanIndicesGetter' | ||
export defaultCellRangeRenderer from './defaultCellRangeRenderer' | ||
export defaultOverscanIndicesGetter from './defaultOverscanIndicesGetter' |
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.