Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
feat(ui): dismiss selected actions with escape (#7638)
Andrew Huang757cf5133035
diff --git a/frontend/src/components/v3/generic/SelectedActionBar/SelectedActionBar.stories.tsx b/frontend/src/components/v3/generic/SelectedActionBar/SelectedActionBar.stories.tsxindex 8dd7b22af4..9207041095 100644--- a/frontend/src/components/v3/generic/SelectedActionBar/SelectedActionBar.stories.tsx+++ b/frontend/src/components/v3/generic/SelectedActionBar/SelectedActionBar.stories.tsx@@ -1,3 +1,4 @@+import { useState } from "react";import type { Meta, StoryObj } from "@storybook/react-vite";import { Button } from "../Button";@@ -52,3 +53,26 @@ export const Hidden: Story = {selectedCount: 0}};++export const EscapeClearsSelection: Story = {+ name: "Interaction: Escape clears selection",+ render: (args) => {+ const [selectedCount, setSelectedCount] = useState(args.selectedCount);++ return (+ <>+ <div className="fixed top-6 left-6 space-y-2 text-sm text-foreground">+ <p>Press Escape while this story is focused to clear the selection.</p>+ <Button size="sm" variant="outline" onClick={() => setSelectedCount(3)}>+ Restore selection+ </Button>+ </div>+ <SelectedActionBar+ {...args}+ selectedCount={selectedCount}+ onClearSelection={() => setSelectedCount(0)}+ />+ </>+ );+ }+};diff --git a/frontend/src/components/v3/generic/SelectedActionBar/SelectedActionBar.tsx b/frontend/src/components/v3/generic/SelectedActionBar/SelectedActionBar.tsxindex 37cfab7f64..3f6bdf14bc 100644--- a/frontend/src/components/v3/generic/SelectedActionBar/SelectedActionBar.tsx+++ b/frontend/src/components/v3/generic/SelectedActionBar/SelectedActionBar.tsx@@ -5,6 +5,16 @@ import { cn } from "@app/components/v3/utils";import { Button } from "../Button";+const OVERLAY_SELECTOR = [+ '[role="dialog"]',+ '[role="menu"]',+ '[role="listbox"]',+ '[data-slot="dialog-content"]',+ '[data-slot="popover-content"]',+ '[data-slot="dropdown-menu-content"]',+ '[data-slot="select-content"]'+].join(", ");+type SelectedActionBarProps = Omit<React.ComponentProps<"div">, "children"> & {selectedCount: number;onClearSelection: () => void;@@ -24,8 +34,31 @@ function SelectedActionBar({...props}: SelectedActionBarProps) {const isVisible = selectedCount > 0;+ const clearSelectionRef = React.useRef(onClearSelection);const lastVisibleContent = React.useRef({ children, selectedCount, selectionLabel });+ clearSelectionRef.current = onClearSelection;++ React.useEffect(() => {+ if (!isVisible) return undefined;++ const handleKeyDown = (event: KeyboardEvent) => {+ if (event.key !== "Escape" || event.defaultPrevented) return;++ const target = event.target instanceof Element ? event.target : null;+ const isEditableTarget =+ target?.closest("input, textarea, select, [contenteditable='true']") ?? false;+ const isOverlayTarget = target?.closest(OVERLAY_SELECTOR) ?? false;++ if (isEditableTarget || isOverlayTarget) return;++ clearSelectionRef.current();+ };++ document.addEventListener("keydown", handleKeyDown);+ return () => document.removeEventListener("keydown", handleKeyDown);+ }, [isVisible]);+if (isVisible) {lastVisibleContent.current = { children, selectedCount, selectionLabel };}