Skip to content
This repository has been archived by the owner on Oct 26, 2021. It is now read-only.

Trigger attribute-changed-callback for different attribute capitalization #168

Closed
wants to merge 1 commit into from

Conversation

TimvdLippe
Copy link
Contributor

This patches setAttribute and removeAttribute to lowercase when setting attributes. I have confirmed with the implementation in Chrome that setAttributeNS and remove alike do NOT trigger the callback with different capitalization.

Fixes #167

@@ -132,7 +132,7 @@ export default function(internals) {
const oldValue = Native.Element_getAttribute.call(this, name);
Native.Element_setAttribute.call(this, name, newValue);
newValue = Native.Element_getAttribute.call(this, name);
internals.attributeChangedCallback(this, name, oldValue, newValue, null);
internals.attributeChangedCallback(this, name.toLowerCase(), oldValue, newValue, null);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be clearer to create the lowercase version of this string before the const oldValue = ... line so that it's used it in place of name when calling the native API. Even though the behavior should be the same, I think it'll be more explicit that the effects are intended for an attribute with that particular name. (Also, below in removeAttribute.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are attributes that do rely on capitalization, for example viewBox on svg: https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/viewBox If we therefore lowercase all attribute names, we would break svg.setAttribute('viewBox', '....'). I think the lowercasing should therefore only be in our callback, as we check it there with observedAttributes.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought viewBox was in the SVG namespace, so you would need to use setAttributeNS for that one? Although, I've definitely been confused when running into this sort of thing before, so I'll have to double check.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we move forward with this PR?

tests/html/Element/removeAttributeNS.html Show resolved Hide resolved
@dfreedm
Copy link
Contributor

dfreedm commented Jun 10, 2019

Issue moved to webcomponents/polyfills#110.

@dfreedm
Copy link
Contributor

dfreedm commented Jun 10, 2019

Remaking PR in monorepo

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

Successfully merging this pull request may close these issues.

4 participants