Skip to content

Commit 32b16c7

Browse files
author
Dobromir Hristov
authored
Allow disabling the sidebar resizing and setting a fixed width (#437)
related rdar://97716953
1 parent 526cd27 commit 32b16c7

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
lines changed

src/components/AdjustableSidebarWidth.vue

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
/>
3838
</div>
3939
<div
40+
v-if="!fixedWidth"
4041
class="resize-handle"
4142
@mousedown.prevent="startDrag"
4243
@touchstart.prevent="startDrag"
@@ -113,6 +114,10 @@ export default {
113114
type: Boolean,
114115
default: false,
115116
},
117+
fixedWidth: {
118+
type: Number,
119+
default: null,
120+
},
116121
},
117122
data() {
118123
const windowWidth = window.innerWidth;
@@ -131,7 +136,7 @@ export default {
131136
return {
132137
isDragging: false,
133138
// limit the width to a range
134-
width: Math.min(Math.max(storedWidth, minWidth), maxWidth),
139+
width: this.fixedWidth || Math.min(Math.max(storedWidth, minWidth), maxWidth),
135140
isTouch: false,
136141
windowWidth,
137142
windowHeight,
@@ -146,10 +151,12 @@ export default {
146151
computed: {
147152
minWidthPercent: ({ breakpoint }) => minWidthResponsivePercents[breakpoint] || 0,
148153
maxWidthPercent: ({ breakpoint }) => maxWidthResponsivePercents[breakpoint] || 100,
149-
maxWidth: ({ maxWidthPercent, windowWidth }) => (
150-
calcWidthPercent(maxWidthPercent, windowWidth)
154+
maxWidth: ({ maxWidthPercent, windowWidth, fixedWidth }) => (
155+
Math.max(fixedWidth, calcWidthPercent(maxWidthPercent, windowWidth))
156+
),
157+
minWidth: ({ minWidthPercent, windowWidth, fixedWidth }) => (
158+
Math.min(fixedWidth || windowWidth, calcWidthPercent(minWidthPercent, windowWidth))
151159
),
152-
minWidth: ({ minWidthPercent, windowWidth }) => calcWidthPercent(minWidthPercent, windowWidth),
153160
widthInPx: ({ width }) => `${width}px`,
154161
events: ({ isTouch }) => (isTouch ? eventsMap.touch : eventsMap.mouse),
155162
asideStyles: ({
@@ -417,6 +424,7 @@ export default {
417424
position: fixed;
418425
top: var(--top-offset-mobile);
419426
bottom: 0;
427+
left: 0;
420428
z-index: $nav-z-index + 1;
421429
transform: translateX(-100%);
422430
transition: transform 0.15s ease-in;

tests/unit/components/AdjustableSidebarWidth.spec.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,22 @@ describe('AdjustableSidebarWidth', () => {
554554
expect(aside.classes()).toContain('hide-on-large');
555555
});
556556

557+
it('allows hard-coding a width', async () => {
558+
const wrapper = createWrapper({
559+
propsData: {
560+
fixedWidth: 200,
561+
},
562+
});
563+
expect(wrapper.vm.asideStyles).toHaveProperty('width', '200px');
564+
// simulate window changes width form orientation change.
565+
// This should trigger both breakpoint emitter and window resize, but not in Jest
566+
window.innerWidth = 1500;
567+
window.dispatchEvent(createEvent('resize'));
568+
await flushPromises();
569+
assertWidth(wrapper, 200); // hardcoded width
570+
expect(wrapper.find('.resize-handle').exists()).toBe(false);
571+
});
572+
557573
describe('stores the content width in the store', () => {
558574
function setContentWidth(wrapper, value) {
559575
Object.defineProperty(wrapper.find({ ref: 'content' }).element, 'offsetWidth', {

tests/unit/views/DocumentationTopic.spec.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ describe('DocumentationTopic', () => {
182182
expect(adjustableWidth.props()).toEqual({
183183
shownOnMobile: false,
184184
hiddenOnLarge: false,
185+
fixedWidth: null,
185186
});
186187
const technology = topicData.references['topic://foo'];
187188
expect(wrapper.find(NavigatorDataProvider).props()).toEqual({

0 commit comments

Comments
 (0)