shakee93 / vue-toasted

🖖 Responsive Touch Compatible Toast plugin for VueJS 2+
https://shakee93.github.io/vue-toasted/
MIT License
2.21k stars 194 forks source link

Icon string with multiple lines throws error #88

Closed greggilbert closed 5 years ago

greggilbert commented 5 years ago

Given this:

    var self = this;
    this.$toasted.show('Hello, this is a test!', {
      icon: {
        name: 'fas fa-check-circle'
      }
    });

throws this error:

[Vue warn]: Error in created hook: "InvalidCharacterError: String contains an invalid character"

Specifically this:

The token provided ('fas fa-check-circle') contains HTML space characters, which are not valid in tokens

Per the docs it should work fine. Any ideas?

rizzdev commented 5 years ago

any idea on this one?

robjbrain commented 5 years ago

Having this exact same error when using an example straight from the docs

docs: https://github.com/shakee93/vue-toasted/blob/master/examples/using-icons.js

example:

Vue.toasted.show(
    'hello there, i am a toast !!', {
        icon: {
            name: 'fal fa-check fa-spin fa-fw',
        }
    });

results in:

DOMException: Failed to execute 'add' on 'DOMTokenList': The token provided ('fal fa-check fa-spin fa-fw') contains HTML space characters, which are not valid in tokens.

Did either of you resolve this @rizzdev or @greggilbert ?

robjbrain commented 5 years ago

It seems to come from here: https://github.com/shakee93/vue-toasted/blob/8e49008aefec53331f30f5dd75e7c113bd3580ee/src/js/show.js#L190-L197

The name is put into classList.add which only accepts one string at a time.

There's a commit here which seems to allow for adding an array of classes (at least that's what the commit message says) https://github.com/shakee93/vue-toasted/commit/7f32d03eef40305cecb202fc5375e82bcaf63aff#diff-20d2b7593390e44ab67b3919ea1ececc

but it only works for the "custom-class" option.

So you would have to do this:

Vue.toasted.show(
    'hello there, i am a toast !!', {
        iconPack: 'custom-class',
        icon: {
            name: 'fas fa-spinner fa-spin',
        }
    });

I'm not sure if it's a case of the documentation needing updating or the code needing fixing, @shakee93 ?

shakee93 commented 5 years ago

you can use "custom-class" and achieve this.