Skip to content

Commit

Permalink
Merge pull request writer#683 from madeindjs/fix-slider-warning
Browse files Browse the repository at this point in the history
fix(ui): add default value for Slider
  • Loading branch information
ramedina86 authored Dec 10, 2024
2 parents f663ac2 + f5e574e commit 3364f5e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/ui/src/components/core/input/CoreSliderInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ const { formValue, handleInput } = useFormValueBroker<number>(
wf,
instancePath,
rootInstance,
50,
);
</script>

Expand Down
3 changes: 2 additions & 1 deletion src/ui/src/components/core/input/CoreSliderRangeInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
>
<BaseInputSliderRange
popover-display-mode="always"
:value="formValue || [20, 50]"
:value="formValue"
:min="fields.minValue.value"
:max="fields.maxValue.value"
:step="fields.stepSize.value"
Expand Down Expand Up @@ -103,6 +103,7 @@ const { formValue, handleInput } = useFormValueBroker<[number, number]>(
wf,
instancePath,
rootInstance,
[20, 50],
);
</script>

Expand Down
6 changes: 4 additions & 2 deletions src/ui/src/renderer/useFormValueBroker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,19 @@ import { useEvaluator } from "@/renderer/useEvaluator";
import { Core, InstancePath } from "@/writerTypes";

/**
*
* Encapsulates repeatable form value logic, including binding.
*
* @param wf
* @param componentId
* @param defaultValue the initial value when binding is not set
* @returns
*/
export function useFormValueBroker<T = any>(
wf: Core,
instancePath: InstancePath,
emitterEl: Ref<HTMLElement | ComponentPublicInstance>,
// @ts-expect-error keep default string for compatibility reason
defaultValue: T = "",
) {
const formValue: Ref<T> = ref();
const isBusy = ref(false);
Expand Down Expand Up @@ -110,7 +112,7 @@ export function useFormValueBroker<T = any>(
formValue,
(newValue) => {
if (typeof newValue === "undefined") {
formValue.value = "" as T;
formValue.value = defaultValue;
}
},
{ immediate: true },
Expand Down

0 comments on commit 3364f5e

Please sign in to comment.