Skip to content

Commit 14f74bf

Browse files
feat(sidebar): support exact for exact activePath matching
1 parent e1dbf18 commit 14f74bf

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

app/views/course/courses/_sidebar_items.json.jbuilder

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ json.array! items do |item|
55
json.path item[:path]
66
json.icon item[:icon]
77
json.unread item[:unread] if item[:unread]&.nonzero?
8+
json.exact item[:exact].presence
89
end

client/app/bundles/course/container/Sidebar/SidebarItem.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@ const SidebarItem = (props: SidebarItemProps): JSX.Element => {
2121
const location = useLocation();
2222
const activeUrl = activePath ?? location.pathname + location.search;
2323

24-
const isActive = exact
25-
? activeUrl === item.path
26-
: activeUrl.startsWith(item.path);
24+
const isActive =
25+
exact || item.exact
26+
? activeUrl === item.path
27+
: activeUrl.startsWith(item.path);
2728

2829
const Icon = defensivelyGetIcon(item.icon, isActive ? 'filled' : 'outlined');
2930

client/app/types/course/courses.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ export interface SidebarItemData {
8181
path: string;
8282
icon: CourseComponentIconName;
8383
unread?: number;
84+
exact?: boolean;
8485
}
8586

8687
export interface CourseUserProgressData {

0 commit comments

Comments
 (0)