Skip to content

Commit 2712586

Browse files
authored
Tweak search box (#686)
* make esc button more prominent/separate * tweaks * fix hovers
1 parent b00f797 commit 2712586

File tree

2 files changed

+108
-64
lines changed

2 files changed

+108
-64
lines changed

packages/site-kit/src/lib/search/SearchBox.svelte

Lines changed: 107 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -159,31 +159,37 @@ It appears when the user clicks on the `Search` component or presses the corresp
159159
use:trap
160160
>
161161
<div class="search-box">
162-
<div style="background: var(--background); padding: 0.5rem">
163-
<input
164-
use:forcefocus
165-
onkeydown={(e) => {
162+
<div class="controls">
163+
<div class="input-group">
164+
<input
165+
use:forcefocus
166+
onkeydown={(e) => {
166167
if (e.key === 'Enter' && !e.isComposing) {
167168
const element = modal.querySelector('a[data-has-node]') as HTMLElement | undefined;
168169
element?.click();
169170
}
170171
}}
171-
oninput={(e) => {
172-
$search_query = e.currentTarget.value;
173-
}}
174-
value={$search_query}
175-
{placeholder}
176-
aria-describedby="search-description"
177-
aria-label={placeholder}
178-
spellcheck="false"
179-
/>
172+
oninput={(e) => {
173+
$search_query = e.currentTarget.value;
174+
}}
175+
value={$search_query}
176+
{placeholder}
177+
aria-describedby="search-description"
178+
aria-label={placeholder}
179+
spellcheck="false"
180+
/>
181+
182+
<button aria-label="Clear" onclick={() => ($search_query = '')}>
183+
<Icon name="close" />
184+
</button>
185+
</div>
186+
187+
<button class="raised" aria-label="Close" onclick={close}>
188+
<!-- <Icon name="close" /> -->
189+
<kbd>Esc</kbd>
190+
</button>
180191
</div>
181192

182-
<button aria-label="Close" onclick={close}>
183-
<!-- <Icon name="close" /> -->
184-
<kbd>Esc</kbd>
185-
</button>
186-
187193
<span id="search-description" class="visually-hidden">
188194
{#if search_description}
189195
{@render search_description()}
@@ -222,14 +228,15 @@ It appears when the user clicks on the `Search` component or presses the corresp
222228
</a>
223229

224230
<button
231+
class="raised icon"
225232
aria-label="Delete"
226233
onclick={(e) => {
227234
$search_recent = $search_recent.filter((href) => href !== search.href);
228235
e.stopPropagation();
229236
e.preventDefault();
230237
}}
231238
>
232-
<Icon name="delete" />
239+
<Icon name="delete" size={16} />
233240
</button>
234241
</li>
235242
{/each}
@@ -302,50 +309,85 @@ It appears when the user clicks on the `Search` component or presses the corresp
302309
}
303310
}
304311
305-
input {
306-
font: var(--sk-font-ui-large);
307-
width: 100%;
308-
padding: calc(var(--padding) - 0.5rem) 5rem calc(var(--padding) - 0.5rem) var(--padding);
309-
height: 6rem;
310-
border: none;
311-
border-bottom: 1px solid var(--sk-back-3);
312-
flex-shrink: 0;
313-
background: var(--sk-back-3);
314-
color: var(--sk-text-1);
315-
316-
&::selection {
317-
background-color: var(--sk-back-translucent);
318-
}
312+
.controls {
313+
background: var(--background);
314+
padding: 0.5rem;
315+
display: flex;
316+
gap: 1rem;
317+
}
319318
320-
&::placeholder {
321-
color: var(--sk-text-2);
322-
opacity: 0.3;
319+
.input-group {
320+
position: relative;
321+
flex: 1;
322+
323+
input {
324+
font: var(--sk-font-ui-large);
325+
width: 100%;
326+
padding: var(--padding) 6rem var(--padding) calc(var(--padding) - 0.5rem);
327+
height: 6rem;
328+
border: none;
329+
flex-shrink: 0;
330+
color: var(--sk-text-1);
331+
border-bottom: 1px solid var(--sk-back-6);
332+
background: inherit;
333+
334+
&::selection {
335+
background-color: var(--sk-back-translucent);
336+
}
337+
338+
&::placeholder {
339+
color: var(--sk-text-2);
340+
opacity: 0.3;
341+
}
342+
343+
&:focus-visible {
344+
outline-offset: -2px;
345+
}
323346
}
324347
325-
&:focus-visible {
326-
outline-offset: -3px;
348+
button {
349+
position: absolute;
350+
right: 0;
351+
top: 0;
352+
height: 100%;
353+
aspect-ratio: 1;
354+
color: var(--sk-text-4);
355+
356+
&:hover,
357+
&:focus {
358+
color: var(--sk-text-3);
359+
}
360+
361+
&:focus-visible {
362+
outline-offset: -2px;
363+
}
327364
}
328365
}
329366
330367
button[aria-label='Close'] {
331-
--size: 2rem;
332-
position: absolute;
333-
top: 0.5rem;
334-
right: 0;
335-
width: 5rem;
336-
height: 6rem;
368+
height: 100%;
369+
aspect-ratio: 1;
337370
background: none;
338-
color: var(--sk-text-2);
339-
opacity: 0.3;
371+
372+
&:hover,
373+
&:focus {
374+
color: var(--sk-text-3);
375+
}
340376
341377
&:focus-visible {
342-
opacity: 1;
343-
outline-offset: -3px;
378+
outline-offset: -2px;
344379
}
345380
346381
kbd {
382+
display: flex;
383+
align-items: center;
384+
justify-content: center;
347385
text-transform: uppercase;
348-
font: var(--sk-font-ui-small);
386+
background: none;
387+
font: var(--sk-font-ui-medium);
388+
color: var(--sk-text-4);
389+
width: 100%;
390+
height: 100%;
349391
}
350392
}
351393
@@ -365,38 +407,40 @@ It appears when the user clicks on the `Search` component or presses the corresp
365407
366408
li {
367409
position: relative;
410+
display: flex;
411+
padding: 0.2rem var(--padding);
412+
gap: 1rem;
413+
414+
&:hover {
415+
background: var(--sk-back-3);
416+
}
368417
369418
a {
370419
color: var(--sk-text-2);
371420
display: block;
372421
text-decoration: none;
373-
padding: 0.5rem calc(4rem + var(--padding)) 0.5rem var(--padding);
374-
375-
&:hover {
376-
background: rgba(0, 0, 0, 0.05);
377-
}
422+
margin: 0 -0.5rem;
423+
padding: 0.5rem;
424+
flex: 1;
378425
379426
&:focus {
380427
outline-offset: -3px;
381428
}
382429
}
383430
384431
button[aria-label='Delete'] {
385-
position: absolute;
386-
top: 0;
387-
right: 0;
388-
width: 5rem;
389-
height: 100%;
390-
color: var(--sk-text-2);
391-
opacity: 0.1;
432+
width: 3.2rem;
433+
height: 3.2rem;
434+
color: var(--sk-text-4);
435+
background-color: var(--sk-back-2);
392436
393437
&:hover {
394-
opacity: 1;
395438
outline: none;
439+
color: var(--sk-text-3);
396440
}
397441
398442
&:focus-visible {
399-
opacity: 1;
443+
color: var(--sk-text-3);
400444
outline-offset: -3px;
401445
}
402446
}

packages/site-kit/src/lib/search/SearchResultList.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@
149149
}
150150
151151
&:hover {
152-
--background: var(--sk-back-4);
152+
--background: var(--sk-back-3);
153153
text-decoration: none;
154154
}
155155

0 commit comments

Comments
 (0)