Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CHOPS-888] disabled scrolling when mobile menu is open #2004

Merged
merged 2 commits into from
Jul 8, 2024
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
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ebury/chameleon-components",
"version": "2.8.14",
"version": "2.8.15",
"main": "src/main.ts",
"sideEffects": false,
"author": "Ebury Team (http://labs.ebury.rocks/)",
Expand Down
4 changes: 4 additions & 0 deletions src/components/ec-navigation/ec-navigation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,17 @@ describe('EcNavigation', () => {
},
});

expect(document.body.style.overflow).not.toBe('hidden');

// Open mobile menu first
await wrapper.findByDataTest('ec-mobile-header__menu').trigger('click');
expect(wrapper.element).toMatchSnapshot('before');
expect(document.body.style.overflow).toBe('hidden');

// Close navigation when a menu item is clicked
await wrapper.findByDataTest('my-custom-link').trigger('click');
expect(wrapper.element).toMatchSnapshot('after');
expect(document.body.style.overflow).not.toBe('hidden');
});
});
});
10 changes: 9 additions & 1 deletion src/components/ec-navigation/ec-navigation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@
</template>

<script setup lang="ts">
import { ref } from 'vue';
import { useScrollLock } from '@vueuse/core';
import { ref, watch } from 'vue';

import EcIcon from '../ec-icon';
import { IconName } from '../ec-icon/types';
Expand All @@ -133,6 +134,13 @@ defineOptions({
inheritAttrs: false,
});

const scrollLockTarget = ref(document.body);
const isLocked = useScrollLock(scrollLockTarget);

watch(isMobileMenuOpen, (newValue) => {
isLocked.value = newValue;
});

withDefaults(defineProps<NavigationProps>(), {
showBrandingLogo: true,
});
Expand Down
Loading