Skip to content

Commit 11e8197

Browse files
committed
Convert Toggle to a controlled component
1 parent 2dd3ea2 commit 11e8197

File tree

4 files changed

+32
-24
lines changed

4 files changed

+32
-24
lines changed

site/frontend/src/pages/compare/header/data-selector.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,13 @@ function submitSettings() {
3737
const params = {start, end, stat};
3838
emit("change", params);
3939
}
40+
41+
const opened = ref(false);
4042
</script>
4143

4244
<template>
4345
<fieldset class="settings">
44-
<Toggle>
46+
<Toggle :opened="opened" @change="(value) => (opened = value)">
4547
<template #label>Do another comparison</template>
4648
<template #content>
4749
<div class="commits section">

site/frontend/src/pages/compare/header/filters.vue

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,17 @@ watch(
2929
},
3030
{deep: true}
3131
);
32+
33+
function updateOpened(opened: boolean) {
34+
filterOpened.value = opened;
35+
}
36+
37+
const filterOpened = ref(false);
3238
</script>
3339

3440
<template>
3541
<fieldset class="collapsible-section">
36-
<Toggle :defaultOpened="false">
42+
<Toggle :opened="filterOpened" @change="updateOpened">
3743
<template #label>Filters</template>
3844
<template #content>
3945
<div>
@@ -46,9 +52,8 @@ watch(
4652
<div style="width: 160px">
4753
<span>Profiles</span>
4854
<Tooltip
49-
>The different compilation profiles (check, debug, opt,
50-
doc).</Tooltip
51-
>
55+
>The different compilation profiles (check, debug, opt, doc).
56+
</Tooltip>
5257
</div>
5358
</div>
5459
<ul class="states-list">
@@ -84,9 +89,8 @@ watch(
8489
<span class="cache-label">opt</span>
8590
</label>
8691
<Tooltip
87-
>Release build that produces as optimized code as
88-
possible.</Tooltip
89-
>
92+
>Release build that produces as optimized code as possible.
93+
</Tooltip>
9094
</li>
9195
<li>
9296
<label>
@@ -125,9 +129,8 @@ watch(
125129
<span class="cache-label">full</span>
126130
</label>
127131
<Tooltip
128-
>A non-incremental full build starting with empty
129-
cache.</Tooltip
130-
>
132+
>A non-incremental full build starting with empty cache.
133+
</Tooltip>
131134
</li>
132135
<li>
133136
<label>
@@ -139,8 +142,8 @@ watch(
139142
<span class="cache-label">incr-full</span>
140143
</label>
141144
<Tooltip
142-
>An incremental build starting with empty cache.</Tooltip
143-
>
145+
>An incremental build starting with empty cache.
146+
</Tooltip>
144147
</li>
145148
<li>
146149
<label>
@@ -181,8 +184,8 @@ watch(
181184
<span>Categories</span>
182185
<Tooltip
183186
>Select benchmarks based on their category (primary or
184-
secondary).</Tooltip
185-
>
187+
secondary).
188+
</Tooltip>
186189
</div>
187190
</div>
188191
<ul class="states-list">

site/frontend/src/pages/compare/summary/aggregations.vue

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import {computeSummary, SummaryGroup, TestCase} from "../data";
33
import Toggle from "../toggle.vue";
44
import SummaryTable from "./summary-table.vue";
5+
import {ref} from "vue";
56
67
const props = defineProps<{
78
cases: TestCase[];
@@ -19,11 +20,13 @@ function calculateSummary(
1920
}
2021
return computeSummary(benchmarks);
2122
}
23+
24+
const opened = ref(false);
2225
</script>
2326

2427
<template>
2528
<fieldset class="collapsible-section">
26-
<Toggle>
29+
<Toggle :opened="opened" @change="(value) => (opened = value)">
2730
<template #label>Aggregations</template>
2831
<template #content>
2932
<div>

site/frontend/src/pages/compare/toggle.vue

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
<script setup lang="ts">
2-
import {ref} from "vue";
3-
42
const props = withDefaults(
53
defineProps<{
6-
defaultOpened?: boolean;
4+
opened?: boolean;
75
}>(),
86
{
9-
defaultOpened: false,
7+
opened: false,
108
}
119
);
1210
13-
const opened = ref(props.defaultOpened);
11+
const emit = defineEmits<{
12+
(e: "change", opened: boolean): void;
13+
}>();
1414
</script>
1515

1616
<template>
17-
<legend class="toggle section-heading" @click="opened = !opened">
17+
<legend class="toggle section-heading" @click="emit('change', !props.opened)">
1818
<slot name="label"></slot>
19-
<span>{{ opened ? " ▼" : " ▶" }}</span>
19+
<span>{{ props.opened ? " ▼" : " ▶" }}</span>
2020
</legend>
21-
<div v-show="opened">
21+
<div v-show="props.opened">
2222
<slot name="content"></slot>
2323
</div>
2424
</template>

0 commit comments

Comments
 (0)