Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: v-show with custom controls #173

Merged
merged 1 commit into from
Sep 29, 2023
Merged
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
18 changes: 12 additions & 6 deletions src/components/CustomControl.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
v-show must be used instead of v-if otherwise there
would be no rendered content pushed to the map controls
-->
<div ref="controlRef" v-show="showContent">
<div ref="controlRef" class="custom-control-wrapper">
<slot />
</div>
</template>
Expand Down Expand Up @@ -36,8 +36,6 @@ export default defineComponent({
const api = inject(apiSymbol, ref());
const mapTilesLoaded = inject(mapTilesLoadedSymbol, ref(false));

const showContent = ref(false);

// To avoid rendering the content outside the map we need to wait for the map AND the api to fully load
const stopWatchingOnMapLoad = watch(
[mapTilesLoaded, api, controlRef],
Expand All @@ -49,8 +47,6 @@ export default defineComponent({
if (api && mapLoadedStatus && contentRef) {
addControl(props.position);

showContent.value = true;

emit("content:loaded");

// As the watcher is imediately invoked if the api and the map was already loaded
Expand Down Expand Up @@ -105,7 +101,17 @@ export default defineComponent({
}
);

return { controlRef, showContent };
return { controlRef };
},
});
</script>

<style scoped>
.custom-control-wrapper {
display: none;
}

.mapdiv .custom-control-wrapper {
display: inline-block;
}
</style>