Skip to content

Commit

Permalink
Fix onboarding options jumping (#10236)
Browse files Browse the repository at this point in the history
* fix: don't add padding to onboarding options when they're sticking
* delete console.log
* fix typo
* remove rounded corners from OnboardingOptionButtons

---------

Co-authored-by: Stephanie Anderson <[email protected]>
  • Loading branch information
a-hariti and stephanie-anderson committed Jun 8, 2024
1 parent c962942 commit 20915b8
Showing 1 changed file with 3 additions and 30 deletions.
33 changes: 3 additions & 30 deletions src/components/onboarding/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use client';

import {ReactNode, useEffect, useReducer, useRef, useState} from 'react';
import {ReactNode, useEffect, useReducer, useState} from 'react';
import {QuestionMarkCircledIcon} from '@radix-ui/react-icons';
import * as Tooltip from '@radix-ui/react-tooltip';
import {Button, Checkbox, Theme} from '@radix-ui/themes';
Expand Down Expand Up @@ -176,8 +176,6 @@ export function OnboardingOptionButtons({
`[data-onboarding-option="${option.id}"]`
);
targetElements.forEach(el => {
console.log('el', el.dataset);

const hiddenForThisOption = el.dataset.hideForThisOption === 'true';
if (hiddenForThisOption) {
el.classList.toggle('hidden', option.checked);
Expand Down Expand Up @@ -211,35 +209,10 @@ export function OnboardingOptionButtons({
});
}
});
}, [options, touchOptions]);

const buttonsRef = useRef<HTMLDivElement>(null);
const containerTopPx = 80;
const [isSticky, setIsSticky] = useState(false);

useEffect(() => {
const observer = new IntersectionObserver(
function ([buttonsContainer]) {
setIsSticky(!buttonsContainer.isIntersecting);
},
{
// the 1 exptra px is important to trigger the observer
// https://stackoverflow.com/questions/16302483/event-to-detect-when-positionsticky-is-triggered
rootMargin: `-${containerTopPx + 1}px 0px 0px 0px`,
threshold: [1],
}
);

observer.observe(buttonsRef.current!);
}, []);
}, [options, touchedOptions]);

return (
<div
ref={buttonsRef}
className={`flex flex-wrap gap-3 py-2 bg-white/90 sticky top-[80px] z-[1000] rounded shadow-[var(--shadow-6)] transition ${
isSticky ? 'px-2 backdrop-blur' : ''
}`}
>
<div className="flex flex-wrap gap-3 py-2 bg-white/90 sticky top-[80px] z-[1000] shadow-[var(--shadow-6)] transition">
{options.map(option => (
<Button
variant="surface"
Expand Down

0 comments on commit 20915b8

Please sign in to comment.