Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions src/components/AdjustableSidebarWidth.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
/>
</div>
<div
v-if="!fixedWidth"
class="resize-handle"
@mousedown.prevent="startDrag"
@touchstart.prevent="startDrag"
Expand Down Expand Up @@ -113,6 +114,10 @@ export default {
type: Boolean,
default: false,
},
fixedWidth: {
type: Number,
default: null,
},
},
data() {
const windowWidth = window.innerWidth;
Expand All @@ -131,7 +136,7 @@ export default {
return {
isDragging: false,
// limit the width to a range
width: Math.min(Math.max(storedWidth, minWidth), maxWidth),
width: this.fixedWidth || Math.min(Math.max(storedWidth, minWidth), maxWidth),
isTouch: false,
windowWidth,
windowHeight,
Expand All @@ -146,10 +151,12 @@ export default {
computed: {
minWidthPercent: ({ breakpoint }) => minWidthResponsivePercents[breakpoint] || 0,
maxWidthPercent: ({ breakpoint }) => maxWidthResponsivePercents[breakpoint] || 100,
maxWidth: ({ maxWidthPercent, windowWidth }) => (
calcWidthPercent(maxWidthPercent, windowWidth)
maxWidth: ({ maxWidthPercent, windowWidth, fixedWidth }) => (
Math.max(fixedWidth, calcWidthPercent(maxWidthPercent, windowWidth))
),
minWidth: ({ minWidthPercent, windowWidth, fixedWidth }) => (
Math.min(fixedWidth || windowWidth, calcWidthPercent(minWidthPercent, windowWidth))
),
minWidth: ({ minWidthPercent, windowWidth }) => calcWidthPercent(minWidthPercent, windowWidth),
widthInPx: ({ width }) => `${width}px`,
events: ({ isTouch }) => (isTouch ? eventsMap.touch : eventsMap.mouse),
asideStyles: ({
Expand Down Expand Up @@ -417,6 +424,7 @@ export default {
position: fixed;
top: var(--top-offset-mobile);
bottom: 0;
left: 0;
z-index: $nav-z-index + 1;
transform: translateX(-100%);
transition: transform 0.15s ease-in;
Expand Down
16 changes: 16 additions & 0 deletions tests/unit/components/AdjustableSidebarWidth.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,22 @@ describe('AdjustableSidebarWidth', () => {
expect(aside.classes()).toContain('hide-on-large');
});

it('allows hard-coding a width', async () => {
const wrapper = createWrapper({
propsData: {
fixedWidth: 200,
},
});
expect(wrapper.vm.asideStyles).toHaveProperty('width', '200px');
// simulate window changes width form orientation change.
// This should trigger both breakpoint emitter and window resize, but not in Jest
window.innerWidth = 1500;
window.dispatchEvent(createEvent('resize'));
await flushPromises();
assertWidth(wrapper, 200); // hardcoded width
expect(wrapper.find('.resize-handle').exists()).toBe(false);
});

describe('stores the content width in the store', () => {
function setContentWidth(wrapper, value) {
Object.defineProperty(wrapper.find({ ref: 'content' }).element, 'offsetWidth', {
Expand Down
1 change: 1 addition & 0 deletions tests/unit/views/DocumentationTopic.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ describe('DocumentationTopic', () => {
expect(adjustableWidth.props()).toEqual({
shownOnMobile: false,
hiddenOnLarge: false,
fixedWidth: null,
});
const technology = topicData.references['topic://foo'];
expect(wrapper.find(NavigatorDataProvider).props()).toEqual({
Expand Down