Skip to content

Commit 7faf79a

Browse files
committed
Fix deepLinking scroll behavior
1 parent 9b5accc commit 7faf79a

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

src/core/plugins/deep-linking/spec-wrap-actions.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,32 @@ export const updateResolved = (ori, { layoutActions, getConfigs }) => (...args)
3131
let swaggerUI = document.querySelector(".swagger-ui")
3232
let myScroller = zenscroll.createScroller(swaggerUI)
3333

34+
let target
35+
3436
if(tag && operationId) {
3537
// Pre-expand and scroll to the operation
3638
layoutActions.show(["operations-tag", tag], true)
3739
layoutActions.show(["operations", tag, operationId], true)
3840

39-
let target = document.getElementById(`operations-${escapeDeepLinkPath(tag)}-${escapeDeepLinkPath(operationId)}`)
40-
myScroller.to(target)
41-
41+
target = document
42+
.getElementById(`operations-${escapeDeepLinkPath(tag)}-${escapeDeepLinkPath(operationId)}`)
4243
} else if(tag) {
4344
// Pre-expand and scroll to the tag
4445
layoutActions.show(["operations-tag", tag], true)
4546

46-
let target = document.getElementById(`operations-tag-${escapeDeepLinkPath(tag)}`)
47+
target = document.getElementById(`operations-tag-${escapeDeepLinkPath(tag)}`)
48+
}
49+
50+
51+
if(target) {
4752
myScroller.to(target)
53+
setTimeout(() => {
54+
// Backup functionality: if we're still at the top of the document,
55+
// scroll on the entire page (not within the Swagger-UI container)
56+
if(zenscroll.getY() === 0) {
57+
zenscroll.to(target)
58+
}
59+
}, 50)
4860
}
4961
}
5062

0 commit comments

Comments
 (0)