stickybits icon indicating copy to clipboard operation
stickybits copied to clipboard

Calling updates, allows not to set a new stickyBitStickyOffset value

Open patric-eberle opened this issue 4 years ago • 4 comments

Describe the bug When calling this.stickybitInstance.update({ stickyBitStickyOffset: <my-new-value> }), the top spacing of the sticky element is not adjusted. It always seems to use the initial value, even though, the prop is updated on the instance.

To Reproduce

const stickybitsInstancetoBeUpdated = stickybits("selector");
stickybitsInstancetoBeUpdated.update({ stickyBitStickyOffset: 20 });

Expected behavior The sticky element uses the newly defined stickyBitStickyOffset as top value.

Screenshots

Desktop (please complete the following information):

  • OS: macOS 10.15
  • Browser: Chrome
  • Version: 83

Additional context Stickybits: 3.7.7

I think the following ticket on the old repository documents the same issue, even if I was not able to call the recalculation from outside myself: https://github.com/dollarshaveclub/stickybits/issues/663

patric-eberle avatar Jul 08 '20 07:07 patric-eberle

We have the same problem... any ideas for solving?

sedax90 avatar Sep 14 '20 10:09 sedax90

This seems to have done it for me:

    stickybitsInstance.update({ stickyBitStickyOffset: 20 });
    stickybitsInstance.update();

hanoii avatar Nov 06 '20 17:11 hanoii

So I've found an alternative way of updating it, by cleaning it up and it works for me:

stickyBitsInstance.cleanup();
stickyBitsInstance = stickybits('selector', {stickyBitStickyOffset: newOffset });

Of course your cleaning up the old instance and making a new instance of it but for now it works for my use-case.

gching avatar Dec 14 '20 00:12 gching

I think the main problem is that update does not actually have an effect or move the element directly. It would need to call the manageState() method with a force flag or similar to do all calculations checks again, and actually call applyStyles() even if the sticky/stuck state hasn't changed. There is no practical way to force that from the outside right now.

TwoD avatar Sep 12 '21 13:09 TwoD