Skip to content

Commit 52847fc

Browse files
author
Dobromir Hristov
authored
Default sidebar width on large and ultrawide screens (#607)
resolves rdar://105566775
1 parent d0d2b33 commit 52847fc

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

src/components/AdjustableSidebarWidth.vue

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,9 @@ import { baseNavStickyAnchorId } from 'docc-render/constants/nav';
6565
export const STORAGE_KEY = 'sidebar';
6666
6767
// the maximum width, after which the full-width content does not grow
68-
export const MAX_WIDTH = 1920;
68+
export const MAX_WIDTH = 1921;
6969
export const ULTRA_WIDE_DEFAULT = 543;
70+
export const LARGE_DEFAULT_WIDTH = 400;
7071
7172
export const eventsMap = {
7273
touch: {
@@ -130,7 +131,7 @@ export default {
130131
// have a default width for very large screens, or use half of the min and max
131132
const defaultWidth = windowWidth >= MAX_WIDTH
132133
? ULTRA_WIDE_DEFAULT
133-
: Math.round((minWidth + maxWidth) / 2);
134+
: LARGE_DEFAULT_WIDTH;
134135
// get the already stored data, fallback to a default one.
135136
const storedWidth = storage.get(STORAGE_KEY, defaultWidth);
136137
return {

tests/unit/components/AdjustableSidebarWidth.spec.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import AdjustableSidebarWidth, {
1313
STORAGE_KEY,
1414
MAX_WIDTH,
1515
ULTRA_WIDE_DEFAULT,
16+
LARGE_DEFAULT_WIDTH,
1617
} from '@/components/AdjustableSidebarWidth.vue';
1718

1819
import store from '@/stores/DocumentationTopicStore';
@@ -106,9 +107,9 @@ describe('AdjustableSidebarWidth', () => {
106107
});
107108

108109
describe('on mount', () => {
109-
it('sets the `width` to the middle between min and max for `large`, on mount', () => {
110+
it('sets the `width` to the `large` default width, on mount', () => {
110111
const wrapper = createWrapper();
111-
assertWidth(wrapper, 350); // 35% on large
112+
assertWidth(wrapper, LARGE_DEFAULT_WIDTH);
112113
});
113114

114115
it('changes the `width`, to the next closest max or min, on mount, as soon as the breakpoint gets changed', () => {
@@ -145,7 +146,7 @@ describe('AdjustableSidebarWidth', () => {
145146
assertWidth(wrapper, 450);
146147
// assert the storage was called with the key and the default size
147148
// 350 is half of min and max on Large
148-
expect(storage.get).toHaveBeenLastCalledWith(STORAGE_KEY, 350);
149+
expect(storage.get).toHaveBeenLastCalledWith(STORAGE_KEY, LARGE_DEFAULT_WIDTH);
149150
});
150151

151152
it('sets the `width` to the `max width allowed`, if stored value is bigger', () => {
@@ -369,8 +370,8 @@ describe('AdjustableSidebarWidth', () => {
369370
// assert drop
370371
document.dispatchEvent(createEvent(eventsMap.mouse.end));
371372
// assert emit event
372-
expect(wrapper.emitted('width-change')).toHaveLength(4);
373-
expect(wrapper.emitted('width-change')[3]).toEqual([maxWidth]);
373+
expect(wrapper.emitted('width-change')).toHaveLength(3);
374+
expect(wrapper.emitted('width-change')[2]).toEqual([maxWidth]);
374375
// assert saved storage
375376
expect(storage.set).toHaveBeenLastCalledWith(STORAGE_KEY, maxWidth);
376377
// assert drag stopped
@@ -407,8 +408,8 @@ describe('AdjustableSidebarWidth', () => {
407408
// assert drop
408409
document.dispatchEvent(createEvent(eventsMap.touch.end));
409410
// assert emit event
410-
expect(wrapper.emitted('width-change')).toHaveLength(4);
411-
expect(wrapper.emitted('width-change')[3]).toEqual([maxWidth]);
411+
expect(wrapper.emitted('width-change')).toHaveLength(3);
412+
expect(wrapper.emitted('width-change')[2]).toEqual([maxWidth]);
412413
// assert saved storage
413414
expect(storage.set).toHaveBeenLastCalledWith(STORAGE_KEY, maxWidth);
414415
// assert drag stopped

0 commit comments

Comments
 (0)