From 0c01480fbbf85377f8118453005bbb96b4954036 Mon Sep 17 00:00:00 2001 From: Jeff <158072326+jeffrey701@users.noreply.github.com> Date: Fri, 24 Jul 2026 03:40:31 -0700 Subject: [PATCH] fix(ui-kit): don't hijack Cmd/Ctrl+B Bold in text fields (SidebarProvider) (#8305) --- .../src/components/sidebar.test.tsx | 87 +++++++++++++++++++ .../src/components/sidebar.tsx | 19 ++++ 2 files changed, 106 insertions(+) create mode 100644 packages/loopover-ui-kit/src/components/sidebar.test.tsx diff --git a/packages/loopover-ui-kit/src/components/sidebar.test.tsx b/packages/loopover-ui-kit/src/components/sidebar.test.tsx new file mode 100644 index 0000000000..27d3fbc893 --- /dev/null +++ b/packages/loopover-ui-kit/src/components/sidebar.test.tsx @@ -0,0 +1,87 @@ +import { fireEvent, render, screen } from "@testing-library/react"; +import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; +import { SidebarProvider, useSidebar } from "./sidebar"; + +// jsdom implements no window.matchMedia; SidebarProvider pulls it in via useIsMobile. Stub it desktop-shaped +// (matches:false), the standard shadcn use-mobile test setup. +beforeEach(() => { + vi.stubGlobal( + "matchMedia", + vi.fn(() => ({ + matches: false, + media: "", + addEventListener: () => {}, + removeEventListener: () => {}, + })), + ); +}); +afterEach(() => vi.unstubAllGlobals()); + +// #8305: SidebarProvider's global Cmd/Ctrl+B keydown handler used to toggle the sidebar (and preventDefault()) +// no matter what had focus — hijacking the browser-native Bold shortcut inside text fields. These pin the +// isTyping() guard: the shortcut still works from non-editable targets, and is inert inside a form field or +// contenteditable element (target's own text-editing keeps the native behavior). + +function StateProbe() { + const { open } = useSidebar(); + return {open ? "open" : "closed"}; +} + +function setup() { + const utils = render( + + + +