Skip to content

Commit 3586c10

Browse files
feat: add agent emoji search
1 parent e67303f commit 3586c10

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
@@ -122,6 +122,32 @@ export function AgentCreationPreview({
122122
isAvatarMenuOpen && activeTab === "emoji",
123123
);
124124

125+
// Emoji Mart mounts its search input inside a shadow root. Wait for it
126+
// before focusing so the surrounding Radix popover cannot win the race.
127+
React.useEffect(() => {
128+
if (!isAvatarMenuOpen || activeTab !== "emoji") {
129+
return;
130+
}
131+
132+
let animationFrame = 0;
133+
const focusSearchInput = () => {
134+
const searchInput =
135+
emojiPickerContainerRef.current
136+
?.querySelector("em-emoji-picker")
137+
?.shadowRoot?.querySelector<HTMLInputElement>(
138+
'input[type="search"]',
139+
) ?? null;
140+
if (!searchInput) {
141+
animationFrame = window.requestAnimationFrame(focusSearchInput);
142+
return;
143+
}
144+
searchInput.focus();
145+
};
146+
147+
animationFrame = window.requestAnimationFrame(focusSearchInput);
148+
return () => window.cancelAnimationFrame(animationFrame);
149+
}, [activeTab, isAvatarMenuOpen]);
150+
125151
const customColorDraft = React.useMemo(
126152
() => hsvToHex(customHue, customSaturation, customValue),
127153
[customHue, customSaturation, customValue],
@@ -526,6 +552,7 @@ export function AgentCreationPreview({
526552
style={emojiMartThemeVars}
527553
>
528554
<Picker
555+
autoFocus
529556
categories={EMOJI_MART_CATEGORIES}
530557
data={emojiData}
531558
dynamicWidth
@@ -553,7 +580,7 @@ export function AgentCreationPreview({
553580
applyEmojiAvatar(emoji.native, nextColor);
554581
}}
555582
previewPosition="none"
556-
searchPosition="none"
583+
searchPosition="sticky"
557584
set="native"
558585
skinTonePosition="none"
559586
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)