Skip to content

Adding an html or body class when modal is opened #463

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

Open
mrleblanc101 opened this issue Feb 19, 2025 · 1 comment
Open

Adding an html or body class when modal is opened #463

mrleblanc101 opened this issue Feb 19, 2025 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@mrleblanc101
Copy link

Hi,
I'd like to add a body class when a modal is opened, this is reposition my Toast container.
My toast are offset under my fixed header:
Image

But if a modal trigger a Toast, I don't want the offset.

Currently:
Image

Desired:
Image

@mrleblanc101 mrleblanc101 added the enhancement New feature or request label Feb 19, 2025
@mrleblanc101 mrleblanc101 changed the title Adding a body class when modal is opened Adding an html or body class when modal is opened Feb 19, 2025
@mrleblanc101
Copy link
Author

mrleblanc101 commented Feb 19, 2025

Took me a while, but I guess this is the solution:

import { createVfm, type Vfm } from 'vue-final-modal';

export default defineNuxtPlugin((nuxtApp) => {
    const vfm = createVfm() as Vfm;
    const { openedModals } = vfm;

    watch(openedModals, (opened) => {
        if (opened.length) {
            document.documentElement.classList.add('has-vfm');
        } else {
            document.documentElement.classList.remove('has-vfm');
        }
    });

    nuxtApp.vueApp.use(vfm);
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants