Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Pinned messages menu: after the last unpin, focus goes to the nearest button, not the first
luishron12363aa8e026f38
diff --git a/src/components/PinnedMessagesMenu.dom.test.ts b/src/components/PinnedMessagesMenu.dom.test.tsindex 6102237334..777216dce9 100644--- a/src/components/PinnedMessagesMenu.dom.test.ts+++ b/src/components/PinnedMessagesMenu.dom.test.ts@@ -59,6 +59,7 @@ it("closes for good once the last pin is gone, and hands focus to the button besconst onUnpin = vi.fn();const root = createRoot(document.body.appendChild(document.createElement("div")));const render = (pins: typeof PINS) => act(async () => root.render(createElement("div", null,+ createElement("button", { "data-first": "" }),createElement("button", { "data-beside": "" }),createElement(PinnedMessagesMenu, { pins, onJump: vi.fn(), onUnpin }),)));@@ -75,6 +76,21 @@ it("closes for good once the last pin is gone, and hands focus to the button besact(() => root.unmount());});+it("prefers the button after the menu to the one before it when the last pin goes", async () => {+ const root = createRoot(document.body.appendChild(document.createElement("div")));+ await act(async () => root.render(createElement("div", null,+ createElement("button", { "data-before": "" }),+ createElement(PinnedMessagesMenu, { pins: PINS, onJump: vi.fn(), onUnpin: vi.fn() }),+ createElement("button", { disabled: true }),+ createElement("button", { "data-after": "" }),+ createElement("button", { "data-last": "" }),+ )));+ await act(async () => trigger()!.click());+ await act(async () => items()[1]!.click());+ expect(document.activeElement).toBe(document.querySelector("[data-after]"));+ act(() => root.unmount());+});+it("jumps to a row by its first letter, and Tab closes the menu back onto its button", async () => {const { root } = await mount();await act(async () => trigger()!.click());diff --git a/src/components/PinnedMessagesMenu.tsx b/src/components/PinnedMessagesMenu.tsxindex db2ca34bf5..e7488408b8 100644--- a/src/components/PinnedMessagesMenu.tsx+++ b/src/components/PinnedMessagesMenu.tsx@@ -48,8 +48,11 @@ export function PinnedMessagesMenu({ pins, onJump, onUnpin, triggerClassName }:const unpin = (messageId: string) => {if (pins.length === 1) {setOpen(false);- const beside = [...(root.current?.parentElement?.querySelectorAll<HTMLElement>("button:not(:disabled)") ?? [])];- (beside.find((button) => !root.current?.contains(button) && button.checkVisibility?.() !== false) ?? trigger.current)?.focus();+ const here = root.current;+ const beside = [...(here?.parentElement?.querySelectorAll<HTMLElement>("button:not(:disabled)") ?? [])]+ .filter((button) => !here?.contains(button) && button.checkVisibility?.() !== false);+ const comesAfter = (button: HTMLElement) => Boolean(here && here.compareDocumentPosition(button) & Node.DOCUMENT_POSITION_FOLLOWING);+ (beside.find(comesAfter) ?? beside.findLast((button) => !comesAfter(button)) ?? trigger.current)?.focus();}onUnpin?.(messageId);};