Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can not use spaces in class names when using List/Vec #935

Closed
1 of 3 tasks
liquidnya opened this issue Feb 10, 2020 · 7 comments · Fixed by #1084
Closed
1 of 3 tasks

Can not use spaces in class names when using List/Vec #935

liquidnya opened this issue Feb 10, 2020 · 7 comments · Fixed by #1084

Comments

@liquidnya
Copy link
Contributor

Problem
When using a List (a tuple within the html! macro) or a Vec of classes and one item contains spaces e.g.

html! {
    <div class=("hello", "hello world")>{ "Example" }</div>
}

Steps To Reproduce

  1. Include the above code within a components view function.
  2. Inspect the class string or read the console of the used web browser.

Expected behavior
I expected unique class names: "hello world" or the support of non-unique class names when specifying the classes as string.

Screenshots
master (as of commit 1ede167)
image
Version 0.11.0
image
(Note that Example is not rendered)
image

Environment:

  • Yew version v0.11.0, master as of commit 1ede167
  • Rust version 1.41.0 (5e1a79984 2020-01-27)
  • stdweb / web-sys version [e.g. web-sys v0.3.33]
  • OS: Windows 10, Ubuntu 16.04.6 LTS running on WSL
  • Browser Firefox
  • Browser version 72.0.2 (64-bit)

Questionnaire

  • I'm interested in fixing this myself but don't know where to start
  • I would like to fix and I have a solution
  • I don't have time to fix this right now, but maybe later

Suggestions
I have a solution in mind for both of my expected behaviors, but i am not sure if either of them is a desired one.
Should i open another issue to suggest some kind of feature to support non-unique class names?
Non-unique class names can be desired if e.g. Semantic UI is used, which is also one reason why the ordering of classes is supported in yew: #393.
I suggest to also add documentation for the expected behavior to

@liquidnya liquidnya added the bug label Feb 10, 2020
@liquidnya liquidnya changed the title Spaces in class names when using List/Vec Can not use spaces in class names when using List/Vec Feb 10, 2020
@jstarry
Copy link
Member

jstarry commented Feb 11, 2020

@LiquidBlock by non-unique class names do you mean that class names can be repeated?

@liquidnya
Copy link
Contributor Author

@LiquidBlock by non-unique class names do you mean that class names can be repeated?

Yes

@jstarry
Copy link
Member

jstarry commented Feb 11, 2020

Should i open another issue to suggest some kind of feature to support non-unique class names?

I'm in favour of non-unique class names if it's needed for using Semantic-UI. So in that case, we could probably just change this issue to reflect supporting that feature. Thoughts?

@liquidnya
Copy link
Contributor Author

Semantic-UI has an closed issue, where they discussed the usage of repeating class names: Semantic-Org/Semantic-UI#1526
An example class string would be:

"sixteen wide mobile eight wide tablet four wide computer column"

There are some arguments about the HTML5 spec:

The classes that an HTML element has assigned to it consists of all the classes returned when the value of the class attribute is split on spaces. (Duplicates are ignored.)

As far as i am aware of, this is the reason, that https://github.com/meteor/blaze does not support repeating class names, but there is a library for meteor supporting Semantic-UI: https://github.com/Semantic-Org/Semantic-UI-Meteor
The above quote from the spec is outdated, as far as i know.

Below are some current quotes from the spec:

https://html.spec.whatwg.org/multipage/dom.html#classes

When specified on HTML elements, the class attribute must have a value that is a set of space-separated tokens representing the various classes that the element belongs to.

Which itself links to https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#set-of-space-separated-tokens:

A set of space-separated tokens is a string containing zero or more words (known as tokens) separated by one or more ASCII whitespace, where words consist of any string of one or more characters, none of which are ASCII whitespace.
[...]
An unordered set of unique space-separated tokens is a set of space-separated tokens where none of the tokens are duplicated.
An ordered set of unique space-separated tokens is a set of space-separated tokens where none of the tokens are duplicated but where the order of the tokens is meaningful.
[...]

Some things i noticed:

  • The HTML spec says that the class attribute is a set of space-separated tokens, but it does not specify neither an unordered set of unique space-separated tokens nor an ordered set of unique space-separated tokens

  • The classList attribute is defined as a set, which has a different definition:

    Some lists are designated as ordered sets. An ordered set is a list with the additional semantic that it must not contain the same item twice.

    https://dom.spec.whatwg.org/#dom-element-classlist.

  • But the className attribute is defined as must reflect the "class" content attribute.

The classList does not support for repeated class names, but i am not so sure about className or the class HTML attribute.
Maybe someone can elaborate on the definition of the spec regarding unique class names?

Regardless of the spec requiring unique names or not, i would like to suggest at least the optional usage of repeated class names.
E.g. in the case of the spec requiring unique names the cargo features feature could be used for conditional compilation options.

@jstarry
Copy link
Member

jstarry commented Mar 3, 2020

@ADustyOldMuffin you could try this issue as well. It requires less knowledge of how Yew works internally

@bryanjswift
Copy link
Contributor

I'll be honest, I did not understand the outcome of the comments about the using multiple class names. The implementation proposed in #1084 continues using the IndexSet in the current Classes struct which enforces unique class names.

@jstarry
Copy link
Member

jstarry commented Apr 14, 2020

@bryanjswift that's fine, this issue was about spaces in class names. We can create a new issue for non-unique classnames if it's really needed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants