Skip to content

Commit e4e51cb

Browse files
committed
fix(clerk-js): Disable scroll to top for OrganizationProfile navbar
1 parent 7a84295 commit e4e51cb

3 files changed

Lines changed: 18 additions & 6 deletions

File tree

packages/clerk-js/src/ui/components/OrganizationProfile/OrganizationProfileNavbar.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@ const organizationProfileRoutes: NavbarRoute[] = [
1212
id: 'members',
1313
icon: User,
1414
path: '/',
15+
scroll: false,
1516
},
1617
{
1718
name: localizationKeys('organizationProfile.start.headerTitle__settings'),
1819
id: 'settings',
1920
icon: CogFilled,
2021
path: 'organization-settings',
22+
scroll: false,
2123
},
2224
];
2325

packages/clerk-js/src/ui/components/UserProfile/UserProfileNavbar.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@ const userProfileRoutes: NavbarRoute[] = [
1111
id: 'account',
1212
icon: User,
1313
path: '/',
14+
scroll: true,
1415
},
1516
{
1617
name: localizationKeys('userProfile.start.headerTitle__security'),
1718
id: 'security',
1819
icon: TickShield,
1920
path: '',
21+
scroll: true,
2022
},
2123
];
2224

packages/clerk-js/src/ui/elements/Navbar.tsx

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,21 @@ type NavbarContextValue = { isOpen: boolean; open: () => void; close: () => void
2222
export const [NavbarContext, useNavbarContext, useUnsafeNavbarContext] =
2323
createContextAndHook<NavbarContextValue>('NavbarContext');
2424

25-
export const NavbarContextProvider = (props: React.PropsWithChildren<{}>) => {
25+
export const NavbarContextProvider = (props: React.PropsWithChildren<Record<never, never>>) => {
2626
const [isOpen, setIsOpen] = React.useState(false);
2727
const open = React.useCallback(() => setIsOpen(true), []);
2828
const close = React.useCallback(() => setIsOpen(false), []);
2929
const value = React.useMemo(() => ({ value: { isOpen, open, close } }), [isOpen]);
3030
return <NavbarContext.Provider value={value}>{props.children}</NavbarContext.Provider>;
3131
};
3232

33-
export type NavbarRoute = { name: LocalizationKey; id: string; icon: React.ComponentType; path: string };
33+
export type NavbarRoute = {
34+
name: LocalizationKey;
35+
id: string;
36+
icon: React.ComponentType;
37+
path: string;
38+
scroll: boolean;
39+
};
3440
type RouteId = NavbarRoute['id'];
3541
type NavBarProps = {
3642
contentRef: React.RefObject<HTMLDivElement>;
@@ -59,8 +65,10 @@ export const NavBar = (props: NavBarProps) => {
5965
} else {
6066
await navigate(route.path);
6167
}
62-
const el = contentRef.current?.querySelector(getSectionId(route.id));
63-
el?.scrollIntoView({ behavior: 'smooth', block: 'start' });
68+
if (route.scroll) {
69+
const el = contentRef.current?.querySelector(getSectionId(route.id));
70+
el?.scrollIntoView({ behavior: 'smooth', block: 'start' });
71+
}
6472
}
6573
};
6674

@@ -135,7 +143,7 @@ export const NavBar = (props: NavBarProps) => {
135143
);
136144
};
137145

138-
const NavbarContainer = (props: React.PropsWithChildren<{}>) => {
146+
const NavbarContainer = (props: React.PropsWithChildren<Record<never, never>>) => {
139147
return (
140148
<Col
141149
elementDescriptor={descriptors.navbar}
@@ -154,7 +162,7 @@ const NavbarContainer = (props: React.PropsWithChildren<{}>) => {
154162
);
155163
};
156164

157-
const MobileNavbarContainer = (props: React.PropsWithChildren<{}>) => {
165+
const MobileNavbarContainer = (props: React.PropsWithChildren<Record<never, never>>) => {
158166
const navbarContext = useNavbarContext();
159167
const { floating, isOpen, open, close } = usePopover({ defaultOpen: false, autoUpdate: false });
160168

0 commit comments

Comments
 (0)