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

added new scroll to demo logic #13

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
37 changes: 31 additions & 6 deletions components/EditorOverview.vue
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const { $track } = useNuxtApp();
function playDemoClicked(){
demoEnabled.value = true;

demoCanvas.value?.scrollIntoViewIfNeeded();
smoothScrollToView(demoCanvas.value)

const isMobile = window.matchMedia('(max-width: 710px)').matches;

Expand All @@ -77,22 +77,47 @@ function playDemoClicked(){
* contenteditable element which is not presents on a page in a moment of button click
*
* So we use fake invisible input to focus it first, then change focus to our editor
*
* setTimeout is used because the virtual keyboard interrupts scroll
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This problem and solution is unclear to me. Do you mean mobile devices?

For now, it breaks the focus of editor on mobile devices (tested in Safari), which is working fine in main. Also, scroll works fine in main on mobile safari

Copy link
Author

@VKR981 VKR981 Aug 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure because I tested it on Safari (IOS Simulator), it was working fine, and yes the focus and scroll breaks on Chrome (Android) main.

Copy link
Author

@VKR981 VKR981 Aug 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another solution is to put
`const block: HTMLElement | null = document.querySelector('.ce-paragraph');
if (block !== null){

    block.focus()
  }`

inside onReady callback which is woking on Chrome (Android) and Safari(IOS Simulator).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have kept the changes to a minimum this PR only addresses the scroll issue on web tested on Chrome (Desktop) and Safari (Desktop)

*/
(document.querySelector('.fake-input') as HTMLElement).focus();

setTimeout(()=>{
(document.querySelector('.fake-input') as HTMLElement).focus();

const block: HTMLElement | null = document.querySelector('.ce-paragraph');
const block: HTMLElement | null = document.querySelector('.ce-paragraph');

if (block !== null){
if (block !== null){

block.focus()
}
block.focus()
}
},1000)
}

/**
* Send analytics event
*/
$track(AnalyticEvent.PlayWithDemoClicked)
}


/**
* Scroll the target element to 33% from top of the screen
*/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have problems with identations

function smoothScrollToView(targetEle:HTMLElement|null) {

if (!targetEle) {
return;
}

const targetPosition = targetEle.getBoundingClientRect().top + window.scrollY;
const screenHeight = window.innerHeight;
const targetOffset = targetPosition - (screenHeight / 3);

window.scrollTo({
top: targetOffset,
behavior: 'smooth'
});
}
</script>

<style lang="postcss">
Expand Down