diff --git a/apps/zbugs/src/components/emoji-panel.tsx b/apps/zbugs/src/components/emoji-panel.tsx index 1be0ecff77..eacb9f25da 100644 --- a/apps/zbugs/src/components/emoji-panel.tsx +++ b/apps/zbugs/src/components/emoji-panel.tsx @@ -148,8 +148,10 @@ function normalizeEmoji(emoji: string): string { } function groupAndSortEmojis(emojis: Emoji[]): Record { + // Sort the emojis by creation time. Not sure how to sort this with ZQL. + const sortedEmojis = [...emojis].sort((a, b) => a.created - b.created); const rv: Record = {}; - for (const emoji of emojis) { + for (const emoji of sortedEmojis) { const normalizedEmoji = normalizeEmoji(emoji.value); if (!rv[normalizedEmoji]) { rv[normalizedEmoji] = []; @@ -157,11 +159,6 @@ function groupAndSortEmojis(emojis: Emoji[]): Record { rv[normalizedEmoji].push(emoji); } - // Sort the emojis by creation time. Not sure how to sort this with ZQL. - for (const key in rv) { - rv[key] = rv[key].sort((a, b) => a.created - b.created); - } - return rv; } diff --git a/apps/zbugs/src/components/emoji-picker.tsx b/apps/zbugs/src/components/emoji-picker.tsx index 3b164da998..8d5dab3229 100644 --- a/apps/zbugs/src/components/emoji-picker.tsx +++ b/apps/zbugs/src/components/emoji-picker.tsx @@ -71,6 +71,31 @@ export function EmojiPicker({onEmojiChange}: Props) { el.addEventListener('emoji-click', onEmojiClick); el.addEventListener('skin-tone-change', onSkinToneChange); lastPicker.current = el; + + // The emoji-picker-element does not allow auto focusing the search input + // when it's first rendered. We can work around this by observing the + // shadow DOM and focusing the search input when it's added to the DOM. + if (el.shadowRoot) { + const m = new MutationObserver(records => { + for (const record of records) { + for (const node of record.addedNodes) { + if (node.nodeType === Node.ELEMENT_NODE) { + const search = (node as Element).querySelector('#search'); + if (search) { + (search as HTMLElement).focus(); + m.disconnect(); + } + return; + } + } + } + }); + + m.observe(el.shadowRoot, { + subtree: true, + childList: true, + }); + } } };