Skip to content

Commit 134920a

Browse files
committed
fix: Standardize filter params for class
1 parent 5b5afe4 commit 134920a

File tree

3 files changed

+5
-3
lines changed

3 files changed

+5
-3
lines changed

src/getClasses.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export function getClasses( el, filter )
1616

1717
try {
1818
return Array.prototype.slice.call( el.classList )
19-
.filter((cls) => !filter || filter('attribute', 'class', cls));
19+
.filter((cls) => !filter || filter('class', 'class', cls));
2020
} catch (e) {
2121
let className = el.getAttribute( 'class' );
2222

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const attrRegex = /^attribute:(.+)/m;
1919
/**
2020
* @typedef Filter
2121
* @type {Function}
22-
* @param {string} type - the trait being considered ('attribute', 'tag', 'nth-child').
22+
* @param {string} type - the trait being considered ('attribute', 'tag', 'nth-child'). As a special case, the `class` attribute is split on whitespace and each token passed individually with a `class` type.
2323
* @param {string} key - your trait key (for 'attribute' will be the attribute name, for others will typically be the same as 'type').
2424
* @param {string} value - the trait value.
2525
* @returns {boolean} whether this trait can be used when building the selector (true = allow). Defaults to 'true' if no value returned.

test/unique-selector.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,11 @@ describe( 'Unique Selector Tests', () =>
8686

8787
it('Classes filters appropriately', () => {
8888
const filter = (type, key, value) => {
89-
if (type === 'attribute' && key === 'class') {
89+
if (key === 'class') {
90+
expect(type).to.eq('class')
9091
return value.startsWith('a')
9192
}
93+
expect(type).not.to.eq('class')
9294
return true
9395
}
9496
let el = $.parseHTML( '<div class="a1"></div>' )[0];

0 commit comments

Comments
 (0)