Skip to content

Commit

Permalink
Implements saving when control leaves the viewport as the user scrolls
Browse files Browse the repository at this point in the history
  • Loading branch information
latin-panda committed Feb 10, 2025
1 parent a2a068a commit f5cace8
Showing 1 changed file with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,16 @@ const isLocating = computed(() => {
return watchID.value !== null;
});
const controlElement = ref<HTMLElement | null>(null);
const observer = new IntersectionObserver(
([entry]) => {
if (!entry.isIntersecting) {
save();
}
},
{ threshold: 0.6 }
);
const start = () => {
geoLocationError.value = false;
if (watchID.value) {
Expand All @@ -114,6 +124,8 @@ const start = () => {
},
{ enableHighAccuracy: true }
);
observer?.observe(controlElement.value);
};
const stop = () => {
Expand All @@ -123,6 +135,7 @@ const stop = () => {
navigator.geolocation.clearWatch(watchID.value);
watchID.value = null;
observer?.disconnect();
};
const save = () => {
Expand All @@ -145,7 +158,7 @@ const formatNumber = (num: number) => {
</script>

<template>
<div class="geolocation-control">
<div class="geolocation-control" ref="controlElement">

Check warning on line 161 in packages/web-forms/src/components/controls/Input/InputGeopoint.vue

View workflow job for this annotation

GitHub Actions / Lint (global) (22.12.0)

Attribute "ref" should go before "class"

Check warning on line 161 in packages/web-forms/src/components/controls/Input/InputGeopoint.vue

View workflow job for this annotation

GitHub Actions / Lint (global) (22.12.0)

Attribute "ref" should go before "class"
<Button
v-if="value === null && !isLocating"
rounded
Expand Down

0 comments on commit f5cace8

Please sign in to comment.