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

Class names aren't merged correctly when ...attributes is specified first #17692

Closed
GavinJoyce opened this issue Mar 2, 2019 · 10 comments
Closed

Comments

@GavinJoyce
Copy link
Member

GavinJoyce commented Mar 2, 2019

There seems to be a difference in how attributes are merged depending on the position of ...attributes within an element. The RFC doesn't seem to specify what the behaviour should be, I'm assuming that position shouldn't matter as otherwise it would likely be a source of confusion.

With the following Foo component template:

<div class="inner" ...attributes />
<div ...attributes class="inner" />

And the following invocation:

<Foo class="outer />

The result is:

<div class="inner outer" />
<div class="outer" />

update: After trying to write a failing test in glimmer-vm, it appears that the classes should be merged and the order will be different. The output should be:

<div class="inner outer" />
<div class="outer inner" />
@GavinJoyce
Copy link
Member Author

Failing test: #17693

@GavinJoyce
Copy link
Member Author

GavinJoyce commented Mar 2, 2019

I tried to write a similar failing test in glimmer-vm, it appears to work correctly there:

GavinJoyce/glimmer-vm#1

@rwjblue
Copy link
Member

rwjblue commented Mar 2, 2019

The order was actually intended to matter, though we do have a bug in class merging still (#17533 tracks that) which is what I think you are really reporting here.

The idea was that you could use the location of ...attributes to control if a given attribute could or could not be "clobbered" by your caller.

For example, given these two possibilities:

<div data-foo="inner" ...attributes></div>
<div ...attributes data-foo="inner"></div>

With this invocation:

<Foo data-foo="outer" />

We expect the location of ...attributes to affect the final result:

<div data-foo="outer"></div>
<div data-foo="inner"></div>

@rwjblue
Copy link
Member

rwjblue commented Mar 2, 2019

Also, RE: this working correctly in glimmer-vm, thats because the system doing the merging was overhauled in glimmer-vm but we haven't gotten Ember updated to the newer version (there were breaking changes, and its a bit of work to figure out what exactly is needed to do an upgrade).

@GavinJoyce
Copy link
Member Author

👍 thanks for the explanation. It looks like the tests in #17533 are similar so I'll close #17693.

I'll leave this issue open so that it's discoverable for anyone else hitting the bug

@MelSumner
Copy link
Contributor

If it helps, this would also matter for aria-labelledby because you can concatenate a label from several text nodes- see https://www.w3.org/WAI/GL/wiki/Using_aria-labelledby_to_concatenate_a_label_from_several_text_nodes

@rwjblue
Copy link
Member

rwjblue commented Mar 3, 2019

@MelSumner - Good catch! I think we'll need a small RFC to tweak that behavior since the merged RFC explicitly states that class is the only execption:

This means that attributes provided by the caller will override (replace) those added by the component (except for class, which is merged).

@MelSumner
Copy link
Contributor

MelSumner commented Mar 4, 2019

for attributes coming from ARIA, there are five whose value is an ID reference list (meaning, they can have one or more values):

  • aria-controls - It seems like the order could possibly matter in some instances.
  • aria-describedby: order definitely matters
  • aria-flowto - the order could matter, depending on intent of content.
  • aria-labelledby - order definitely matters
  • aria-owns Order could matter, depending on design intent (if someone is using this, really we should make them stop and think twice tbh, it's smelly),

@rwjblue
Copy link
Member

rwjblue commented Mar 6, 2019

👍 thank you for researching that! We should totally do an RFC to get those added to the "plz merge, don't clobber" list. During that RFC cycle we should try to see if there are other attributes like this that should be considered...

wycats pushed a commit that referenced this issue Apr 6, 2019
(beta will need a different version)

Closes #17533, #17692.
wycats pushed a commit that referenced this issue Apr 6, 2019
wycats pushed a commit that referenced this issue Apr 6, 2019
(beta will need a different version)

Closes #17533, #17692.
wycats pushed a commit that referenced this issue Apr 6, 2019
@chancancode
Copy link
Member

This (the bug in the original thread) should now be fixed on canary and beta!

wycats pushed a commit that referenced this issue Apr 9, 2019
Closes #17533, #17692.

(cherry picked from commit 2a96c78)
(cherry picked from commit 61c1830)
@rwjblue rwjblue closed this as completed Apr 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants