From 5ecd09b39e08d4a4d4a3392677d00f7310527c1b Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Tue, 23 Nov 2021 16:40:31 +0000 Subject: [PATCH] Add readonly prop to combobox --- packages/bbui/src/Form/Combobox.svelte | 2 ++ packages/bbui/src/Form/Core/Combobox.svelte | 2 ++ packages/bbui/src/Form/Core/TextField.svelte | 8 ++++---- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/bbui/src/Form/Combobox.svelte b/packages/bbui/src/Form/Combobox.svelte index 368e8bec4b..83927b05db 100644 --- a/packages/bbui/src/Form/Combobox.svelte +++ b/packages/bbui/src/Form/Combobox.svelte @@ -6,6 +6,7 @@ export let value = null export let label = undefined export let disabled = false + export let readonly = false export let labelPosition = "above" export let error = null export let placeholder = "Choose an option or type" @@ -33,6 +34,7 @@ {value} {options} {placeholder} + {readonly} {getOptionLabel} {getOptionValue} on:change={onChange} diff --git a/packages/bbui/src/Form/Core/Combobox.svelte b/packages/bbui/src/Form/Core/Combobox.svelte index 6a1390eeea..6a6423cccf 100644 --- a/packages/bbui/src/Form/Core/Combobox.svelte +++ b/packages/bbui/src/Form/Core/Combobox.svelte @@ -9,6 +9,7 @@ export let id = null export let placeholder = "Choose an option or type" export let disabled = false + export let readonly = false export let error = null export let options = [] export let getOptionLabel = option => option @@ -73,6 +74,7 @@ value={value || ""} placeholder={placeholder || ""} {disabled} + {readonly} class="spectrum-Textfield-input spectrum-InputGroup-input" /> diff --git a/packages/bbui/src/Form/Core/TextField.svelte b/packages/bbui/src/Form/Core/TextField.svelte index 85c71338f7..d2064ddde0 100644 --- a/packages/bbui/src/Form/Core/TextField.svelte +++ b/packages/bbui/src/Form/Core/TextField.svelte @@ -16,15 +16,15 @@ const dispatch = createEventDispatcher() let focus = false - const updateValue = value => { + const updateValue = newValue => { if (readonly) { return } if (type === "number") { - const float = parseFloat(value) - value = isNaN(float) ? null : float + const float = parseFloat(newValue) + newValue = isNaN(float) ? null : float } - dispatch("change", value) + dispatch("change", newValue) } const onFocus = () => {