From 314a4474f6475435cfac7e5e02862015a9455660 Mon Sep 17 00:00:00 2001 From: tusooa Date: Mon, 2 Jan 2023 12:40:03 -0500 Subject: [PATCH] Fix header indicator --- src/components/emoji_picker/emoji_picker.js | 28 +++++++++++++++++--- src/components/emoji_picker/emoji_picker.vue | 2 ++ 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/components/emoji_picker/emoji_picker.js b/src/components/emoji_picker/emoji_picker.js index c87dea7e21..9c97e16ccd 100644 --- a/src/components/emoji_picker/emoji_picker.js +++ b/src/components/emoji_picker/emoji_picker.js @@ -81,6 +81,13 @@ const filterByKeyword = (list, keyword = '', languages, nameLocalizer) => { return orderedEmojiList.flat() } +const getOffset = (elem) => { + const style = elem.style.transform + const res = /translateY\((\d+)px\)/.exec(style) + if (!res) { return 0 } + return res[1] +} + const EmojiPicker = { props: { enableStickerPicker: { @@ -144,12 +151,25 @@ const EmojiPicker = { this.$emit('emoji', { insertion: value, keepOpen: this.keepOpen }) }, onScroll (startIndex, endIndex, visibleStartIndex, visibleEndIndex) { + console.log('onScroll', startIndex, endIndex, visibleStartIndex, visibleEndIndex) const current = this.filteredEmojiGroups[visibleStartIndex].id - this.scrolledGroup(current) + const target = this.$refs['emoji-groups'].$el + this.scrolledGroup(target, current, visibleStartIndex, visibleEndIndex) }, - scrolledGroup (groupId) { - this.activeGroup = groupId - this.scrollHeader() + scrolledGroup (target, groupId, start, end) { + const top = target.scrollTop + 5 + this.$nextTick(() => { + this.filteredEmojiGroups.slice(start, end + 1).forEach(group => { + const ref = this.groupRefs['group-' + group.id] + if (!ref) { return } + const elem = ref.$el.parentElement + if (!elem) { return } + if (elem && getOffset(elem) <= top) { + this.activeGroup = group.id + } + }) + this.scrollHeader() + }) }, scrollHeader () { // Scroll the active tab's header into view diff --git a/src/components/emoji_picker/emoji_picker.vue b/src/components/emoji_picker/emoji_picker.vue index 15cdb7041f..78da48083e 100644 --- a/src/components/emoji_picker/emoji_picker.vue +++ b/src/components/emoji_picker/emoji_picker.vue @@ -80,10 +80,12 @@ :class="groupsScrolledClass" :min-item-size="minItemSize" :items="filteredEmojiGroups" + :emit-update="true" @update="onScroll" >