Skip to content

Commit

Permalink
pass options to createFilter to make it more flexible, closes #86
Browse files Browse the repository at this point in the history
  • Loading branch information
mskocik committed Feb 21, 2022
1 parent 062da87 commit 18c96d1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/Svelecte.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@
$: {
itemConfig.labelAsValue = labelAsValue;
}
$: dropdownInputValue = createFilter($inputValue, options);
/**
* Dispatch change event on add options/remove selected items
Expand Down Expand Up @@ -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 = {
Expand Down Expand Up @@ -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}
Expand Down
11 changes: 9 additions & 2 deletions src/lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(' ');
}

0 comments on commit 18c96d1

Please sign in to comment.