From 1308efb8d01b56a37a70693f6f2716bef24f4551 Mon Sep 17 00:00:00 2001 From: tophf Date: Thu, 7 Jan 2021 12:35:44 +0300 Subject: [PATCH] fix/simplify fitSelectBox --- manage/render.js | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/manage/render.js b/manage/render.js index 71fbcb2b..c3299ab0 100644 --- a/manage/render.js +++ b/manage/render.js @@ -229,7 +229,7 @@ function fitSelectBox(...elems) { const data = []; for (const el of elems) { const sel = el.selectedOptions[0]; - if (!sel) return; + if (!sel) continue; const oldWidth = parseFloat(el.style.width); const text = []; data.push({el, text, oldWidth}); @@ -237,15 +237,13 @@ function fitSelectBox(...elems) { text.push(elOpt.textContent); if (elOpt !== sel) elOpt.textContent = ''; } - el.style.width = ''; + el.style.width = 'min-content'; + } + for (const {el, text, oldWidth} of data) { + const w = el.offsetWidth; + if (w && oldWidth !== w) el.style.width = w + 'px'; + text.forEach((t, i) => (el.options[i].textContent = t)); } - requestAnimationFrame(() => { - for (const {el, text, oldWidth} of data) { - const w = el.offsetWidth; - if (w && oldWidth !== w) el.style.width = w + 'px'; - text.forEach((t, i) => (el[i].textContent = t)); - } - }); } /* exported fitSelectBoxesIn */