Skip to content

Commit

Permalink
Fix sticky tabs and filters
Browse files Browse the repository at this point in the history
* expose stickyIndicator from AuditGenerationHeader

* watch for ref updates in AuditGenerationPage

Note that nested stickyIndicator height is used with 2 sticky divs: filters and tabs
  • Loading branch information
yaaax committed Jul 11, 2024
1 parent 26cb621 commit 5c40cf8
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ defineProps<{
editUniqueId?: string;
}>();
const stickyIndicator = ref<HTMLDivElement>();
defineExpose({
stickyIndicator
});
const isOffline = useIsOffline();
const router = useRouter();
Expand Down Expand Up @@ -219,7 +225,7 @@ onMounted(() => {

<h1>{{ auditName }}</h1>

<div id="sticky-indicator" class="sticky-indicator fr-grid-row fr-mb-3w">
<div ref="stickyIndicator" class="sticky-indicator fr-grid-row fr-mb-3w">
<div
v-if="!systemStore.isOnline"
id="offlineAlert"
Expand Down
30 changes: 23 additions & 7 deletions confiture-web-app/src/pages/audit/AuditGenerationPage.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script setup lang="ts">
import { sortBy } from "lodash-es";
import { computed, onMounted, ref, watch } from "vue";
import { computed, onBeforeUnmount, onMounted, ref, watch } from "vue";
import { onBeforeRouteLeave, useRoute } from "vue-router";
import AraTabs from "../../components/audit/AraTabs.vue";
Expand All @@ -16,7 +16,7 @@ import rgaa from "../../criteres.json";
import { CRITERIA_BY_AUDIT_TYPE } from "../../criteria";
import { useAuditStore, useFiltersStore, useResultsStore } from "../../store";
import { AuditPage, AuditType, CriteriumResultStatus } from "../../types";
import { getCriteriaCount, pluralize, waitForElement } from "../../utils";
import { getCriteriaCount, pluralize } from "../../utils";
const route = useRoute();
Expand Down Expand Up @@ -151,13 +151,28 @@ watch(
);
// Observe the height of the sticky indicator and sync the `top` CSS property with it.
const stickyTop = ref("0");
const auditGenerationHeader = ref<InstanceType<
typeof AuditGenerationHeader
> | null>(null);
const stickyTop = ref<string>("0");
let resizeObserver: ResizeObserver | null = null;
onMounted(async () => {
const el = await waitForElement("#sticky-indicator");
const resizeObserver = new ResizeObserver((entries) => {
stickyTop.value = entries[0].target.clientHeight + "px";
// Because auditGenerationHeader ref is inside a "v-if",
// Vue will not instantiate the ref immediately.
// We need to watch it before observing nested stickyIndicator
watch(auditGenerationHeader, async () => {
const stickyIndicator = auditGenerationHeader.value?.stickyIndicator;
resizeObserver = new ResizeObserver((entries) => {
stickyTop.value = entries[0].target.clientHeight + "px";
});
stickyIndicator && resizeObserver.observe(stickyIndicator);
});
resizeObserver.observe(el);
});
onBeforeUnmount(() => {
const stickyIndicator = auditGenerationHeader.value?.stickyIndicator;
stickyIndicator && resizeObserver?.unobserve(stickyIndicator);
});
const pageTitle = computed(() => {
Expand Down Expand Up @@ -214,6 +229,7 @@ const tabsData = computed((): TabData[] => {
/>

<AuditGenerationHeader
ref="auditGenerationHeader"
:audit-name="auditStore.currentAudit.procedureName"
:key-infos="headerInfos"
:audit-publication-date="auditStore.currentAudit.publicationDate"
Expand Down

0 comments on commit 5c40cf8

Please sign in to comment.