@estiva-app/ui 0.60.0 → 0.60.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/TopBar.d.ts +5 -0
- package/dist/TopBar.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +2 -2
- package/package.json +1 -1
- package/registry.json +1 -1
- package/src/TopBar.mdx +2 -0
- package/src/TopBar.test.tsx +24 -0
- package/src/TopBar.tsx +6 -1
package/package.json
CHANGED
package/registry.json
CHANGED
package/src/TopBar.mdx
CHANGED
|
@@ -64,6 +64,8 @@ import { TopBar, IdentityMenu } from '@estiva-app/ui'
|
|
|
64
64
|
don't restyle it per app.
|
|
65
65
|
- `onSearch` is called on every Ctrl+K, open or not: to close the launcher
|
|
66
66
|
on a second Ctrl+K, toggle in your handler.
|
|
67
|
+
- A click on the field leaves focus where it was, so a launcher can act on the
|
|
68
|
+
text box and the selection you were in. Tab still reaches the field.
|
|
67
69
|
- The frame is desktop-only for now — there is no narrow-screen
|
|
68
70
|
behaviour; the menu button collapses panels, it does not open a drawer.
|
|
69
71
|
|
package/src/TopBar.test.tsx
CHANGED
|
@@ -29,6 +29,30 @@ describe('TopBar search', () => {
|
|
|
29
29
|
expect(onSearch).toHaveBeenCalledTimes(1)
|
|
30
30
|
})
|
|
31
31
|
|
|
32
|
+
it('leaves focus where it was on a click', async () => {
|
|
33
|
+
const onSearch = vi.fn()
|
|
34
|
+
render(
|
|
35
|
+
<>
|
|
36
|
+
<input aria-label="composer" />
|
|
37
|
+
<TopBar onSearch={onSearch} />
|
|
38
|
+
</>,
|
|
39
|
+
)
|
|
40
|
+
const composer = screen.getByRole('textbox', { name: 'composer' })
|
|
41
|
+
composer.focus()
|
|
42
|
+
await userEvent.click(screen.getByRole('button', { name: /Search…/ }))
|
|
43
|
+
expect(onSearch).toHaveBeenCalledTimes(1)
|
|
44
|
+
expect(document.activeElement).toBe(composer)
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
it('is reached with Tab and pressed with Enter', async () => {
|
|
48
|
+
const onSearch = vi.fn()
|
|
49
|
+
render(<TopBar onSearch={onSearch} />)
|
|
50
|
+
await userEvent.tab()
|
|
51
|
+
expect(document.activeElement).toBe(screen.getByRole('button', { name: /Search…/ }))
|
|
52
|
+
await userEvent.keyboard('{Enter}')
|
|
53
|
+
expect(onSearch).toHaveBeenCalledTimes(1)
|
|
54
|
+
})
|
|
55
|
+
|
|
32
56
|
it('says "Search…" when given no words', () => {
|
|
33
57
|
render(<TopBar onSearch={() => {}} />)
|
|
34
58
|
expect(screen.getByRole('button', { name: /Search…/ })).toBeTruthy()
|
package/src/TopBar.tsx
CHANGED
|
@@ -32,6 +32,11 @@ import { shortcutLabel } from './shortcuts'
|
|
|
32
32
|
* app searches with — and Ctrl+K (Cmd+K on a Mac) presses it from anywhere.
|
|
33
33
|
* Before, every app drew its own field and listened for the keys itself.
|
|
34
34
|
* A `search` of the caller's own still takes the centre.
|
|
35
|
+
*
|
|
36
|
+
* **A click leaves focus where it was**, as Peek's field did: what searching
|
|
37
|
+
* opens often acts on what you were in — Peek's launcher reads the composer
|
|
38
|
+
* you were typing in and its selection — and taking focus would leave it
|
|
39
|
+
* nothing. Tab still reaches the field, and Enter or Space presses it.
|
|
35
40
|
*/
|
|
36
41
|
export interface TopBarProps {
|
|
37
42
|
variant?: 'solid' | 'floating' | 'inset'
|
|
@@ -73,7 +78,7 @@ export function TopBar({ variant = 'solid', menu, logo, search, onSearch, search
|
|
|
73
78
|
const centre =
|
|
74
79
|
search ??
|
|
75
80
|
(onSearch && (
|
|
76
|
-
<BaseButton type="button" onClick={onSearch} className={cn('flex w-[290px] cursor-pointer items-center gap-2 px-3 py-2', FIELD_SHELL_CLASSES)}>
|
|
81
|
+
<BaseButton type="button" onMouseDown={(event) => event.preventDefault()} onClick={onSearch} className={cn('flex w-[290px] cursor-pointer items-center gap-2 px-3 py-2', FIELD_SHELL_CLASSES)}>
|
|
77
82
|
<span className="min-w-0 flex-1 truncate text-left text-input-value text-text-muted">{searchPlaceholder}</span>
|
|
78
83
|
<Kbd>{shortcutLabel('Mod-K')}</Kbd>
|
|
79
84
|
</BaseButton>
|