Skip to content

Commit 9e3a976

Browse files
authored
Merge pull request #54 from alenaksu/fix/dont-render-filtered-elements
fix: don't render filter elements
2 parents f543a09 + 6aa2367 commit 9e3a976

File tree

1 file changed

+31
-27
lines changed

1 file changed

+31
-27
lines changed

src/JsonViewer.ts

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { html, LitElement, TemplateResult } from 'lit';
1+
import { html, LitElement, nothing, TemplateResult } from 'lit';
22
import { property, queryAll, state } from 'lit/decorators.js';
33
import { classMap } from 'lit/directives/class-map.js';
44
import { map } from 'lit/directives/map.js';
@@ -262,32 +262,36 @@ export class JsonViewer extends LitElement {
262262
const nodePath = path ? `${path}.${key}` : key;
263263
const isPrimitiveNode = isPrimitive(nodeData);
264264
const isExpanded = this.state.expanded[nodePath];
265-
266-
return html`
267-
<li
268-
part="property"
269-
role="treeitem"
270-
data-path="${nodePath}"
271-
aria-expanded="${isExpanded ? 'true' : 'false'}"
272-
tabindex="-1"
273-
.hidden="${this.state.filtered[nodePath]}"
274-
aria-hidden="${this.state.filtered[nodePath]}"
275-
>
276-
<span
277-
part="key"
278-
class="${classMap({
279-
key: key,
280-
collapsable: !isPrimitiveNode,
281-
['collapsable--collapsed']: !this.state.expanded[nodePath]
282-
})}"
283-
@click="${!isPrimitiveNode ? this.#handlePropertyClick(nodePath) : null}"
284-
>
285-
${key}: ${when(!isPrimitiveNode && !isExpanded, () => this.renderNodePreview(nodeData))}
286-
</span>
287-
288-
${when(isPrimitiveNode || isExpanded, () => this.renderValue(nodeData, nodePath))}
289-
</li>
290-
`;
265+
const isFiltered = this.state.filtered[nodePath];
266+
267+
return isFiltered
268+
? nothing
269+
: html`
270+
<li
271+
part="property"
272+
role="treeitem"
273+
data-path="${nodePath}"
274+
aria-expanded="${isExpanded ? 'true' : 'false'}"
275+
tabindex="-1"
276+
.hidden="${this.state.filtered[nodePath]}"
277+
aria-hidden="${this.state.filtered[nodePath]}"
278+
>
279+
<span
280+
part="key"
281+
class="${classMap({
282+
key: key,
283+
collapsable: !isPrimitiveNode,
284+
['collapsable--collapsed']: !this.state.expanded[nodePath]
285+
})}"
286+
@click="${!isPrimitiveNode ? this.#handlePropertyClick(nodePath) : null}"
287+
>
288+
${key}:
289+
${when(!isPrimitiveNode && !isExpanded, () => this.renderNodePreview(nodeData))}
290+
</span>
291+
292+
${when(isPrimitiveNode || isExpanded, () => this.renderValue(nodeData, nodePath))}
293+
</li>
294+
`;
291295
})}
292296
</ul>
293297
`;

0 commit comments

Comments
 (0)