From 9d6200e275b6a05c9e983ba91ef0c74d36efdb7b Mon Sep 17 00:00:00 2001 From: Santiago Balladares <744091+santiagoballadares@users.noreply.github.com> Date: Sun, 3 Dec 2023 18:36:36 +0100 Subject: [PATCH] refact(kt-field): refact label to reduce field interactivity Co-Authored-By: Carol Soliman <17387510+carsoli@users.noreply.github.com> --- .../source/kotti-field-date/KtFieldDate.vue | 1 + .../kotti-field-date/KtFieldDateRange.vue | 2 + .../kotti-field-date/KtFieldDateTime.vue | 1 + .../kotti-field-date/KtFieldDateTimeRange.vue | 2 + .../KtFieldFileUpload.vue | 5 +- .../KtFieldFileUploadRemote.vue | 5 +- .../components/DropArea.vue | 21 +++++--- .../source/kotti-field-file-upload/types.ts | 28 +++++----- .../kotti-field-number/KtFieldNumber.vue | 5 +- .../components/ActionIcon.vue | 2 +- .../components/GenericSelectField.vue | 26 +++++++-- .../hooks/use-select-tippy.ts | 15 ++++-- .../kotti-field-toggle/KtFieldToggle.vue | 7 ++- .../components/ToggleInner.vue | 4 +- .../components/ToggleInnerSuffix.vue | 4 +- .../kotti-ui/source/kotti-field/KtField.vue | 53 +++++++++++++------ packages/kotti-ui/source/kotti-field/hooks.ts | 12 +++++ packages/kotti-ui/source/kotti-field/types.ts | 1 + 18 files changed, 141 insertions(+), 53 deletions(-) diff --git a/packages/kotti-ui/source/kotti-field-date/KtFieldDate.vue b/packages/kotti-ui/source/kotti-field-date/KtFieldDate.vue index 96a266649e..86586f5b68 100644 --- a/packages/kotti-ui/source/kotti-field-date/KtFieldDate.vue +++ b/packages/kotti-ui/source/kotti-field-date/KtFieldDate.vue @@ -90,6 +90,7 @@ export default defineComponent({ clearable: !field.hideClear, 'data-test': field.inputProps['data-test'], disabled: field.isDisabled || field.isLoading, + id: field.inputProps.id, pickerOptions: pickerOptions.value, placeholder: props.placeholder ?? '', type: 'date', diff --git a/packages/kotti-ui/source/kotti-field-date/KtFieldDateRange.vue b/packages/kotti-ui/source/kotti-field-date/KtFieldDateRange.vue index ee4004a32d..70ddbba7b5 100644 --- a/packages/kotti-ui/source/kotti-field-date/KtFieldDateRange.vue +++ b/packages/kotti-ui/source/kotti-field-date/KtFieldDateRange.vue @@ -4,6 +4,7 @@ class="kt-field-date-range" :getEmptyValue="() => [null, null]" :helpTextSlot="$slots.helpText" + isRange >
-
+
showDropArea.value ? { 'padding-top': 'var(--unit-4)' } : undefined, ), + inputId: computed(() => field.inputProps.id), onAddFiles: (value: Shared.Events.AddFiles) => { if (props.allowMultiple) field.setValue([ diff --git a/packages/kotti-ui/source/kotti-field-file-upload/KtFieldFileUploadRemote.vue b/packages/kotti-ui/source/kotti-field-file-upload/KtFieldFileUploadRemote.vue index ce3e3ab471..3000c37197 100644 --- a/packages/kotti-ui/source/kotti-field-file-upload/KtFieldFileUploadRemote.vue +++ b/packages/kotti-ui/source/kotti-field-file-upload/KtFieldFileUploadRemote.vue @@ -9,6 +9,7 @@ collapseExtensionsAfter, externalUrl, icon, + inputId, tabIndex, }" @addFiles="onAddFiles" @@ -24,7 +25,7 @@ /> -
+
showDropArea.value ? { 'padding-top': 'var(--unit-4)' } : undefined, ), + inputId: computed(() => field.inputProps.id), onAddFiles: (value: Shared.Events.AddFiles) => { if (props.allowMultiple) field.setValue([ diff --git a/packages/kotti-ui/source/kotti-field-file-upload/components/DropArea.vue b/packages/kotti-ui/source/kotti-field-file-upload/components/DropArea.vue index 454f4de203..92704a553c 100644 --- a/packages/kotti-ui/source/kotti-field-file-upload/components/DropArea.vue +++ b/packages/kotti-ui/source/kotti-field-file-upload/components/DropArea.vue @@ -3,11 +3,12 @@ :class="classes" :data-test="dataTest ? `${dataTest}.dropArea` : undefined" :tabIndex="_tabIndex" + @click.stop="onTriggerInput" @dragleave.stop.prevent="onDragLeave" @dragover.stop.prevent="onDragOver" @drop.stop.prevent="onDrop" - @keydown.enter.stop.prevent="uploadInputRef.click()" - @keydown.space.stop.prevent="uploadInputRef.click()" + @keydown.enter.stop.prevent="onTriggerInput" + @keydown.space.stop.prevent="onTriggerInput" @mouseenter.stop.prevent="isHovering = true" @mouseleave.stop.prevent="isHovering = false" > @@ -33,11 +34,7 @@
(props.isDisabled ? -1 : props.tabIndex ?? 0)), - accept: computed(() => buildAcceptString(props.extensions)), classes: computed(() => ({ 'kt-field-file-upload-drop-area': true, 'kt-field-file-upload-drop-area--is-disabled': props.isDisabled, @@ -122,6 +118,14 @@ export default defineComponent({ (isDragging.value || isHovering.value), })), informationText, + inputProps: computed(() => ({ + accept: buildAcceptString(props.extensions), + 'data-test': props.dataTest ? `${props.dataTest}.input` : undefined, + disabled: props.isDisabled || props.isLoading, + id: props.inputId, + multiple: props.allowMultiple, + type: 'file', + })), isError, isHovering, onDragLeave: () => { @@ -145,6 +149,7 @@ export default defineComponent({ const target = event.target as HTMLInputElement emitFiles(target.files) }, + onTriggerInput: () => uploadInputRef.value?.click(), showInformation: computed( () => informationText.value || props.externalUrl, ), diff --git a/packages/kotti-ui/source/kotti-field-file-upload/types.ts b/packages/kotti-ui/source/kotti-field-file-upload/types.ts index 977192c50d..4c06198ba4 100644 --- a/packages/kotti-ui/source/kotti-field-file-upload/types.ts +++ b/packages/kotti-ui/source/kotti-field-file-upload/types.ts @@ -82,18 +82,22 @@ export namespace Shared { } export namespace DropArea { - export const schema = propsSchema.pick({ - allowMultiple: true, - collapseExtensionsAfter: true, - dataTest: true, - extensions: true, - externalUrl: true, - icon: true, - isDisabled: true, - isLoading: true, - maxFileSize: true, - tabIndex: true, - }) + export const schema = propsSchema + .pick({ + allowMultiple: true, + collapseExtensionsAfter: true, + dataTest: true, + extensions: true, + externalUrl: true, + icon: true, + isDisabled: true, + isLoading: true, + maxFileSize: true, + tabIndex: true, + }) + .extend({ + inputId: z.number(), + }) export type Props = z.output } diff --git a/packages/kotti-ui/source/kotti-field-number/KtFieldNumber.vue b/packages/kotti-ui/source/kotti-field-number/KtFieldNumber.vue index 3d244b078e..320996b192 100644 --- a/packages/kotti-ui/source/kotti-field-number/KtFieldNumber.vue +++ b/packages/kotti-ui/source/kotti-field-number/KtFieldNumber.vue @@ -63,7 +63,7 @@ import { import Big from 'big.js' import { KtField } from '../kotti-field' -import { useField, useForceUpdate } from '../kotti-field/hooks' +import { useFocusInput, useField, useForceUpdate } from '../kotti-field/hooks' import { useI18nContext } from '../kotti-i18n/hooks' import { KottiI18n } from '../kotti-i18n/types' import { makeProps } from '../make-props' @@ -93,6 +93,7 @@ export default defineComponent({ supports: KOTTI_FIELD_NUMBER_SUPPORTS, }) + const { focusInput } = useFocusInput(field.inputProps.id) const { forceUpdate, forceUpdateKey } = useForceUpdate() const i18nContext = useI18nContext() @@ -225,6 +226,7 @@ export default defineComponent({ : props.minimum ?? props.maximum ?? 0 : Big(field.currentValue).minus(props.step).toNumber(), ) + focusInput() } const incrementValue = () => { @@ -237,6 +239,7 @@ export default defineComponent({ : props.minimum ?? props.maximum ?? 0 : Big(field.currentValue).add(props.step).toNumber(), ) + focusInput() } const wrapperRef = ref(null) diff --git a/packages/kotti-ui/source/kotti-field-select/components/ActionIcon.vue b/packages/kotti-ui/source/kotti-field-select/components/ActionIcon.vue index 94701dcda3..df4df2c662 100644 --- a/packages/kotti-ui/source/kotti-field-select/components/ActionIcon.vue +++ b/packages/kotti-ui/source/kotti-field-select/components/ActionIcon.vue @@ -4,7 +4,7 @@ v-if="showClear" class="yoco" role="button" - @click.stop="handleClear()" + @click.stop="handleClear" v-text="Yoco.Icon.CLOSE" />
@@ -75,7 +76,13 @@