Skip to content

Commit 9bad70b

Browse files
committed
fix(selector): select by attribute independent of value and order
Closes #2513
1 parent 5bfcca2 commit 9bad70b

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

modules/angular2/src/render/dom/compiler/selector.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,11 @@ export class SelectorMatcher {
285285
result;
286286

287287
var partialValuesMap = MapWrapper.get(this._attrValuePartialMap, attrName);
288+
if (!StringWrapper.equals(attrValue, _EMPTY_ATTR_VALUE)) {
289+
result = this._matchPartial(partialValuesMap, _EMPTY_ATTR_VALUE, cssSelector,
290+
matchedCallback) ||
291+
result;
292+
}
288293
result =
289294
this._matchPartial(partialValuesMap, attrValue, cssSelector, matchedCallback) || result;
290295
}

modules/angular2/test/render/dom/compiler/selector_spec.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,24 @@ export function main() {
6868
expect(matcher.match(CssSelector.parse('[someAttr][someAttr2]')[0], selectableCollector))
6969
.toEqual(true);
7070
expect(matched).toEqual([s1[0], 1, s2[0], 2]);
71+
72+
reset();
73+
expect(matcher.match(CssSelector.parse('[someAttr=someValue][someAttr2]')[0],
74+
selectableCollector))
75+
.toEqual(true);
76+
expect(matched).toEqual([s1[0], 1, s2[0], 2]);
77+
78+
reset();
79+
expect(matcher.match(CssSelector.parse('[someAttr2][someAttr=someValue]')[0],
80+
selectableCollector))
81+
.toEqual(true);
82+
expect(matched).toEqual([s1[0], 1, s2[0], 2]);
83+
84+
reset();
85+
expect(matcher.match(CssSelector.parse('[someAttr2=someValue][someAttr]')[0],
86+
selectableCollector))
87+
.toEqual(true);
88+
expect(matched).toEqual([s1[0], 1, s2[0], 2]);
7189
});
7290

7391
it('should select by attr name only once if the value is from the DOM', () => {

0 commit comments

Comments
 (0)