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

Fix onboarding options jumping #10236

Merged
merged 4 commits into from
Jun 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading