Skip to content

Commit

Permalink
fix minor sidenav bugs (#50249)
Browse files Browse the repository at this point in the history
  • Loading branch information
rudream authored Dec 16, 2024
1 parent 186db7a commit 3155da7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 29 deletions.
37 changes: 18 additions & 19 deletions web/packages/teleport/src/Navigation/SideNavigation/Navigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -350,31 +350,30 @@ export function Navigation() {

// If the page is not part of the sidenav, such as Account Settings, curentPageSection will be undefined, and the drawer should be collapsed.
if (currentPageSection) {
// If there is already an expanded section set, don't change it.
if (debouncedSection) {
return;
}
handleSetExpandedSection(currentPageSection);
} else {
collapseDrawer(false);
}
}, [currentPageSection]);

// Handler for navigation actions
const handleNavigation = useCallback(
(route: string) => {
history.push(route);

// Clear any existing timeout
if (navigationTimeoutRef.current) {
clearTimeout(navigationTimeoutRef.current);
}
// Handler for clicking nav items.
const onNavigationItemClick = useCallback(() => {
// Clear any existing timeout
if (navigationTimeoutRef.current) {
clearTimeout(navigationTimeoutRef.current);
}

if (!stickyMode) {
// Add a small delay to the close to allow the user to see some feedback (see the section they clicked become active).
navigationTimeoutRef.current = setTimeout(() => {
collapseDrawer(false);
}, 150);
}
},
[collapseDrawer, history]
);
if (!stickyMode) {
// Add a small delay to the close to allow the user to see some feedback (see the section they clicked become active).
navigationTimeoutRef.current = setTimeout(() => {
collapseDrawer(false);
}, 150);
}
}, [collapseDrawer]);

// Hide the nav if the current feature has hideNavigation set to true.
const hideNav = features.find(
Expand Down Expand Up @@ -449,7 +448,7 @@ export function Navigation() {
toggleStickyMode={toggleStickyMode}
$active={section.category === currentView?.category}
aria-controls={`panel-${debouncedSection?.category}`}
handleNavigation={handleNavigation}
onNavigationItemClick={onNavigationItemClick}
isExpanded={isExpanded}
/>
</React.Fragment>
Expand Down
14 changes: 4 additions & 10 deletions web/packages/teleport/src/Navigation/SideNavigation/Section.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export function DefaultSection({
$active,
section,
isExpanded,
handleNavigation,
onNavigationItemClick,
previousExpandedSection,
stickyMode,
toggleStickyMode,
Expand All @@ -55,7 +55,7 @@ export function DefaultSection({
onExpandSection,
}: SharedSectionProps & {
currentView?: NavigationSubsection;
handleNavigation?: (route: string) => void;
onNavigationItemClick?: () => void;
currentPageSection?: NavigationSection;
stickyMode: boolean;
toggleStickyMode: () => void;
Expand All @@ -67,11 +67,6 @@ export function DefaultSection({
$active={$active}
onMouseEnter={onExpandSection}
onFocus={onExpandSection}
onClick={() => {
if (section.standalone) {
handleNavigation(section.subsections[0].route);
}
}}
isExpanded={isExpanded}
tabIndex={section.standalone ? 0 : -1}
>
Expand Down Expand Up @@ -109,9 +104,8 @@ export function DefaultSection({
to={subsection.route}
exact={subsection.exact}
key={subsection.title}
onClick={(e: React.MouseEvent) => {
e.preventDefault();
handleNavigation(subsection.route);
onClick={() => {
onNavigationItemClick();
}}
>
<subsection.icon size={16} />
Expand Down

0 comments on commit 3155da7

Please sign in to comment.