fancy-select
Advanced tools
Comparing version 0.5.0 to 0.6.0
10
index.js
@@ -15,3 +15,5 @@ var mercury = require('mercury') | ||
data.filter = data.filter || function (opt, query, value) { | ||
if (opt.id === '__create__') return {keep: true} | ||
// keep any that start with __ | ||
if (opt.id && opt.id.indexOf('__') === 0) return {keep: true} | ||
// omit value | ||
@@ -24,2 +26,3 @@ for (var i = value.length - 1; i >= 0; i--) { | ||
// match query | ||
try { | ||
@@ -76,3 +79,5 @@ var regex = new RegExp(query || '', 'i') | ||
options: tree.state.options, | ||
isOpen: mercury.value(true) | ||
isOpen: mercury.value(true), | ||
placeholder: mercury.value(data.placeholder || '') | ||
}) | ||
@@ -82,3 +87,2 @@ | ||
state: state, | ||
events: {}, | ||
setOptions: tree.setOptions, | ||
@@ -85,0 +89,0 @@ setQuery: tree.setQuery |
{ | ||
"name": "fancy-select", | ||
"description": "fancy select", | ||
"version": "0.5.0", | ||
"version": "0.6.0", | ||
"repository": { | ||
@@ -6,0 +6,0 @@ "url": "nrw/fancy-select" |
14
view.js
@@ -37,4 +37,5 @@ var mercury = require('mercury') | ||
autocomplete: 'off', | ||
placeholder: state.placeholder, | ||
style: { | ||
width: measureString(state.query) + 'px' | ||
width: maxWidth([state.query, state.placeholder]) + 'px' | ||
}, | ||
@@ -128,2 +129,13 @@ className: styles.input.className, | ||
function maxWidth (strs) { | ||
var one, max = 0 | ||
strs.forEach(function (str) { | ||
one = measureString(str) | ||
if (one > max) { | ||
max = one | ||
} | ||
}) | ||
return max | ||
} | ||
function measureString (str, current) { | ||
@@ -130,0 +142,0 @@ if (!str) return 0 |
9226
275