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

[selector] Remove auto added ID on testing for selector #1927

Open
wants to merge 1 commit into
base: dev-master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/dom/js/selector-native.js
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,8 @@ var Selector = {
* @static
*/
test: function(node, selector, root) {
var ret = false,
var defaultId,
ret = false,
useFrag = false,
groups,
parent,
Expand Down Expand Up @@ -330,6 +331,7 @@ var Selector = {

id = Y.Selector._escapeId(Y.DOM.getId(node));
if (!id) {
defaultId = true;
id = Y.guid();
Y.DOM.setId(node, id);
}
Expand All @@ -352,6 +354,10 @@ var Selector = {
if (useFrag) { // cleanup
frag.removeChild(node);
}

if (defaultId) { // cleanup, remove auto generated ID
node.removeAttribute('id');
}
};
}

Expand Down
7 changes: 7 additions & 0 deletions src/dom/tests/unit/selector.html
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,11 @@
Assert.isTrue(Selector.test(Y.DOM.byId('foo-bar'), 'input#foo-bar', form));
Assert.isFalse(Selector.test(Y.DOM.byId('foo-bar'), '#test-inputs input#foo-bar', form));
Assert.isTrue(Selector.test(Y.DOM.byId('foo-bar'), '#test-inputs input#foo-bar', form.parentNode));

var strongEl = document.getElementsByTagName('strong')[0];
Selector.test(strongEl, 'strong');
Assert.isFalse(strongEl.hasAttribute('id'), 'The strong element shouldn\'t have an ID');

},

testRootQuery: function() {
Expand Down Expand Up @@ -816,5 +821,7 @@
<form id="test-chars-form">
<input id="test-chars" type="hidden" value="ML キshigo, Mfg.,& Co.">
</form>

<strong>Foo</strong>
</body>
</html>