From 904ffe1dd60548b0a959ed22fdc73d4c50e744ef Mon Sep 17 00:00:00 2001 From: Kaz Wesley Date: Thu, 13 Jun 2024 10:43:35 -0700 Subject: [PATCH] Support empty and non-numeric default values in number picker (#10251) Numeric default (unchanged): Screenshot 2024-06-11 at 10 19 21 Non-numeric default: https://github.com/enso-org/enso/assets/1047859/bfe812e2-4d1c-477b-9500-f384fa499890 No default: Screenshot 2024-06-11 at 10 19 36 Closes #9449. --- .../GraphEditor/widgets/WidgetNumber.vue | 31 ++++++++++++------- .../src/components/widgets/AutoSizedInput.vue | 16 +++++++--- .../components/widgets/NumericInputWidget.vue | 26 ++++++++-------- 3 files changed, 44 insertions(+), 29 deletions(-) diff --git a/app/gui2/src/components/GraphEditor/widgets/WidgetNumber.vue b/app/gui2/src/components/GraphEditor/widgets/WidgetNumber.vue index 05fdda3dbff..4ee906f6551 100644 --- a/app/gui2/src/components/GraphEditor/widgets/WidgetNumber.vue +++ b/app/gui2/src/components/GraphEditor/widgets/WidgetNumber.vue @@ -7,18 +7,25 @@ import { computed, ref, type ComponentInstance } from 'vue' const props = defineProps(widgetProps(widgetDefinition)) const inputComponent = ref>() -const value = computed({ - get() { - const valueStr = WidgetInput.valueRepr(props.input) - return valueStr ? parseFloat(valueStr) : 0 - }, - set(value) { - props.onUpdate({ - portUpdate: { value: value.toString(), origin: props.input.portId }, - }) - }, + +function setValue(value: number | string) { + props.onUpdate({ + portUpdate: { value: value.toString(), origin: props.input.portId }, + }) +} + +const value = computed(() => { + const inputValue = WidgetInput.valueRepr(props.input) + if (inputValue == null) return undefined + const inputNumber = parseFloat(inputValue) + if (Number.isNaN(inputNumber)) return undefined + return inputNumber }) +const placeholder = computed(() => + value.value == null ? WidgetInput.valueRepr(props.input) : undefined, +) + const limits = computed(() => { const config = props.input.dynamicConfig if (config?.kind === 'Numeric_Input' && config?.minimum != null && config?.maximum != null) { @@ -64,9 +71,11 @@ export const widgetDefinition = defineWidget(