question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

"class" and "style" attributes have no effect on functional SFC components

See original GitHub issue

Version

2.5.16

Reproduction link

https://github.com/padcom/vue-functional-no-class-passed

Steps to reproduce

What is expected?

Functional component is painted in green/red by applying the items CSS class and color: red style

What is actually happening?

The items CSS class nor style is not applied


I am mostly using the added class in components for BEM-style annotations where a component is at the same time an element from the point of view of the container and a block from its personal point of view thus allowing me to delegate certain properties to the container, like positioning for example. I’d like to use that same principle in functional components, for example with transition-group that has the option to specify the tag attribute. It works with statefull components but functional components fail to pass the class and style properties when rendering.

Please note that the functional components declared in the example repository do contain the v-bind="data.attrs" and v-on="listeners" attributes on the root node as described in the documentation.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

19reactions
padcomcommented, Apr 9, 2018

This would also work in an SFC but it is ugly:

<template functional>
  <div v-bind="data.attrs" :class="data.staticClass" :style="data.staticStyle">
    Functional component
  </div>
</template>
9reactions
padcomcommented, Apr 9, 2018

I think I have it! SFC’s seem to be very powerful and that I like very much:

<script>
export default {
  functional: true,
  render: (h, { data, children }) => (
    <transition-group { ...data} tag="ul" name="slide">
      { children }
    </transition-group>
  )
}
</script>

<style>
.slide-move {
  transition: transform 1s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}
</style>

That is very elegant 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

SFC CSS Features - Vue.js
DOM content created with v-html are not affected by scoped styles, but you can still style them using deep selectors. Slotted Selectors #....
Read more >
vue.js - Scoped CSS not being applied within the component
The <style> uses the scoped attribute. When applied, the CSS does not get loaded in. When scoped is removed, it does get applied....
Read more >
Why I'm not a fan of Single File Components
I want to talk about the limitation of SFCs as a component format. To me, this topic is a lot like discussing the...
Read more >
Components and Props - React
Components let you split the UI into independent, reusable pieces, and think about each piece in isolation. This page provides an introduction to...
Read more >
How to Create Single File Components in VueJS (A Tutorial)
CSS/styling information is included in the component definition. ... your project is created, this folder will contain an index.html file:.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found