Skip to content

Commit 313f793

Browse files
feat(desktop): add search to agent emoji picker (#2630)
## Why The agent avatar picker disables Emoji Mart search, making emojis difficult to find when creating or editing an agent. ## What - Enable sticky search in the shared agent avatar picker - Focus the search field when the Emoji tab opens - Add end-to-end coverage for search, focus, and selection ## Risk Assessment Low — this is limited to the desktop agent avatar picker and does not change avatar persistence or agent configuration. ## References - `pnpm --dir desktop test` — 3,448 passed - `pnpm --dir desktop typecheck` — passed - `pnpm --dir desktop exec playwright test tests/e2e/agents.spec.ts` — 20 passed --- **Update Jul 24, 16:28 EDT:** Completed `CONTRIBUTING.md` validation. ### Manual test 1. Create an agent and open Add avatar → Emoji. 2. Confirm the search field is focused and filters results. 3. Select an emoji and confirm it becomes the avatar. 4. Repeat while editing an existing agent. ### Validation - `just ci` — passed - `just test` — passed ### Follow-up work None. Generated with Codex
1 parent be275cf commit 313f793

2 files changed

Lines changed: 51 additions & 1 deletion

File tree

‎desktop/src/features/agents/ui/AgentCreationPreview.tsx‎

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,32 @@ export function AgentCreationPreview({
133133
isAvatarMenuOpen && activeTab === "emoji",
134134
);
135135

136+
// Emoji Mart mounts its search input inside a shadow root. Wait for it
137+
// before focusing so the surrounding Radix popover cannot win the race.
138+
React.useEffect(() => {
139+
if (!isAvatarMenuOpen || activeTab !== "emoji") {
140+
return;
141+
}
142+
143+
let animationFrame = 0;
144+
const focusSearchInput = () => {
145+
const searchInput =
146+
emojiPickerContainerRef.current
147+
?.querySelector("em-emoji-picker")
148+
?.shadowRoot?.querySelector<HTMLInputElement>(
149+
'input[type="search"]',
150+
) ?? null;
151+
if (!searchInput) {
152+
animationFrame = window.requestAnimationFrame(focusSearchInput);
153+
return;
154+
}
155+
searchInput.focus();
156+
};
157+
158+
animationFrame = window.requestAnimationFrame(focusSearchInput);
159+
return () => window.cancelAnimationFrame(animationFrame);
160+
}, [activeTab, isAvatarMenuOpen]);
161+
136162
const customColorDraft = React.useMemo(
137163
() => hsvToHex(customHue, customSaturation, customValue),
138164
[customHue, customSaturation, customValue],
@@ -550,6 +576,7 @@ export function AgentCreationPreview({
550576
style={emojiMartThemeVars}
551577
>
552578
<Picker
579+
autoFocus
553580
categories={EMOJI_MART_CATEGORIES}
554581
data={emojiData}
555582
dynamicWidth
@@ -577,7 +604,7 @@ export function AgentCreationPreview({
577604
applyEmojiAvatar(emoji.native, nextColor);
578605
}}
579606
previewPosition="none"
580-
searchPosition="none"
607+
searchPosition="sticky"
581608
set="native"
582609
skinTonePosition="none"
583610
theme="auto"

‎desktop/tests/e2e/agents.spec.ts‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,29 @@ test("built-in persona edits persist", async ({ page }) => {
263263
});
264264
});
265265

266+
test("searches agent avatar emoji with focus on open", async ({ page }) => {
267+
await gotoApp(page);
268+
await page.getByTestId("open-agents-view").click();
269+
await page.getByTestId("new-agent-card").click();
270+
await page.getByRole("menuitem", { name: "Create from scratch" }).click();
271+
272+
await expect(page.getByTestId("persona-dialog")).toBeVisible();
273+
await page.getByLabel("Add avatar").click();
274+
await page.getByRole("tab", { name: "Emoji" }).click();
275+
276+
const picker = page.locator("em-emoji-picker");
277+
const searchInput = picker.locator("input[type='search']");
278+
await expect(searchInput).toBeVisible();
279+
await expect(searchInput).toBeFocused();
280+
281+
await searchInput.fill("rocket");
282+
await picker.locator("button[aria-label='🚀']").first().click();
283+
284+
await expect(page.getByRole("img", { name: "Agent name avatar" })).toHaveText(
285+
"🚀",
286+
);
287+
});
288+
266289
test("agent avatar emoji picker scrolls inside its popover", async ({
267290
page,
268291
}) => {

0 commit comments

Comments
 (0)