Skip to content

Commit

Permalink
let --> var, tweak for <select>
Browse files Browse the repository at this point in the history
  • Loading branch information
LeaVerou committed Nov 26, 2021
1 parent 9a164e6 commit 7dce018
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions src/stretchy.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ export function resize (element) {
return;
}

var cs = getComputedStyle(element);
var offset = 0;
var empty;
let cs = getComputedStyle(element);
let offset = 0;
let empty;

if (!element.value && element.placeholder) {
empty = true;
element.value = element.placeholder;
}

var type = element.nodeName.toLowerCase();
let type = element.nodeName.toLowerCase();

if (type == "textarea") {
element.style.height = "0";
Expand Down Expand Up @@ -60,15 +60,15 @@ export function resize (element) {
offset = parseFloat(cs.minWidth);
}

var width = Math.max(offset, element.scrollWidth - element.clientWidth);
let width = Math.max(offset, element.scrollWidth - element.clientWidth);

element.style.width = width + "px";

// To bulletproof, we will set scrollLeft to a
// huge number, and read that back to see what it was clipped to
// and increment width by that much, iteratively

for (var i=0; i<10; i++) { // max iterations
for (let i=0; i<10; i++) { // max iterations
element.scrollLeft = 1e+10;

if (element.scrollLeft == 0) {
Expand All @@ -91,18 +91,18 @@ export function resize (element) {
return;
}

var selectedIndex = element.selectedIndex > 0? element.selectedIndex : 0;
let selectedIndex = element.selectedIndex > 0? element.selectedIndex : 0;

// Need to use dummy element to measure :(
var option = document.createElement("_");
let option = document.createElement("_");
option.textContent = element.options[selectedIndex].textContent;
element.parentNode.insertBefore(option, element.nextSibling);

// The name of the appearance property, as it might be prefixed
var appearance;
let appearance;

for (var property in cs) {
var value = cs[property];
for (let property in cs) {
let value = cs[property];
if (!/^(width|webkitLogicalWidth|length)$/.test(property) && typeof value == "string" && property in option.style) {
option.style[property] = value;

Expand All @@ -119,7 +119,7 @@ export function resize (element) {

if (!cs[appearance] || cs[appearance] !== "none") {
// Account for arrow
element.style.width = "calc(" + element.style.width + " + 2em)";
element.style.width = "calc(" + element.style.width + " + 2.1em)";
}
}

Expand Down

0 comments on commit 7dce018

Please sign in to comment.