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

[v17] [Web] Fix minor sidenav-related UX bugs #50249

Merged
merged 1 commit into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
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
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
Loading