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

PrimeNG18 Beta: Dark mode selector not applied #16356

Closed
Szanik opened this issue Sep 7, 2024 · 11 comments
Closed

PrimeNG18 Beta: Dark mode selector not applied #16356

Szanik opened this issue Sep 7, 2024 · 11 comments
Labels
Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible

Comments

@Szanik
Copy link

Szanik commented Sep 7, 2024

Describe the bug

Using the new primeng 18 beta 1 version.
tailwindcss is installed like in the documentation and i am using the primeconfig like this:

 this.config.theme.set({
      preset: Noir,
      options: {
        prefix: 'p',
        darkModeSelector: '.my-dark',
        cssLayer: false
      }
    }
    );

now i am using in a normak div this class:
bg-surface-0 dark:bg-amber-400

The div is always displayed in amber.
Doesn't matter if the html has the class="my-dark" or not.

Interestingly. If I change the darkModeSelector to system and simulate the preferred-color-scheme with the dev console the colors are shown correctly.

Maybe a bug, or maybe I am using this wrong.

Also are there documentations on what css classes to use when using primeng?
Or should one use the tailwindcss classnames?

thank you

Environment

primeng 18 beta 1
angular 18.2
tailwindcss-primeui: ^0.3.4
tailwindcss: "3.4.10

Reproducer

No response

Angular version

18.2

PrimeNG version

18.beta.1

Build / Runtime

Angular CLI App

Language

TypeScript

Node version (for AoT issues node --version)

20.15.0

Browser(s)

Edge 128

Steps to reproduce the behavior

No response

Expected behavior

No response

@Szanik Szanik added the Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible label Sep 7, 2024
@hm-kynecto
Copy link

was just playing with this on angular 19 with tailwind and primeng v18 beta

this._primeConfig.theme.set({
      preset: Lara,
      options: {
        darkModeSelector: '.prime-dark-mode',
      },
    });

and then when I set my theme in my app I just listen for the changes

 const element = document.querySelector('html');
        if (this.config.scheme === 'light') {
          element?.classList.remove('prime-dark-mode');
        }
        if (this.config.scheme === 'dark') {
          element?.classList.add('prime-dark-mode');
        }

not doing auto in my app though

maybe some use to you @Szanik

@Szanik
Copy link
Author

Szanik commented Sep 8, 2024

Yes, that code also works for me.
I was wondering about this classes tho:
bg-surface-0 dark:bg-amber-400
i have this classNames in a div.

only the bg-amber-400 is visible. doesn't matter if prime-dark-mode is set on the html or not.
Maybe it's not the way to style a div in primeng18?

@mehmetcetin01140 mehmetcetin01140 added Resolution: Cannot Replicate Issue could not be replicated by Core Team and removed Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible labels Sep 10, 2024
Copy link

We're unable to replicate your issue, if you are able to create a reproducer by using PrimeNG Issue Template or add details please edit this issue. This issue will be closed if no activities in 20 days.

@Szanik
Copy link
Author

Szanik commented Sep 11, 2024

Sure here is a stackblotz link:
StackBlitz

Hope that helps

P.S.
can you also please update the issue tempalte to angular 18 in the future?

@Momme97
Copy link

Momme97 commented Sep 11, 2024

Hi, I am also facing the exact same issue. The dark mode style applies correctly but the default style has no effect.

@Szanik
Copy link
Author

Szanik commented Sep 26, 2024

@mehmetcetin01140 was the provided stackblitz any help?

@GitStorageOne
Copy link

GitStorageOne commented Oct 1, 2024

Firefox 130.0.1.
https://primeng.org (17.18.11) - Switching to dark theme works.
https://v18.primeng.org/ (beta.2) - Switching to dark theme doesn't work (even after cleaning browser cache).
(no issues with beta.1)

@Szanik
Copy link
Author

Szanik commented Oct 2, 2024

if i put cssLayers to true it works.
but then the styles of the primeng are lost.
The theming docs didn't help me further, i might not understand how it all should work here

@Szanik
Copy link
Author

Szanik commented Oct 2, 2024

I fixed the issue with this code from the docs: PrimeNG Tailwind

Still for me hard to grasp and what the problems here are. I think the documentation needs improvement or thewords "styled"/"unstyled" r misleading

import { PrimeNGConfig } from 'primeng/api;
import { Aura } from 'primeng/themes/aura';
@Component({...})
export class AppComponent() {
    constructor(private primengConfig: PrimeNGConfig) {
        this.primengConfig.theme.set({
            preset: Aura,
                options: {
                    cssLayer: {
                        name: 'primeng',
                        order: 'tailwind-base, primeng, tailwind-utilities'
                    }
                }
            })
        }
    }
}
@layer tailwind-base, primeng, tailwind-utilities;

@layer tailwind-base {
@tailwind base;
}

@layer tailwind-utilities {
@tailwind components;
@tailwind utilities;
}

@GitStorageOne Please open a new issue because it's not realated to this one. btw FireFox 126 has the same issue

EDIT:
Actually no, sorry. It helps tho.
Changing is still possible from dark to light with the html class but the tailwindcss are uneffected.
If i now additonially change, via the emulator, the preffered scheme now also the tailwindcss classes are correct

@Szanik Szanik closed this as completed Oct 2, 2024
@Szanik Szanik reopened this Oct 2, 2024
@github-actions github-actions bot added Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible and removed Resolution: Cannot Replicate Issue could not be replicated by Core Team labels Oct 2, 2024
@Szanik
Copy link
Author

Szanik commented Oct 2, 2024

i think its because i have edge on system and my system is dark, will update here more infos

@Szanik
Copy link
Author

Szanik commented Oct 2, 2024

Two Solutions:

First: Add selector to the tailwind.config.js. But then the darkmode selector from PrimeNG needs to be .dark

/** @type {import('tailwindcss').Config} */
module.exports = {
  darkMode: 'selector',
  content: [
    "./src/**/*.{html,ts}",
  ],
  theme: {
    extend: {},
  },
  plugins: [require('tailwindcss-primeui')],
}


PRIMENG:
 this.config.theme.set({
      preset: Noir,
      options: {
        prefix: 'p',
        darkModeSelector: '.dark',
        cssLayer: {
          name: 'primeng',
          order: 'tailwind-base, primeng, tailwind-utilities'
        }
      }
    }
    );

Or Second:

use another darkmode Selector:
darkMode: ['selector', '.prime-dark-mode'],

.prime-dark-mode can then be any selector u want.
But then this also needs to be the name use put in for the config for the darkModeSelect Property.
Got it from the Tailwind Docs

@Szanik Szanik closed this as completed Oct 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible
Projects
None yet
Development

No branches or pull requests

5 participants