File tree 2 files changed +16
-1
lines changed
2 files changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -83,6 +83,11 @@ describe(`sidebar`, () => {
83
83
const { queryByText } = renderSidebar ( `/characters/jay-gatsby/` )
84
84
expect ( queryByText ( `Jay Gatsby` ) ) . toBeInTheDocument ( )
85
85
} )
86
+
87
+ it ( `opens sections with active items when the pathname is missing a trailing slash` , ( ) => {
88
+ const { queryByText } = renderSidebar ( `/characters/jay-gatsby` )
89
+ expect ( queryByText ( `Jay Gatsby` ) ) . toBeInTheDocument ( )
90
+ } )
86
91
} )
87
92
88
93
describe ( `toggle section` , ( ) => {
@@ -127,6 +132,11 @@ describe(`sidebar`, () => {
127
132
expect ( scrollIntoViewMock ) . toHaveBeenCalled ( )
128
133
} )
129
134
135
+ it ( `scrolls the sidebar into view on load when the pathname is missing a trailing slash` , ( ) => {
136
+ renderSidebar ( `/characters/jay-gatsby` )
137
+ expect ( scrollIntoViewMock ) . toHaveBeenCalled ( )
138
+ } )
139
+
130
140
it ( `does not scroll into view when loaded with a hash` , ( ) => {
131
141
renderSidebar ( `/themes/` , {
132
142
activeItemHash : `the-american-dream` ,
Original file line number Diff line number Diff line change 1
1
import { getLocaleAndBasePath } from "../i18n"
2
2
3
+ function addTrailingSlashIfMissing ( pathname ) {
4
+ return pathname . endsWith ( `/` ) ? pathname : `${ pathname } /`
5
+ }
6
+
3
7
const isItemActive = ( location , item , activeItemHash ) => {
4
- const { basePath } = getLocaleAndBasePath ( location . pathname )
8
+ const pathnameWithTrailingSlash = addTrailingSlashIfMissing ( location . pathname )
9
+ const { basePath } = getLocaleAndBasePath ( pathnameWithTrailingSlash )
5
10
const linkMatchesPathname = item . link === basePath
6
11
const linkWithoutHashMatchesPathname =
7
12
item . link . replace ( / # .* / , `` ) === basePath
You can’t perform that action at this time.
0 commit comments