Fully autonomous AI Agents system capable of performing complex penetration testing tasks
Go ai-agentsai-security-toolanthropicautonomous-agentsgolanggptgraphqlmulti-agent-systemoffensive-securityopen-sourceopenaipenetration-testingpenetration-testing-toolsreactsecurity-automationsecurity-testingsecurity-toolsself-hosted
feat(frontend): add trailing X clear button to InputSearch (parity with DataTableFilter)
Sergey Kozyrenko237179524b4d
diff --git a/frontend/src/components/ui/input-search.test.tsx b/frontend/src/components/ui/input-search.test.tsxindex b10aa96d..59901016 100644--- a/frontend/src/components/ui/input-search.test.tsx+++ b/frontend/src/components/ui/input-search.test.tsx@@ -137,6 +137,70 @@ describe('InputSearch — typing and outbound emit', () => {});});+describe('InputSearch — trailing clear button', () => {+ const queryClearButton = () => screen.queryByRole('button', { name: 'Clear search docs' });++ it('does not render the clear button when the field is empty', () => {+ render(<SearchHost emitted={[]} initialQuery="" />, { wrapper: Wrapper });+ expect(queryClearButton()).not.toBeInTheDocument();+ });++ it('renders the clear button on mount when deep-linked with a non-empty query', () => {+ render(<SearchHost emitted={[]} initialQuery="jwt" />, { wrapper: Wrapper });+ expect(queryClearButton()).toBeInTheDocument();+ });++ it('shows the clear button after typing, hides it once the field is empty again', async () => {+ const emitted: string[] = [];+ const user = userEvent.setup();+ render(<SearchHost emitted={emitted} initialQuery="" />, { wrapper: Wrapper });++ await user.click(queryTrigger()!);+ expect(queryClearButton()).not.toBeInTheDocument();++ await user.type(getInput(), 'foo');+ expect(queryClearButton()).toBeInTheDocument();++ await user.clear(getInput());+ expect(queryClearButton()).not.toBeInTheDocument();+ });++ it('clears the value, emits "" upstream, and keeps focus on the input', async () => {+ const emitted: string[] = [];+ const user = userEvent.setup();+ render(<SearchHost emitted={emitted} initialQuery="jwt" />, { wrapper: Wrapper });++ const input = getInput();+ await user.click(queryClearButton()!);+ await sleep(PAST_DEBOUNCE_MS);++ expect(input.value).toBe('');+ expect(emitted.at(-1)).toBe('');+ // Focus returned to the input — the programmatic-clear collapse+ // effect should NOT fire, so the trigger button stays absent.+ expect(document.activeElement).toBe(input);+ expect(queryTrigger()).not.toBeInTheDocument();+ });++ it('drops a pending debounce when clicked mid-typing', async () => {+ const emitted: string[] = [];+ const user = userEvent.setup();+ render(<SearchHost emitted={emitted} />, { wrapper: Wrapper });++ await user.click(queryTrigger()!);+ await user.type(getInput(), 'ab');+ // Clear button appears as soon as a character is typed.+ const clearBtn = queryClearButton();+ expect(clearBtn).toBeInTheDocument();++ await user.click(clearBtn!);+ await sleep(PAST_DEBOUNCE_MS);++ expect(emitted.some((value) => value.length > 0)).toBe(false);+ expect(getInput().value).toBe('');+ });+});+describe('InputSearch — Escape semantics', () => {it('first Esc clears a non-empty query but keeps the input expanded', async () => {const emitted: string[] = [];diff --git a/frontend/src/components/ui/input-search.tsx b/frontend/src/components/ui/input-search.tsxindex dc64f8a7..eee3e795 100644--- a/frontend/src/components/ui/input-search.tsx+++ b/frontend/src/components/ui/input-search.tsx@@ -1,4 +1,4 @@-import { Search } from 'lucide-react';+import { Search, X } from 'lucide-react';import { motion } from 'motion/react';import { type ChangeEvent, useCallback, useEffect, useMemo, useRef, useState } from 'react';import { useDebouncedCallback } from 'use-debounce';@@ -40,7 +40,20 @@ interface InputSearchProps {* Collapsible search input. Idle state shows only a `<Search>` icon button;* clicking it (or pressing the configured hotkey) expands a controlled text* input with a smooth width animation. Blurring an empty input collapses it- * back. Escape clears the value, a second Escape collapses + blurs.+ * back.+ *+ * Clearing the value has two equivalent entry points:+ * - A trailing `<X>` button rendered only while the field has content+ * (mirrors `DataTableFilter` so every search field across the app shares+ * the same shape).+ * - First `Escape` press — same effect, useful when the user's hand is on+ * the keyboard. A second `Escape` on an already-empty field collapses+ * and blurs.+ *+ * Both paths route through `handleClear`, which cancels any pending+ * debounce, emits `''` upstream, and keeps focus on the input — so the+ * field stays open and ready for fresh typing rather than collapsing out+ * from under the user.** The trigger is a real `<button>` (via `InputGroupButton`) — never a `<div>`* with `onClick` — so the control is reachable with Tab and announced by@@ -199,9 +212,27 @@ export function InputSearch({[debouncedEmit],);- // Escape: first press clears the value, second press collapses + blurs.- // The clear path cancels any pending debounce synchronously, then emits- // `''` directly — no chance for an in-flight typed value to land after.+ // Shared clear path used by both the trailing `<X>` button and the first+ // `Escape` press. Focus stays on the input so the programmatic-clear+ // collapse effect (the one keyed on `searchQuery`) doesn't fire — the+ // user just emptied the value and is presumably about to type again,+ // not exit the search.+ const handleClear = useCallback(() => {+ setLocalValue('');+ debouncedEmit.cancel();++ if (lastEmittedReference.current !== '') {+ lastEmittedReference.current = '';+ onSearchChange('');+ }++ inputRef.current?.focus();+ }, [debouncedEmit, onSearchChange]);++ // Escape: first press clears the value (via `handleClear`), second press+ // collapses + blurs. The clear path cancels any pending debounce+ // synchronously, then emits `''` directly — no chance for an in-flight+ // typed value to land after.const handleInputKeyDown = useCallback((event: React.KeyboardEvent<HTMLInputElement>) => {if (event.key !== 'Escape') {@@ -211,13 +242,7 @@ export function InputSearch({event.preventDefault();if (localValue.length > 0) {- setLocalValue('');- debouncedEmit.cancel();-- if (lastEmittedReference.current !== '') {- lastEmittedReference.current = '';- onSearchChange('');- }+ handleClear();return;}@@ -225,7 +250,7 @@ export function InputSearch({inputRef.current?.blur();setIsExpanded(false);},- [debouncedEmit, localValue, onSearchChange],+ [handleClear, localValue],);return (@@ -299,6 +324,17 @@ export function InputSearch({value={localValue}/></motion.div>+ {isExpanded && localValue ? (+ <InputGroupAddon align="inline-end">+ <InputGroupButton+ aria-label={`Clear ${ariaLabel.toLowerCase()}`}+ onClick={handleClear}+ type="button"+ >+ <X />+ </InputGroupButton>+ </InputGroupAddon>+ ) : null}</InputGroup>);}