diff --git a/src/Svelecte.svelte b/src/Svelecte.svelte index e86144d..1d871d5 100644 --- a/src/Svelecte.svelte +++ b/src/Svelecte.svelte @@ -311,6 +311,7 @@ $: { itemConfig.labelAsValue = labelAsValue; } + $: dropdownInputValue = createFilter($inputValue, options); /** * Dispatch change event on add options/remove selected items @@ -371,7 +372,7 @@ if (selectedKeys.has(opt[currentValueField])) return; if (typeof opt === 'string') { - opt = createFilter(opt); + opt = createFilter(opt, options); if (alreadyCreated.includes(opt)) return; !fetch && alreadyCreated.push(opt); opt = { @@ -634,7 +635,7 @@ {virtualList} {vlHeight} {vlItemSize} lazyDropdown={virtualList || lazyDropdown} dropdownIndex={dropdownActiveIndex} items={availableItems} {listIndex} - inputValue={createFilter($inputValue)} {hasDropdownOpened} {listMessage} {disabledField} createLabel={_i18n.createRowLabel} + inputValue={dropdownInputValue} {hasDropdownOpened} {listMessage} {disabledField} createLabel={_i18n.createRowLabel} metaKey={isIOS ? '⌘' : 'Ctrl'} itemComponent={dropdownItem} on:select={onSelect} diff --git a/src/lib/utils.js b/src/lib/utils.js index 035306c..43431e0 100644 --- a/src/lib/utils.js +++ b/src/lib/utils.js @@ -155,6 +155,13 @@ export function iOS() { || (navigator.userAgent.includes("Mac") && "ontouchend" in document) } -export function defaultCreateFilter(val) { - return val.trim().split(' ').filter(ch => ch).join(' '); +/** + * Formatter of newly created items. When `''` is returned, it means new option cannot be created. + * + * @param {string} val + * @param {array} options + * @returns {string} + */ +export function defaultCreateFilter(val, options) { + return (val || '').trim().split(' ').filter(ch => ch).join(' '); }