svelte-headless-components
Advanced tools
Comparing version 1.0.0 to 2.0.0
@@ -39,7 +39,15 @@ import type { ComputeConfig } from 'svelte-floating-ui'; | ||
useVirtualElement?: boolean; | ||
validateAddition?: (search: string) => boolean; | ||
}; | ||
export type AddOption = { | ||
err: false; | ||
id: string; | ||
searchText: string; | ||
}; | ||
export type AddOptionFail = { | ||
err: true; | ||
id: string; | ||
searchText: string; | ||
}; | ||
export type AddOptionResult = AddOption | AddOptionFail; | ||
export type OptionItem = OptionSelect | OptionMenu; | ||
@@ -62,3 +70,3 @@ export type InputOptionItem = InputOptionMenu | InputOptionSelect; | ||
onChange: Writable<OptionSelect>; | ||
onAdd: Writable<AddOption>; | ||
onAdd: Writable<AddOptionResult>; | ||
}; | ||
@@ -65,0 +73,0 @@ readonly state: { |
@@ -56,10 +56,8 @@ import { BROWSER } from 'esm-env'; | ||
const config = { | ||
...{ | ||
additions: [], | ||
closeOnSelect: 'not_multi', | ||
minSearchLength: 1, | ||
activeOnOpen: true, | ||
useVirtualElement: false, | ||
triggerEvent: 'mouseup', | ||
}, | ||
additions: [], | ||
closeOnSelect: 'not_multi', | ||
minSearchLength: 1, | ||
activeOnOpen: true, | ||
useVirtualElement: false, | ||
triggerEvent: 'mouseup', | ||
...inputConfig, | ||
@@ -191,4 +189,9 @@ }; | ||
} | ||
this.events.onAdd.set({ id: option.id, searchText: get(this.state.search) }); | ||
this.resetSearch(); | ||
if (this.config.validateAddition && !this.config.validateAddition(get(this.state.search))) { | ||
this.events.onAdd.set({ err: true, id: option.id, searchText: get(this.state.search) }); | ||
} | ||
else { | ||
this.events.onAdd.set({ err: false, id: option.id, searchText: get(this.state.search) }); | ||
this.resetSearch(); | ||
} | ||
} | ||
@@ -195,0 +198,0 @@ getMenuOptions() { |
{ | ||
"name": "svelte-headless-components", | ||
"version": "1.0.0", | ||
"version": "2.0.0", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
48997
1045