weex icon indicating copy to clipboard operation
weex copied to clipboard

[Discuss] Reset class style for element

Open terrykingcha opened this issue 10 years ago • 6 comments

There are problems about reset class styles. This is the exmaple(or like this issue #218 ):

<template>
  <div>
    <text class="{{className}}" onclick="toggle">Hello Weex</text>
  </div>
</template>

<style>
.normal {
  font-size: 40px;
}

.hightlight {
  font-size: 40px;
  color: red;
}
</style>

<script>
module.exports = {
  data: {
    className: 'highlight'
  },
  methods: {
    toggle: function() {
      if (this.className === 'normal') {
         this.className = 'hightlight'
      } else {
        this.className = 'normal'
      }
    }
  }
}
</script>

When click the text, the color of the text is still red. Because we have no way to clear the last class style.

So maybe we can give the style a empty value(string) to clear the style through calling 'updateStyles'.

What's your opinion?

terrykingcha avatar Jun 03 '16 06:06 terrykingcha

This could work on h5-render after changing some valueFilter stuff.

MrRaindrop avatar Jun 03 '16 06:06 MrRaindrop

Removing style should mean "backing to the default style", but an empty string is meaningful for some styles , especially for extending components, it's difficult for them to understand. Anyway, now passing an empty string to remove style is working for most of styles.

cxfeng1-zz avatar Jun 03 '16 07:06 cxfeng1-zz

In CSS spec, a empty string will reset the style. Maybe it's the common way to do this.

terrykingcha avatar Jun 06 '16 06:06 terrykingcha

@Hanks10100 Please have a look at this issue. Thanks.

Jinjiang avatar Aug 03 '16 00:08 Jinjiang

After fixed this bug in #953 , jsfm will set empty string on the style which need to be reset. I'm sure it works well on HTML5. I hope this feature could be fully support by native.

Hanks10100 avatar Aug 11 '16 11:08 Hanks10100

Though the code merged into jsfm branch, maybe more discussion needed with the native part about the detail of sending default value. @Hanks10100 @cxfeng1 @zshshr Thanks.

Jinjiang avatar Aug 11 '16 15:08 Jinjiang