Skip to content

Commit d739e01

Browse files
committed
feat(search): choose which topics the results come from
Chips in the Cmd-K dialog and on /search/ — Answers, Guides & articles, API reference and the other edition — each an independent on/off switch, every one on by default. The dialog showed all four groups and let a reader say nothing about it; /search/ offered tabs, which let them pick exactly one group or exactly everything. Neither answers "the guides and the answers, not the generated API reference", which on a symbol-shaped query is the case that matters: the API reference outnumbers the other two together. The ranker half is the search-ranker submodule, bumped here. This commit is the markup and the styles. Being ON is the quiet state. Every chip starts on, and four solid accent blocks above the results would read as a banner rather than a control, so the fill is a 12% tint and switching one OFF is what stands out as a change the reader made. A leading glyph carries the state as well as the colour — both are one character wide in the mono face, so a toggle never reflows the row, and "+" is the honest label for an off chip, which is a topic you can add back rather than one that found nothing. At 375px the four labels wrap to three lines. Tightened rather than put in a horizontal scroller, which would hide chips off the edge of exactly the screen where the API reference most needs switching off.
1 parent afc8ad0 commit d739e01

3 files changed

Lines changed: 81 additions & 20 deletions

File tree

src/_shared/css/search.css

Lines changed: 73 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,68 @@
120120

121121
.s-close:hover { color: var(--ink); border-color: var(--accent); }
122122

123+
/* ---- the topic chips --------------------------------------------------- */
124+
125+
/* One row of on/off switches per surface: here between the field and the list, and on
126+
/search/ under the form. `flex: none` matters — .s-form is a column flex box whose
127+
.s-results takes the slack, and without it a wrapped row of chips on a narrow screen
128+
is compressed instead of being given its two lines. */
129+
.s-topics {
130+
display: flex;
131+
flex-wrap: wrap;
132+
gap: 8px;
133+
padding: 12px 18px;
134+
border-bottom: 1px solid var(--line);
135+
flex: none;
136+
}
137+
138+
/* `hidden` is set on the row until a query has something to filter, and `display: flex`
139+
above would otherwise win against the UA's `display: none`. */
140+
.s-topics[hidden] { display: none; }
141+
142+
.s-topic {
143+
display: inline-flex;
144+
align-items: center;
145+
gap: 7px;
146+
border: 1px solid var(--line);
147+
border-radius: 999px;
148+
padding: 5px 13px;
149+
background: none;
150+
font-family: var(--font-mono);
151+
font-size: 13px;
152+
line-height: 1.5;
153+
color: var(--muted);
154+
cursor: pointer;
155+
}
156+
157+
/* A leading glyph, not colour alone. Which topics are showing is information, and a tint
158+
plus a border tint is a thin thing to hang it on for anyone who cannot separate the two.
159+
Both glyphs are one character wide in the mono face, so toggling a chip never reflows
160+
the row — and "+" is the honest label for an off chip, which is a topic you can add back
161+
rather than one that found nothing. */
162+
.s-topic::before { content: "+"; opacity: .75; }
163+
.s-topic[aria-pressed="true"]::before { content: "✓"; opacity: 1; }
164+
165+
/* Being ON is the quiet state. Every chip starts on, and four solid accent blocks above
166+
the results would be a banner rather than a control; switching one OFF is the change the
167+
reader made, so that is what has to be legible at a glance. */
168+
.s-topic[aria-pressed="true"] {
169+
color: var(--ink);
170+
border-color: color-mix(in srgb, var(--accent) 55%, var(--line));
171+
background: color-mix(in srgb, var(--accent) 12%, transparent);
172+
}
173+
174+
.s-topic:hover { color: var(--ink); border-color: var(--accent); }
175+
.s-topic:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
176+
177+
/* Tabular figures so a count changing width — 9 to 10 — does not shuffle the chips beside
178+
it, which happens on every peer index that lands after the first render. */
179+
.s-topic__count {
180+
font-size: 12px;
181+
opacity: .7;
182+
font-variant-numeric: tabular-nums;
183+
}
184+
123185
.s-results {
124186
flex: 1 1 auto;
125187
min-height: 0;
@@ -349,30 +411,16 @@
349411
cursor: pointer;
350412
}
351413

352-
.s-page__tabs {
414+
/* The same chips as the dialog's — see `.s-topic` above — in the page's own row, which
415+
sits in the document rather than in a panel and so needs margin instead of the dialog's
416+
padding and rule. */
417+
.s-page__topics {
353418
display: flex;
354419
flex-wrap: wrap;
355420
gap: 8px;
356421
margin-bottom: 18px;
357422
}
358423

359-
.s-tab {
360-
border: 1px solid var(--line);
361-
border-radius: 999px;
362-
padding: 5px 13px;
363-
font-family: var(--font-mono);
364-
font-size: 13px;
365-
color: var(--muted);
366-
border-bottom: 1px solid var(--line);
367-
}
368-
369-
.s-tab:hover { color: var(--ink); border-color: var(--accent); }
370-
.s-tab.is-active {
371-
color: var(--on-accent);
372-
background: var(--accent);
373-
border-color: transparent;
374-
}
375-
376424
.s-page .s-page__status {
377425
padding: 0 0 14px;
378426
border-top: 0;
@@ -448,6 +496,13 @@
448496
results instead. It is still shown before anything is typed. */
449497
.s-results:not(:empty) ~ .s-hint { display: none; }
450498

499+
/* Tightened, not scrolled sideways. At 375px the four labels wrap to three lines and
500+
that row is the only place the filter exists — putting it in a horizontal scroller
501+
would hide chips off the edge of exactly the screen where the API reference most needs
502+
switching off. This buys back about 20px of result list instead. */
503+
.s-topics { padding: 9px 12px; gap: 6px; }
504+
.s-topic { padding: 4px 10px; font-size: 12.5px; gap: 6px; }
505+
451506
.s-page__form { flex-wrap: wrap; }
452507
.s-page__submit { width: 100%; padding: 12px 20px; }
453508
}

src/search.html

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,13 @@ <h1 style="font-family:var(--font-display);font-size:40px;line-height:1.1;letter
5252
<button class="s-page__submit" type="submit">Search</button>
5353
</form>
5454

55-
<div class="s-page__tabs"></div>
55+
{%- comment -%}
56+
Filled by the ranker with one on/off chip per topic — Answers, Guides & articles, API
57+
reference, and the other edition. `role="group"` rather than a list: the chips are a
58+
set of independent switches with one purpose between them, and the label is what makes
59+
a bare row of buttons mean "these filter the results below".
60+
{%- endcomment %}
61+
<div class="s-page__topics" role="group" aria-label="Show results from these topics"></div>
5662
<p class="s-page__status" role="status" aria-live="polite"></p>
5763
<div class="s-page__results"></div>
5864

vendor/search-ranker

0 commit comments

Comments
 (0)