0

I an working with vue3 and PrimeVue library. When I try to override css fields of PrimeView components using :deep() selector it just does not have any effect. only when I am using an unscoped style it applies my changes. I have trouble understanding why it does not work.

code for example with :deep():

<template>
    <Toast position='buttom-right'/>
</template>

<style scoped>
:deep(.p-toast-message-icon) {
    margin-right: 10px !important;
}
</style>

This doesn't work.

But when using style without scoped like so:

<style>
.p-toast-message-icon {
    margin-right: 10px !important;
}
</style>

This does work.

1 Answer 1

1

The rules generated by a :deep selector target children of the current component, but the p-toast is attached to the body, so the generated class will have no effect.

However, you can set passthrough options to pass the style rule to the icon:

<Toast
    :pt="{
        icon: { style: 'marginRight: 10px !important;' }
    }"
/>

or

<Toast
    :pt="{
        icon: { class: 'mr-2' }
    }"
/>

Here it is in a Sandbox

Sign up to request clarification or add additional context in comments.

6 Comments

Thank you I will try this. Although the Toast component was just one example, I also encountered this problem in almost every primevue component, do you know if there is a general solution? or I need to find a solution for each component?
Hmmm, the problem with the :deep() selector only affects components that are attached outside the current component. With other components, :deep() should work, as suggested by the documentation. Hard to say why it is not working without looking at it.
For some reason your answer still didn’t work, what could prevent it from applying the class even though I am using pass through?
Hmm, not sure, I have added a link to a Sandbox where you can see it working.
Thank you I will try to find my issue with it
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.