color-mode icon indicating copy to clipboard operation
color-mode copied to clipboard

data-theme and class configuration

Open sidewinda opened this issue 2 years ago • 3 comments

I have some questions about the configuration after the latest updates to support data attributes.

1 - Is there a way to use only the class or an data attribute? It seems there is always an data attribute, even if it's not set up in the configuration. I thought I missed something but your own website also has the following HTML-Tag

<html class="dark" data-="dark">

The "data-" part seems to be unnecessary.


2 - If I set a data attribute, is it possible to disable the changes for the regular CSS class?


3 - When I configure a data attribute my HTML-Tag gets an element "data-head-attrs="data-theme"

What is this exactly for? Never seen this before in combination with a theme switch.

sidewinda avatar Jul 05 '22 01:07 sidewinda

The data-="dark" attribute is sth to support daisy-ui theming: pull/144. You can set it like following to have <html data-theme="dark"> tag:

// nuxt.config.js
module.exports = {
  ...
  colorMode: {
    dataValue: 'theme'
  }
}

BkunS avatar Jul 17 '22 09:07 BkunS

The data-="dark" attribute is sth to support daisy-ui theming: pull/144. You can set it like following to have <html data-theme="dark"> tag:

// nuxt.config.js
module.exports = {
  ...
  colorMode: {
    dataValue: 'theme'
  }
}

Yes, I noticed that but like I said in my original post: What if I don't want to to use the Data Attribute? If you don't set the "dataValue" in the confiig it still outputs this incomplete code part "data-="dark".

sidewinda avatar Jul 17 '22 11:07 sidewinda

I think data-="dark" is a bug, do you have a small reproduction please?

atinux avatar Sep 09 '22 08:09 atinux

I think data-="dark" is a bug, do you have a small reproduction please?

Hello sir ! Just landed here because the "dark:" prefix in nuxt-tailwindcss doesn't work (for example with dark:bg-slate-700, because of this data-="dark" attribute. When I modify the HTML code of my page to set data-mode="dark", then it works.

And for a reproduction, you can actually look in the source code of https://color-mode.nuxtjs.org/ and I think in every use of the plugin. On this website, the first line (whether it's light or dark mode) looks like this :

<html class="light" data-="light">

My nuxt.config.ts contained this line :

colorMode: { classSuffix: ''},

and after reading this issue I modified it and now it's this line :

colorMode: { classSuffix: '', dataValue: 'mode' },

and now the dark: prefixes in tailwind classes are correctly parsed.

mathieunicolas avatar Oct 02 '22 23:10 mathieunicolas

This is a build/treeshaking issue. In the script:

if (dataValue) {
  de.setAttribute('data-' + dataValue, value)
 }

is being transformed into:

{
  de.setAttribute('data-' + dataValue, value)
}

(See https://unpkg.com/browse/@nuxtjs/[email protected]/dist/script.mjs.)

danielroe avatar Oct 04 '22 10:10 danielroe

Can you try with 3.1.7 ?

atinux avatar Oct 04 '22 15:10 atinux