Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,13 @@
}
})

$effect(() => {
$effect.pre(() => {
if (css) {
// Reset expanded items when CSS changes to avoid null-pointers
// Runs pre-commit so this reset lands in the same render as the new
// tree_items, instead of a second full-tree render pass right after.
expanded.set([])
// eslint-disable-next-line eslint-plugin-unicorn/no-null
// eslint-disable-next-line eslint-plugin-unicorn/no-null -- null is what Melt UI wants
$selectedItem = null
search_query = ''
}
Expand Down Expand Up @@ -183,10 +185,12 @@
<section class="list">
<header>
<h2>Properties</h2>
<button type="button" onclick={() => expanded.set([])} class="collapse-all">
<Icon name="fold" size={14} />
<div class="sr-only">Collapse all</div>
</button>
{#if filtered_results !== undefined && filtered_results.size > 0}
<button type="button" onclick={() => expanded.set([])} class="collapse-all">
<Icon name="fold" size={14} />
<div class="sr-only">Collapse all</div>
</button>
{/if}
<search>
<form method="GET" onsubmit={onsearch}>
<label for="search-property" class="sr-only">Search property name</label>
Expand Down
7 changes: 4 additions & 3 deletions src/lib/components/custom-property-inspector/Tree.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
} = getContext<TreeView>('tree')
</script>

{#each items as { title, count, index, type, children, parent, location, level, name }}
{#each items as { title, count, index, type, children, parent, location, level, name } (type === 'property' ? title : `${title}-${index}`)}
{@const item_id = type === 'property' ? title : `${title}-${index}`}
{@const has_children = type == 'property'}
{@const matches = search_query === '' ? [name] : name.split(search_query)}
Expand Down Expand Up @@ -67,7 +67,7 @@
{/if}
</button>

{#if has_children && children}
{#if has_children && children && $isExpanded(item_id)}
<ul use:melt={$group({ id: item_id })}>
<Tree items={children} {search_query} />
</ul>
Expand All @@ -77,7 +77,8 @@

<style>
button[role='treeitem'] {
contain-intrinsic-size: auto 28.8px;
content-visibility: auto;
contain-intrinsic-size: auto 1.8rem;
text-align: start;
padding-inline: var(--space-2);
padding-block: 0.25rem;
Expand Down
7 changes: 7 additions & 0 deletions src/routes/(public)/custom-property-inspector/spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ test.describe('with css', () => {

// Starting state
await expect.soft(properties).toHaveCount(4)

// Locations are only rendered in the DOM once their property is expanded,
// so open every property and keep them open for the rest of the test
for (let property of await properties.all()) {
await property.click()
}

await expect.soft(locations).toHaveCount(6)
await expect.soft(unused_toggler).toHaveAttribute('aria-pressed', 'false')
await expect.soft(undefined_toggler).toHaveAttribute('aria-pressed', 'false')
Expand Down
Loading