Skip to content

Commit

Permalink
Merge 4ed924b into c519529
Browse files Browse the repository at this point in the history
  • Loading branch information
nolanlawson committed Dec 18, 2022
2 parents c519529 + 4ed924b commit 1badcd6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
12 changes: 3 additions & 9 deletions src/picker/components/Picker/Picker.js
Expand Up @@ -22,6 +22,7 @@ import { requestPostAnimationFrame } from '../../utils/requestPostAnimationFrame
import { tick } from 'svelte'
import { requestAnimationFrame } from '../../utils/requestAnimationFrame'
import { uniq } from '../../../shared/uniq'
import { resetScrollTopIfPossible } from '../../utils/resetScrollTopIfPossible.js'

// public
export let skinToneEmoji
Expand Down Expand Up @@ -302,15 +303,8 @@ $: {
requestAnimationFrame(() => checkZwjSupportAndUpdate(zwjEmojisToCheck))
} else {
currentEmojis = currentEmojis.filter(isZwjSupported)
requestAnimationFrame(() => {
// Avoid Svelte doing an invalidation on the "setter" here.
// At best the invalidation is useless, at worst it can cause infinite loops:
// https://github.com/nolanlawson/emoji-picker-element/pull/180
// https://github.com/sveltejs/svelte/issues/6521
// Also note tabpanelElement can be null if the element is disconnected
// immediately after connected, hence `|| {}`
(tabpanelElement || {}).scrollTop = 0 // reset scroll top to 0 when emojis change
})
// Reset scroll top to 0 when emojis change
requestAnimationFrame(() => resetScrollTopIfPossible(tabpanelElement))
}
}

Expand Down
10 changes: 10 additions & 0 deletions src/picker/utils/resetScrollTopIfPossible.js
@@ -0,0 +1,10 @@
// Note we put this in its own function outside Picker.js to avoid Svelte doing an invalidation on the "setter" here.
// At best the invalidation is useless, at worst it can cause infinite loops:
// https://github.com/nolanlawson/emoji-picker-element/pull/180
// https://github.com/sveltejs/svelte/issues/6521
// Also note tabpanelElement can be null if the element is disconnected immediately after connected
export function resetScrollTopIfPossible (element) {
if (element) {
element.scrollTop = 0
}
}

0 comments on commit 1badcd6

Please sign in to comment.