Browse Source

feat(nc-gui): auto focus inputs in survey form

pull/3669/head
braks 2 years ago committed by Raju Udava
parent
commit
5373c30368
  1. 18
      packages/nc-gui/pages/[projectType]/form/[viewId]/index/survey.vue

18
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)
</script>
<template>

Loading…
Cancel
Save