wysiwyg-editor icon indicating copy to clipboard operation
wysiwyg-editor copied to clipboard

stickyToolbar & overflowed scrollableContainer not working as intended

Open Mboulianne opened this issue 5 years ago • 18 comments

Expected behavior.

The toolbar should always stick if a scrollableContainer is specified.

Actual behavior.

When there the page and the scrollableContainer have a scrollbar, the toolbar won't stick as it should if the page scrollbar is at its top-most or bottom-most position.

Steps to reproduce the problem.

1- Make sure page scrollbar is at its topmost position. 2- Scroll the scrollbar in the scrollcontainer 3- Toolbar didn't stick :( 4- Do the same with scrollbar at its bottom-most position. 5- Toolbar didn't stick. 6- Put the page scrollbar somwhere between its top-most position and its bottom-most position. 7- Scroll the scrollbar in the scroll container. 8 - Toolbar did stick!!!

See jsfiddle https://jsfiddle.net/ppyLhnqt/65/

To make sure everything is clear I'll put some screenshot 1- Page scrollbar is at its top-most position. image The toolbar isn't visible anymore. It didn't stick.

2- Page scrollbar is at its bottom-most position image The toolbar isn't visible anymore. It didn't stick.

3- Page scrollbar is somwhere in the middle image The toolbar is visible. It did stick.

OS.

Windows 10

Browser.

Firefox 61.0.1 (64-bit) Chrome 67.0.3396.99 (Official Build) (64-bit) Edge Microsoft Edge 42.17134.1.0 / Microsoft EdgeHTML 17.17134

Mboulianne avatar Jul 11 '18 17:07 Mboulianne

@gabra20

Mboulianne avatar Jul 11 '18 17:07 Mboulianne

That is because the height of the view is smaller than 500px and the editor is designed to keep the toolbar at the top when it exceeds the scrollable container. If you would set it to a value smaller than the height of the view all is good: https://jsfiddle.net/froala/ppyLhnqt/70/.

stefanneculai avatar Jul 12 '18 07:07 stefanneculai

new jsfiddle: https://jsfiddle.net/ppyLhnqt/103/

how do you explain that I'm getting that now? image

The toolbar appears below my scrollContainer. I've hadded content before and after my container to represent my real use case

Also image If I only scroll the page (not the scroll container) the toolbar don't stick at all.

It looks pretty buggy to me.

@stefanneculai

Mboulianne avatar Jul 12 '18 12:07 Mboulianne

Thanks for the further details. Indeed, it appears to be a problem. I updated it accordingly.

stefanneculai avatar Jul 12 '18 13:07 stefanneculai

I think I found a similar bug: My editors are contained in a fixed container that lies at the end / bottom of the body tag with top: 0; bottom: 0; left: 0; right: 0; (it take the whole viewport). If the body has enough content to make a scrollbar appear and if that scrollbar is scrolled, editor toolbar won't stick correctly

jsFiddle: https://jsfiddle.net/184f7zpd/63/

Body has no scrollbar => image (everything is ok)

Body has a scrollbar but the user haven't scrolled yet => image (everything is ok)

Body has a scrollbar and the user have scrolled => image Buggy!

@stefanneculai

I think toolbarSticky should work correctly even if the editors are in a fixed container no?

Mboulianne avatar Jul 16 '18 14:07 Mboulianne

Related to https://github.com/froala/wysiwyg-editor/issues/2981.

stefanneculai avatar Sep 07 '18 14:09 stefanneculai

@stefanneculai are you sure these are related? My bug is about the toolbar that isn't positionned correctly. However, I opened a similar bug https://github.com/froala/wysiwyg-editor/issues/3038 ?

Mboulianne avatar Sep 07 '18 14:09 Mboulianne

Yes, they are related because they use the same logic for positioning inside a scrollableContainer.

stefanneculai avatar Sep 10 '18 16:09 stefanneculai

@stefanneculai ok we'll see once this get resolved then. It's not a big deal for us since we found a workaround.

Mboulianne avatar Sep 10 '18 18:09 Mboulianne

Is this bug fixed?

loocaworld avatar Jul 09 '19 08:07 loocaworld

Is a fix for this still in the works? I'm having the same issue in 3.0.6

JessieCowie23 avatar Jan 07 '20 03:01 JessieCowie23

