Skip to content

The agent that grows with you

fix(desktop): pin SearchField's clear button to the row edge (#119204)

Brooklyn Nicholson26481c69ed99
diff --git a/apps/desktop/src/components/ui/search-field.test.tsx b/apps/desktop/src/components/ui/search-field.test.tsx
new file mode 100644
index 00000000000..8b5a3145ff5
--- /dev/null
+++ b/apps/desktop/src/components/ui/search-field.test.tsx
@@ -0,0 +1,48 @@
+import { cleanup, fireEvent, render } from '@testing-library/react'
+import { afterEach, describe, expect, it, vi } from 'vitest'
+
+import { SearchField } from './search-field'
+
+afterEach(cleanup)
+
+describe('SearchField', () => {
+ it('lays the input out as a flex child so the clear button pins to the row edge', () => {
+ // The row is an inline-flex container. The input stays content-sized
+ // (`field-sizing: content`) so width-less callers keep compact rows, but
+ // it is also a flex child that absorbs the row's free space (`flex-1` +
+ // `min-w-0`) — without flex-1 the input kept text width inside a
+ // stretched row (w-full settings rows, flex-1 filter bars) and the clear
+ // button trailed the typed text instead of sitting at the row's right
+ // edge (#119204).
+ const { container, getByRole } = render(<SearchField onChange={() => {}} placeholder="Search" value="abc" />)
+
+ const input = getByRole('textbox') as HTMLInputElement
+ const row = container.firstElementChild as HTMLElement
+
+ expect(row.className).toContain('inline-flex')
+ expect(input.className).toContain('flex-1')
+ expect(input.className).toContain('[field-sizing:content]')
+ expect(input.className).toContain('min-w-0')
+ })
+
+ it('keeps clear wired to the value reset', () => {
+ const onChange = vi.fn()
+ const { getByRole } = render(
+ <SearchField aria-label="find" onChange={onChange} placeholder="Search" value="query" />
+ )
+
+ fireEvent.click(getByRole('button', { name: /clear/i }))
+
+ expect(onChange).toHaveBeenCalledWith('')
+ })
+
+ it('renders no clear button while empty or loading', () => {
+ const { queryByRole, rerender } = render(<SearchField onChange={() => {}} placeholder="Search" value="" />)
+
+ expect(queryByRole('button', { name: /clear/i })).toBeNull()
+
+ rerender(<SearchField loading onChange={() => {}} placeholder="Search" value="query" />)
+
+ expect(queryByRole('button', { name: /clear/i })).toBeNull()
+ })
+})
diff --git a/apps/desktop/src/components/ui/search-field.tsx b/apps/desktop/src/components/ui/search-field.tsx
index c7f6ea68f5a..7275f118978 100644
--- a/apps/desktop/src/components/ui/search-field.tsx
+++ b/apps/desktop/src/components/ui/search-field.tsx
@@ -84,11 +84,14 @@ export function SearchField({
<input
aria-label={ariaLabel ?? placeholder}
className={cn(
- // `field-sizing: content` grows the input to fit the placeholder/typed
- // text; min-w-0 lets it shrink back below content size when the
- // context is narrower — long queries scroll inside the field.
+ // `field-sizing: content` sizes the input to its placeholder/typed
+ // text, so a width-less caller's row stays compact; `flex-1` +
+ // `min-w-0` make the input ABSORB the extra space when the caller
+ // does stretch the row (w-full/flex-1 callers), pinning the clear
+ // button to the row's right edge instead of trailing the typed
+ // text (#119204). Long queries scroll inside the field.
// text-xs matches the form controls (Input/Select via controlVariants).
- 'h-7 min-w-0 max-w-full bg-transparent text-xs text-foreground [field-sizing:content] placeholder:text-muted-foreground focus:outline-none',
+ 'h-7 min-w-0 max-w-full flex-1 bg-transparent text-xs text-foreground [field-sizing:content] placeholder:text-muted-foreground focus:outline-none',
// Boxed: the wrapper owns the chrome, the input fills it (same as an
// adorned Input).
boxed && 'h-auto w-full flex-1 text-sm leading-5 [field-sizing:initial]',