soflyy / breakdance-bugs

Bug reports from Breakdance users.
40 stars 6 forks source link

Media query for offset in Sticky broken #938

Closed MrBushid0 closed 1 month ago

MrBushid0 commented 1 year ago

Hi,

The offset setting in the Sticky feature doesn't work as expected when you have different offsets declared in 3 or more breakpoints.

To test:

1- Enable Sticky on some element 2- Define default offset of 200 3- Define an offset for tablet of 300 4- Define an offset for mobile of 50

Result:

On mobile, the element will turn sticky at the offset defined for the tablet breakpoint instead of the one defined on the mobile breakpoint.

Fix:

In sticky.js, getOffset() function, sort the breakpoints before doing a lookup

Change

const foundBreakpoint = breakpoints .filter((b) => b.id !== BASE_BREAKPOINT_ID) .find((b) => matchMedia(b.id));

To

const foundBreakpoint = breakpoints .filter((b) => b.id !== BASE_BREAKPOINT_ID) .sort((a, b) => a.maxWidth - b.maxWidth) .find((b) => matchMedia(b.id));

Thanks!

louisreingold commented 4 months ago

Thanks for report and suggested fix. This will be addressed in 2.0.

breakdancemoderator commented 1 month ago

Thanks for the report. This has been addressed in Breakdance 2.0.