Such a simple issue faced by many, yet 3 years later still no accepted solution.

spankyed avatar Jan 28 '21 14:01 spankyed

This is really a frustrating bug, so I decided to work around it myself. I'm using Vue but the concept still works in plain JS. "ActivityPage" is my scrollable DIV.

  1. Attach to the scroll event listener on the DIV Tag when the page loads
  2. Wait for scrolling, then disable the listener (better performance than constantly checking)
  3. Check to see how far we've scrolled down the page (my editor is approx 30% down the page, yours will very)
  4. If scrolling is less than 30%, remove the 'sticky' class from the froala toolbar, otherwise add the class because we have scrolled past it
  5. remove the listener when navigating away from the page

[The code block isn't formatting this correctly so that why part of it is in plan text]

` mounted () { document.getElementById('ActivityPage').addEventListener('scroll', this.handleScroll, { passive: true }) }

destroyed () { document.getElementById('ActivityPage').removeEventListener('scroll', this.handleScroll) }

handleScroll (event) {
  document.getElementById('ActivityPage').removeEventListener('scroll', this.handleScroll)
  console.log('stop listening for performance reasons')
  setTimeout(() => {
    document.getElementById('ActivityPage').addEventListener('scroll', this.handleScroll, { passive: true })
    console.log('start listening')
    this.handleStickyToolbar()
  }, 300)
}

handleStickyToolbar () {
  var element = document.getElementById('ActivityPage')
  var b = element.scrollHeight - window.innerHeight
  var c = element.scrollTop / b
  var x = document.getElementsByClassName('fr-toolbar')
  if (c < 0.3) {
    x[0].classList.remove('fr-sticky-on')
  } else {
    x[0].classList.add('fr-sticky-on')
  }
}`

brucetp avatar Jul 03 '21 18:07 brucetp

on every updates, I do this modification.

  1. find t.css("top", S.helpers.getPX(t.data("top")) + i) # S could be L or something. That "i" is problem.
  2. modify this to t.css("top", S.helpers.getPX(t.data("top")) + (S.$sc.css("position") === "fixed" ? S.$sc.position().top : i))

loocaworld avatar Jul 04 '21 06:07 loocaworld

Also, having a similar problem.

@loocaworld - can you reference where in the code you make that change?

nateleavitt avatar Mar 30 '22 21:03 nateleavitt

@nateleavitt Variables are always changed on every big updates. So if you are using froala editor version 4.0.10,

  1. open file "js/froala_editor.min.js"
  2. find this L.helpers.getPX(t.data("top")) + i
  3. change like this L.helpers.getPX(t.data("top")) + (L.$sc.css("position") === "fixed" ? L.$sc.position().top : i)

loocaworld avatar Mar 31 '22 06:03 loocaworld

I have same problem, I add this css in global and fix this problem version: "react-froala-wysiwyg": "3.0.6",

.fr-toolbar.fr-top { position: sticky !important; z-index: 2 !important; }

OdaNeo avatar Apr 26 '22 08:04 OdaNeo

This problem is caused because the editor is in a scroll-downed fixed container. If the background parent has a little offset from the top, inner elements in the fixed container's offset().top contains parent's offset too. So, if $sc(=scrollable container) is in a fixed container or is a fixed container, you have to consider that.

in "js/froala_editor.min.js", find below code t.css("top", L.helpers.getPX(t.data("top")) + i) change that code line to t.css("top", L.helpers.getPX(t.data("top")) + (L.$sc.parents().filter(function(){return $(this).css('position') == 'fixed';}).length ? L.$sc.position().top : i))

loocaworld avatar Apr 27 '22 06:04 loocaworld

I have a similar problem. The scrollable container is not fixed but it sounds like the same issue.

If the scrollable container is offset from the top of the viewport at all, it will offset the toolbar down by that amount. I created a minimal repro here with the latest version (4.0.19) https://jsfiddle.net/2spd3tha/2/

The body adds 8px. The wrapper element adds 16px, and the header adds 64px, so the scrollable container is pushed down for a total of 8px + 16px + 64px = 88px. Since the offsetTop of the scrollable container is 88px, it sets the top of the toolbar to 88px, despite me setting the toolbarStickyOffset to 0.

image

dplarina avatar May 31 '23 13:05 dplarina