Skip to content
Draft
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions src/components/Tutorial/SectionSteps.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
:key="index"
:currentIndex="activeStep"
ref="contentNodes"
@focus="onFocus"
/>
</div>
<!-- the asset-container is only for medium and large breakpoints -->
Expand Down
17 changes: 16 additions & 1 deletion src/components/Tutorial/Step.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
-->

<template>
<div :class="['step-container', `step-${stepNumber}`]">
<div :class="['step-container', `step-${stepNumber}`]" tabindex="0" @focus="onFocus">
<div
ref="step"
class="step"
Expand Down Expand Up @@ -117,6 +117,21 @@ export default {
},
isActive: ({ index, currentIndex }) => index === currentIndex,
},
methods: {
onFocus() {
if (this.isClientMobile) return;
const bodyRect = document.body.getBoundingClientRect().top;
const elementRect = this.$el.getBoundingClientRect().top;
const elementPosition = elementRect - bodyRect;
// make sure the element is at the top 25% of the screen
const offsetPosition = elementPosition - (window.innerHeight * 0.25);

// scroll to the element
window.scrollTo({ top: offsetPosition, behavior: 'smooth' });
// notify the parent it must be in focus, if for some reason it is not.
this.$emit('focus', this.index);
},
},
};
</script>

Expand Down