vuematerial / vue-material

Vue.js Framework - ready-to-use Vue components with Material Design, free forever.
https://www.creative-tim.com/vuematerial
MIT License
9.89k stars 1.15k forks source link

md-option doesn't accept non-text prop #2116

Open chrislebaron opened 5 years ago

chrislebaron commented 5 years ago

md-option will not accept a slot that includes anything other than text elements. If you try to pass HTML or an icon etc, it will throw a nasty error in your face because of the way the getTextContent function is written.

Which browser?

All

What is expected?

Should be able to pass a slot with whatever HTML you want

What is actually happening?

An error is thrown in the getTextContent function because it hits an undefined value if you pass HTML into the slot.

Proposed fix

The getTextContent function could be redefined like this to avoid failure if HTML content is passed in:

getTextContent (children) {
        let that = this;
        return children.map(function (node) {
          return node.children
                  ? that.getTextContent(node.children)
                  : node.text
        }).join('')
      },

The setItem function could be redefined like this:

setItem () {
        this.$set(this.MdSelect.items, this.key, this.getTextContent(this.$slots.default))
}