From 5373c3036866db58b322b424d3be9dedff57a376 Mon Sep 17 00:00:00 2001 From: braks <78412429+bcakmakoglu@users.noreply.github.com> Date: Tue, 4 Oct 2022 18:50:11 +0200 Subject: [PATCH] feat(nc-gui): auto focus inputs in survey form --- .../form/[viewId]/index/survey.vue | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/packages/nc-gui/pages/[projectType]/form/[viewId]/index/survey.vue b/packages/nc-gui/pages/[projectType]/form/[viewId]/index/survey.vue index b2a90d89a2..dbad8242b6 100644 --- a/packages/nc-gui/pages/[projectType]/form/[viewId]/index/survey.vue +++ b/packages/nc-gui/pages/[projectType]/form/[viewId]/index/survey.vue @@ -6,6 +6,7 @@ import { DropZoneRef, computed, onKeyStroke, + onMounted, provide, ref, useEventListener, @@ -85,6 +86,8 @@ function transition(direction: TransitionDirection) { setTimeout(() => { isTransitioning.value = false + + setTimeout(focusInput, 100) }, 1000) } @@ -113,6 +116,19 @@ async function goPrevious() { goToPrevious() } +function focusInput() { + if (document && typeof document !== 'undefined') { + const inputEl = + (document.querySelector('.nc-cell input') as HTMLInputElement) || + (document.querySelector('.nc-cell textarea') as HTMLTextAreaElement) + + if (inputEl) { + inputEl.select() + inputEl.focus() + } + } +} + useEventListener('wheel', (event) => { if (Math.abs(event.deltaX) < Math.abs(event.deltaY)) { // Scrolling more vertically than horizontally @@ -130,6 +146,8 @@ useEventListener('wheel', (event) => { onKeyStroke(['ArrowLeft', 'ArrowDown'], goPrevious) onKeyStroke(['ArrowRight', 'ArrowUp', 'Enter', 'Space'], goNext) + +onMounted(focusInput)