Skip to content

Commit

Permalink
fix(KtFieldToggle/KtField*Select*): isLoading edge cases
Browse files Browse the repository at this point in the history
- prevent triggering setValue on isLoading for KtFieldToggle
- prevent openning tippy on select fields on isLoading
- throw on KtField if setValue is triggered while isLoading is true

Co-Authored-By: Florian Wendelborn <[email protected]>
  • Loading branch information
carsoli and FlorianWendelborn committed Dec 5, 2023
1 parent 75c13a1 commit 3d8e861
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const useSelectTippy = <T>(field: KottiField.Hook.Returns<T>) => {
isDropdownOpen.value = false
},
onShow: () => {
if (field.isDisabled) return false
if (field.isDisabled || field.isLoading) return false

// More correct here, don't move to `onShown()`
isDropdownMounted.value = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ export default defineComponent({
forceUpdateKey: forceUpdateKey.value,
})),
onInput: (newValue: boolean | undefined) => {
field.setValue(newValue ?? null)
if (!field.isDisabled && !field.isLoading)
field.setValue(newValue ?? null)
forceUpdate()
},
Expand Down
5 changes: 4 additions & 1 deletion packages/kotti-ui/source/kotti-field/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,13 @@ const useValue = <DATA_TYPE>({
context,
emit,
isDisabled,
isLoading,
isEmpty,
props,
}: Pick<KottiField.Hook.Parameters<DATA_TYPE>, 'emit' | 'isEmpty' | 'props'> & {
context: KottiForm.Context | null
isDisabled: Ref<boolean>
isLoading: Ref<boolean>
}) => {
watch(
() => props.formKey,
Expand Down Expand Up @@ -114,7 +116,7 @@ const useValue = <DATA_TYPE>({
* @param options defines forceUpdate to set value even when the field is disabled
*/
setValue: ref((newValue: unknown, options?: { forceUpdate: boolean }) => {
if (isDisabled.value && !options?.forceUpdate)
if ((isDisabled.value || isLoading.value) && !options?.forceUpdate)
throw new KtFieldErrors.DisabledSetValueCalled(props)

if (
Expand Down Expand Up @@ -256,6 +258,7 @@ export const useField = <DATA_TYPE>({
emit,
isEmpty,
isDisabled: sharedProperties.isDisabled,
isLoading: sharedProperties.isLoading,
props,
})

Expand Down

0 comments on commit 3d8e861

Please sign in to comment.