Skip to content

Commit 25d82d9

Browse files
committed
Include default false change that I missed from #128426/
1 parent 91b71c1 commit 25d82d9

File tree

2 files changed

+25
-8
lines changed

2 files changed

+25
-8
lines changed

src/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ class FilterInputElement extends HTMLElement {
1717
super()
1818
this.currentQuery = null
1919
this.filter = null
20-
this.debounceInputChange = debounce(() => filterResults(this))
20+
this.debounceInputChange = debounce(() => filterResults(this, true))
2121
this.boundFilterResults = () => {
22-
filterResults(this)
22+
filterResults(this, false)
2323
}
2424
}
2525

@@ -68,7 +68,7 @@ class FilterInputElement extends HTMLElement {
6868
}
6969
}
7070

71-
async function filterResults(filterInput: FilterInputElement, checkCurrentQuery: boolean = true) {
71+
async function filterResults(filterInput: FilterInputElement, checkCurrentQuery: boolean = false) {
7272
const input = filterInput.input
7373
if (!input) return
7474
const query = input.value.toLowerCase()

test/test.js

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ describe('filter-input', function() {
2727
<li>Hubot</li>
2828
<li>Wall-E</li>
2929
<li>BB-8</li>
30-
<li>R2-D2</li>
3130
</ul>
3231
<p data-filter-empty-state hidden>0 robots found.</p>
3332
</div>
@@ -51,7 +50,7 @@ describe('filter-input', function() {
5150
assert.equal(results.length, 1)
5251
assert.equal(results[0].textContent, 'Hubot')
5352
assert.equal(customEvent.detail.count, 1)
54-
assert.equal(customEvent.detail.total, 5)
53+
assert.equal(customEvent.detail.total, 4)
5554
changeValue(input, 'boom')
5655
assert.notOk(emptyState.hidden, 'Empty state should be shown')
5756
})
@@ -64,10 +63,28 @@ describe('filter-input', function() {
6463
changeValue(input, ':)')
6564
const customEvent = await listener
6665
const results = Array.from(list.children).filter(el => !el.hidden)
67-
assert.equal(results.length, 3)
66+
assert.equal(results.length, 2)
6867
assert.equal(results[0].textContent, 'Wall-E')
69-
assert.equal(customEvent.detail.count, 3)
70-
assert.equal(customEvent.detail.total, 5)
68+
assert.equal(customEvent.detail.count, 2)
69+
assert.equal(customEvent.detail.total, 4)
70+
})
71+
72+
it('filters again with the same value when a change event is fired', async function() {
73+
const listener = once('filter-input-updated')
74+
changeValue(input, '-')
75+
const customEvent = await listener
76+
assert.equal(customEvent.detail.count, 2)
77+
assert.equal(customEvent.detail.total, 4)
78+
79+
const newRobot = document.createElement('li')
80+
newRobot.textContent = 'R2-D2'
81+
list.append(newRobot)
82+
83+
const listener2 = once('filter-input-updated')
84+
changeValue(input, '-')
85+
const customEvent2 = await listener2
86+
assert.equal(customEvent2.detail.count, 3)
87+
assert.equal(customEvent2.detail.total, 5)
7188
})
7289
})
7390
})

0 commit comments

Comments
 (0)