Skip to content

Commit 5bb2cb1

Browse files
authored
Guard against empty canvas groupings. Related to #3543 (#3545)
1 parent 17f3fce commit 5bb2cb1

3 files changed

Lines changed: 11 additions & 3 deletions

File tree

__tests__/src/components/ThumbnailNavigation.test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,12 @@ describe('ThumbnailNavigation', () => {
100100
expect(wrapper.instance().areaHeight()).toEqual(150);
101101
expect(rightWrapper.instance().areaHeight(99)).toEqual(99);
102102
});
103+
describe('without any canvases', () => {
104+
it('returns the default for the calculated size', () => {
105+
wrapper = createWrapper({ canvasGroupings: new CanvasGroupings([]).groupings() });
106+
expect(wrapper.instance().calculateScaledSize(0)).toEqual(108);
107+
});
108+
});
103109
});
104110
describe('keyboard navigation', () => {
105111
const setNextCanvas = jest.fn();

src/components/ThumbnailNavigation.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ export class ThumbnailNavigation extends Component {
6969
*/
7070
calculateScaledSize(index) {
7171
const { thumbnailNavigation, canvasGroupings, position } = this.props;
72-
const canvases = canvasGroupings[index] || [];
72+
const canvases = canvasGroupings[index];
73+
if (!canvases) return thumbnailNavigation.width + this.spacing;
74+
7375
const world = new CanvasWorld(canvases);
7476
const bounds = world.worldBounds();
7577
switch (position) {

src/lib/CanvasWorld.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,8 @@ export default class CanvasWorld {
203203
* lined up horizontally starting from left to right.
204204
*/
205205
worldBounds() {
206-
const worldWidth = Math.max(...this.canvasDimensions.map(c => c.x + c.width));
207-
const worldHeight = Math.max(...this.canvasDimensions.map(c => c.y + c.height));
206+
const worldWidth = Math.max(0, ...this.canvasDimensions.map(c => c.x + c.width));
207+
const worldHeight = Math.max(0, ...this.canvasDimensions.map(c => c.y + c.height));
208208

209209
return [
210210
0,

0 commit comments

Comments
 (0)