Skip to content

Commit da4c4c0

Browse files
authored
fix(filtered-list) Filter when document changes (openscd#1077)
* Improve filtering behaviour on document changes, closes openscd#1018 * Add test for activated property in filtered list * Call super in updated method
1 parent f262cae commit da4c4c0

File tree

2 files changed

+26
-11
lines changed

2 files changed

+26
-11
lines changed

src/filtered-list.ts

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import { List } from '@material/mwc-list';
1818
import { ListBase } from '@material/mwc-list/mwc-list-base';
1919
import { ListItemBase } from '@material/mwc-list/mwc-list-item-base';
2020
import { TextField } from '@material/mwc-textfield';
21-
import { ReportControlElementEditor } from './editors/publisher/report-control-element-editor';
2221

2322
function slotItem(item: Element): Element {
2423
if (!item.closest('filtered-list') || !item.parentElement) return item;
@@ -46,14 +45,14 @@ function hideFiltered(item: ListItemBase, searchText: string): void {
4645
.split(/\s+/g);
4746

4847
(terms.length === 1 && terms[0] === '') ||
49-
terms.every(term => {
50-
// regexp escape
51-
const reTerm = new RegExp(
52-
`*${term}*`.replace(/\*/g, '.*').replace(/\?/g, '.{1}'),
53-
'i'
54-
);
55-
return reTerm.test(filterTarget);
56-
})
48+
terms.every(term => {
49+
// regexp escape
50+
const reTerm = new RegExp(
51+
`*${term}*`.replace(/\*/g, '.*').replace(/\?/g, '.{1}'),
52+
'i'
53+
);
54+
return reTerm.test(filterTarget);
55+
})
5756
? slotItem(item).classList.remove('hidden')
5857
: slotItem(item).classList.add('hidden');
5958
}
@@ -115,6 +114,14 @@ export class FilteredList extends ListBase {
115114
this.requestUpdate();
116115
}
117116

117+
protected update(
118+
changedProperties: Map<string | number | symbol, unknown>
119+
): void {
120+
super.update(changedProperties);
121+
// regenerate filtering of text
122+
this.onFilterInput();
123+
}
124+
118125
constructor() {
119126
super();
120127
this.addEventListener('selected', () => {
@@ -129,8 +136,8 @@ export class FilteredList extends ListBase {
129136
?indeterminate=${!this.isAllSelected && this.isSomeSelected}
130137
?checked=${this.isAllSelected}
131138
@change=${() => {
132-
this.onCheckAll();
133-
}}
139+
this.onCheckAll();
140+
}}
134141
></mwc-checkbox
135142
></mwc-formfield>`
136143
: html``;

test/unit/filtered-list.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ describe('filtered-list', () => {
4040
await expect(element).shadowDom.to.equalSnapshot();
4141
});
4242

43+
it('allows items to be activated when selected', async () => {
44+
element.setAttribute('activatable', '');
45+
element.children[0].setAttribute('selected', '');
46+
element.requestUpdate();
47+
await element.updateComplete;
48+
expect(element.children[0].hasAttribute('activated')).to.be.true;
49+
});
50+
4351
describe('has a check all checkbox that', () => {
4452
it('is indeterminate if one but not all check-list-items are selected', async () => {
4553
expect(

0 commit comments

Comments
 (0)