Skip to content

Commit a1abbec

Browse files
committed
Use width calculation select width
1 parent c03a3f2 commit a1abbec

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

assets/css/sidebar.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@
111111

112112
.sidebar .sidebar-staleVersion {
113113
display: inline;
114-
padding-left: 8px;
114+
padding-left: 4px;
115115
}
116116

117117
.sidebar .sidebar-staleVersion > a {

assets/js/sidebar/sidebar-version-select.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,24 @@ function renderVersionsDropdown ({ nodes, latestVersion }) {
3030
const versionsDropdownHtml = versionsDropdownTemplate({ nodes, latestVersion })
3131
versionsContainer.innerHTML = versionsDropdownHtml
3232

33-
qs(VERSIONS_DROPDOWN_SELECTOR).addEventListener('change', handleVersionSelected)
33+
const select = qs(VERSIONS_DROPDOWN_SELECTOR)
34+
select.addEventListener('change', handleVersionSelected)
35+
adjustWidth(select)
36+
}
37+
38+
// Function to adjust the width of the select element
39+
const adjustWidth = (select) => {
40+
// Create a temporary element to measure the width
41+
const temp = document.createElement('span')
42+
temp.style.visibility = 'hidden'
43+
temp.style.position = 'absolute'
44+
temp.style.whiteSpace = 'nowrap'
45+
temp.style.font = window.getComputedStyle(select).font
46+
temp.textContent = select.options[select.selectedIndex].text
47+
48+
document.body.appendChild(temp)
49+
select.style.width = `${temp.offsetWidth + 20}px`
50+
document.body.removeChild(temp)
3451
}
3552

3653
/**

0 commit comments

Comments
 (0)