Skip to content

Commit ea9e509

Browse files
committed
Add min and max sidebar width
1 parent d2ae1c0 commit ea9e509

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

python_docs_theme/static/sidebar.js_t

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ const initialiseSidebar = () => {
4949
const sidebarButton = document.createElement("div")
5050
sidebarButton.id = "sidebarbutton"
5151
{% endif %}
52+
const sidebarMinWidth = 200
53+
const sidebarMaxWidth = Math.round(0.5 * window.innerWidth)
54+
5255
sidebarbutton.innerHTML = ""
5356
sidebarbutton.tabindex = "0" // make it focusable
5457
sidebarbutton.role = "slider"
@@ -60,7 +63,10 @@ const initialiseSidebar = () => {
6063
function onMouseMove(e) {
6164
e.preventDefault()
6265
const sidebarWidth = sidebar.offsetWidth
63-
const newWidth = Math.max(0, Math.min(window.innerWidth, sidebarWidth + e.clientX - clientX))
66+
const newWidth = Math.max(
67+
sidebarMinWidth,
68+
Math.min(sidebarMaxWidth, sidebarWidth + e.clientX - clientX)
69+
)
6470
clientX = e.clientX
6571
sidebar.style.width = `${newWidth}px`
6672
bodyWrapper.style.marginLeft = `${newWidth}px`

0 commit comments

Comments
 (0)