Skip to content

Commit

Permalink
v1.1.8
Browse files Browse the repository at this point in the history
- new: improved "inherit" width, considering dropdown paddings and images
  • Loading branch information
LCweb-ita committed Jun 6, 2023
1 parent 0c9c577 commit bae631d
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 18 deletions.
22 changes: 20 additions & 2 deletions lc_select.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* lc_select.js - Superlight Javascript dropdowns
* Version: 1.1.7
* Version: 1.1.8
* Author: Luca Montanari (LCweb)
* Website: https://lcweb.it
* Licensed under the MIT license
Expand Down Expand Up @@ -298,8 +298,10 @@
}

// static width from select?
let dd_width;
if(options.wrap_width != 'auto') {
div.style.width = (options.wrap_width == 'inherit') ? Math.round(el.getBoundingClientRect().width) + 'px' : options.wrap_width;
dd_width = (options.wrap_width == 'inherit') ? Math.round(el.getBoundingClientRect().width) + 'px' : options.wrap_width;
div.style.width = dd_width;
}


Expand All @@ -310,6 +312,22 @@
el.parentNode.insertBefore(div, el);
div.appendChild(el);


// inherit width - count lc-select paddings
if(options.wrap_width == 'inherit') {
const $lcslt = div.querySelector('.lcslt'),
lcslt_style = $lcslt.currentStyle || window.getComputedStyle($lcslt);

let addit_w = parseInt(lcslt_style.paddingRight, 10) + parseInt(lcslt_style.paddingLeft, 10);

// is there any image? count it
if(el.querySelector('option[data-image]')) {
addit_w = addit_w + 20;
}

div.style.width = (parseInt(dd_width, 10) + addit_w) +'px';
}

const trigger = div.querySelector('.lcslt');


Expand Down
4 changes: 2 additions & 2 deletions lc_select.min.js

Large diffs are not rendered by default.

13 changes: 0 additions & 13 deletions package-lock.json

This file was deleted.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"author": "LCweb",
"name": "lc-select",
"version": "1.1.7",
"version": "1.1.8",
"description": "Superlight vanilla javascript plugin, for modern web dropdowns. Supporting multi-options, search and images. Designed to be seamlessly themed",
"keywords": [
"javascript",
Expand Down

0 comments on commit bae631d

Please sign in to comment.