Skip to content

Commit

Permalink
Some more tests to make an anchor scroll and a focus on the input field.
Browse files Browse the repository at this point in the history
  • Loading branch information
Elweyn committed Apr 17, 2024
1 parent dff581c commit 1b0d55c
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 7 deletions.
7 changes: 7 additions & 0 deletions presenter/src/components/forms/NewsletterForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,18 @@ const showInfoTime: number = 5000
const form = ref<HTMLFormElement>()
const inputFieldNewsletter = ref()
const focusInput = () => {
if (inputFieldNewsletter.value) {
inputFieldNewsletter.value.focusInput()
}
}
const { mutate: sendSubscribeToNewsletter } = useMutation(subscribeToNewsletter)
defineExpose({
form,
inputFieldNewsletter,
focusInput,
})
// submit form with data
async function submitForm() {
Expand Down
14 changes: 14 additions & 0 deletions presenter/src/components/inputs/NameInput.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<template>
<v-text-field
ref="inputField"
:model-value="props.modelValue"
:name="props.name"
:class="props.class"
Expand All @@ -18,6 +19,8 @@
</template>

<script lang="ts" setup>
import { ref } from 'vue'
import { nameRules } from '#src/validation/validation'
const props = withDefaults(
Expand Down Expand Up @@ -61,4 +64,15 @@ const props = withDefaults(
const emit = defineEmits<{
(e: 'update:modelValue', event: string): void
}>()
const inputField = ref()
const focusInput = () => {
if (inputField.value) {
inputField.value.focus()
}
}
defineExpose({
inputField,
focusInput,
})
</script>
10 changes: 5 additions & 5 deletions presenter/src/components/menu/HeaderMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
></AnchorLink>
<AnchorLink
class="mx-4"
href="/#contactname"
:label="$t('menu.header.contact')"
@click.prevent="scrollToNewsletterAnchor"
></AnchorLink>
Expand Down Expand Up @@ -107,7 +106,7 @@
</template>

<script lang="ts" setup>
import { ref, onMounted, onBeforeMount, nextTick } from 'vue'
import { ref, onMounted, onBeforeMount } from 'vue'
import MobileMenuIcon from '#assets/img/hamburger_mobile.svg'
import MainButton from '#components/buttons/MainButton.vue'
Expand All @@ -121,9 +120,10 @@ const anchorNewsletter = ref()
const scrollToNewsletterAnchor = () => {
if (anchorNewsletter.value) {
anchorNewsletter.value.scrollIntoView({ behavior: 'smooth' })
nextTick(() => {
anchorNewsletter.value.newsletterForm.value.inputFieldNewsletter.value.focus()
})
anchorNewsletter.value.focusInput()
// nextTick(() => {
// anchorNewsletter.value.newsletterForm.value.inputFieldNewsletter.value.focus()
// })
}
}
Expand Down
7 changes: 7 additions & 0 deletions presenter/src/components/sections/NewsletterSection.vue
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,15 @@ import NewsletterForm from '#components/forms/NewsletterForm.vue'
// const newsletterDownloadPath = '#'
const newsletterForm = ref()
const focusInput = () => {
if (newsletterForm.value) {
newsletterForm.value.focusInput()
}
}
defineExpose({
newsletterForm,
focusInput,
})
</script>

Expand Down
10 changes: 8 additions & 2 deletions presenter/src/pages/index/+Page.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
<div id="planning-section" class="py-16 px-4">
<PlanningSection />
</div>
<div id="newsletter-section" ref="anchorNewsletter" class="py-16 px-4">
<NewsletterSection />
<div id="newsletter-section" class="py-16 px-4">
<NewsletterSection ref="anchorNewsletter" />
</div>
<div id="coffee-section" class="py-16 px-4">
<CoffeeSection />
Expand All @@ -37,9 +37,15 @@ import PlanningSection from '#root/src/components/sections/PlanningSection.vue'
import ProductsSection from '#root/src/components/sections/ProductsSection.vue'
const anchorNewsletter = ref()
const focusInput = () => {
if (anchorNewsletter.value) {
anchorNewsletter.value.focusInput()
}
}
defineExpose({
anchorNewsletter,
focusInput,
})
</script>

Expand Down

0 comments on commit 1b0d55c

Please sign in to comment.