#How to apply initial data attributes to body?

24 messages · Page 1 of 1 (latest)

shadow sky
#

Hello, I was using I think nuxt rc 13 and to set data attribute on body tag I used bodyAttrs like so

useHead({
  bodyAttrs: {
    'data-is-nav-open': 'false',
  },
})

But after updating to Nuxt 3.0.0 (at least that's when I think it broke, pretty sure it worked earlier) it no longer does anything. Any idea how to apply initial data attribute to body tag?

#

How to apply initial data attributes to body?

timber timber
#
export default defineNuxtConfig({
   app: {
        head: {
            bodyAttrs: {
              class: 'loading',
              'data-test': 'test'
            }
         }
    }
});
shadow sky
#

I put this in defineNuxtConfig and while class and favicon work fine, data doesn't. What Nuxt version do you have your snippet running on if I may ask?

app: {
  head: {
    link: [{ rel: 'icon', type: 'image/svg+xml', href: '/favicon.svg' }],
    bodyAttrs: {
      'class': 'font-sans',
      'data-is-nav-open': 'false',
    },
  },
},
timber timber
#

data works for me on nuxt 3

#

does 'data-test': 'test' work?

shadow sky
#

Nothing here 😦

#

'data-test': 'test' works :////

#

Looks like setting value to 'false' is the problem

#

'data-is-nav-open': 'test' this works fine too

timber timber
#

it's probably interpreting it as being false which unsets it

#

what about 'true'

shadow sky
#

Leaves it empty

#

Damn looks like yes and no it is :/

timber timber
#

could also do data-nav=open/closed

shadow sky
#

Better than yes/no i guess. Thanks for help ❤️

timber timber
#

👍

toxic stream
#

so either check that the attribute doesn't exist instead of checking for false

#

or change the values as posted above

timber timber
#

right but it's a string, not actually a boolean, so i understand the confusion

shadow sky
toxic stream
#

Use a not css selector?