diff --git a/packages/bbui/src/Form/Combobox.svelte b/packages/bbui/src/Form/Combobox.svelte index b718921325..368e8bec4b 100644 --- a/packages/bbui/src/Form/Combobox.svelte +++ b/packages/bbui/src/Form/Combobox.svelte @@ -36,5 +36,7 @@ {getOptionLabel} {getOptionValue} on:change={onChange} + on:pick + on:type /> diff --git a/packages/bbui/src/Form/Core/Combobox.svelte b/packages/bbui/src/Form/Core/Combobox.svelte index 2f832ad91e..6a1390eeea 100644 --- a/packages/bbui/src/Form/Core/Combobox.svelte +++ b/packages/bbui/src/Form/Core/Combobox.svelte @@ -40,8 +40,15 @@ open = false } - const onChange = e => { - selectOption(e.target.value) + const onType = e => { + const value = e.target.value + dispatch("type", value) + selectOption(value) + } + + const onPick = value => { + dispatch("pick", value) + selectOption(value) } @@ -62,7 +69,7 @@ type="text" on:focus={() => (focus = true)} on:blur={() => (focus = false)} - on:change={onChange} + on:change={onType} value={value || ""} placeholder={placeholder || ""} {disabled} @@ -99,7 +106,7 @@ role="option" aria-selected="true" tabindex="0" - on:click={() => selectOption(getOptionValue(option))} + on:click={() => onPick(getOptionValue(option))} > {getOptionLabel(option)} { onChange(tempValue) bindingDrawer.hide() } - const onChange = value => { + const onChange = (value, optionPicked) => { + // Add HBS braces if picking binding + if (optionPicked && !options?.includes(value)) { + value = `{{ ${value} }}` + } + dispatch("change", readableToRuntimeBinding(bindings, value)) } + + const buildOptions = (options, bindings, appendBindingsAsOptions) => { + if (!appendBindingsAsOptions) { + return options + } + return [] + .concat(options || []) + .concat(bindings?.map(binding => binding.readableBinding) || []) + }