Skip to content

Commit

Permalink
scroll board by dragging
Browse files Browse the repository at this point in the history
Signed-off-by: Simon Hötten <[email protected]>
  • Loading branch information
shoetten committed Nov 16, 2023
1 parent 2242a7d commit 9c22a68
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
36 changes: 34 additions & 2 deletions src/components/board/Board.vue
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@
</form>
</template>
</NcEmptyContent>
<div v-else-if="!isEmpty && !loading" key="board" class="board">
<div v-else-if="!isEmpty && !loading"
key="board"
ref="board"
class="board"
@mousedown="onMouseDown">
<Container lock-axix="y"
orientation="horizontal"
:drag-handle-selector="dragHandleSelector"
Expand All @@ -65,6 +69,7 @@
<Draggable v-for="stack in stacksByBoard"
:key="stack.id"
data-click-closes-sidebar="true"
data-dragscroll-enabled
class="stack-draggable-wrapper">
<Stack :stack="stack" :dragging="draggingStack" data-click-closes-sidebar="true" />
</Draggable>
Expand Down Expand Up @@ -117,6 +122,8 @@ export default {
draggingStack: false,
loading: true,
newStackTitle: '',
currentScrollPosX: null,
currentMousePosX: null,
}
},
computed: {
Expand Down Expand Up @@ -184,12 +191,37 @@ export default {
this.$store.dispatch('createStack', newStack)
this.newStackTitle = ''
},
onMouseDown(event) {
this.startMouseDrag(event)
},
startMouseDrag(event) {
if (!('dragscrollEnabled' in event.target.dataset)) return
event.preventDefault()
this.currentMousePosX = event.clientX
this.currentScrollPosX = this.$refs.board.scrollLeft
this.$refs.board.addEventListener('mousemove', this.handleMouseDrag)
this.$refs.board.addEventListener('mouseup', this.stopMouseDrag)
this.$refs.board.addEventListener('mouseleave', this.stopMouseDrag)
},
handleMouseDrag(event) {
event.preventDefault()
const deltaX = event.clientX - this.currentMousePosX
this.$refs.board.scrollLeft = this.currentScrollPosX - deltaX
},
stopMouseDrag(event) {
this.$refs.board.removeEventListener('mousemove', this.handleMouseDrag)
this.$refs.board.removeEventListener('mouseup', this.stopMouseDrag)
},
},
}
</script>

<style lang="scss" scoped>
@import '../../css/animations';
@import '../../css/variables';
Expand Down
1 change: 1 addition & 0 deletions src/components/board/Stack.vue
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@
data-click-closes-sidebar="true"
non-drag-area-selector=".dragDisabled"
:drag-handle-selector="dragHandleSelector"
data-dragscroll-enabled
@should-accept-drop="canEdit"
@drag-start="draggingCard = true"
@drag-end="draggingCard = false"
Expand Down

0 comments on commit 9c22a68

Please sign in to comment.