Skip to content

Commit 24bf460

Browse files
Fix interaction between search and side bars (#1159)
1 parent 58a4cb3 commit 24bf460

File tree

2 files changed

+56
-43
lines changed

2 files changed

+56
-43
lines changed

src/html_support_files/odoc.css

Lines changed: 55 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -302,17 +302,41 @@ body.odoc {
302302
grid-template-columns: min-content 1fr min-content;
303303
grid-template-areas:
304304
"search-bar nav ."
305-
"toc-local preamble toc-global"
306-
"toc-local content toc-global";
305+
"toc-global preamble toc-local"
306+
"toc-global content toc-local";
307307
column-gap: 4ex;
308308
grid-template-rows: auto auto 1fr;
309309
}
310310

311311
body.odoc:has(> .odoc-search:focus-within) {
312312
grid-template-areas:
313-
"search-bar search-bar nav"
314-
"toc-local preamble toc-global"
315-
"toc-local content toc-global";
313+
"search-bar search-bar search-bar"
314+
". nav ."
315+
"toc-global preamble toc-local"
316+
"toc-global content toc-local";
317+
}
318+
319+
body.odoc:not(:has(> .odoc-tocs .odoc-global-toc)) {
320+
grid-template-areas:
321+
"search-bar search-bar"
322+
"nav ."
323+
"preamble toc-local"
324+
"content toc-local";
325+
grid-template-columns: 1fr min-content;
326+
}
327+
328+
/* When there is no global sidebar */
329+
body.odoc:not(:has(> .odoc-tocs .odoc-global-toc)) nav.odoc-nav {
330+
padding-top: 0;
331+
}
332+
333+
/* When there is no global sidebbar and the searchbar is focused */
334+
body.odoc:not(:has(> .odoc-tocs .odoc-global-toc)) nav.odoc-nav:has(+ .odoc-search:focus-within) {
335+
padding-top: var(--search-padding-top);
336+
}
337+
338+
nav.odoc-nav:has(+ .odoc-search:focus-within) {
339+
padding-top: 0;
316340
}
317341

318342
body.odoc-src {
@@ -842,7 +866,7 @@ td.def-doc *:first-child {
842866
/* When a search bar is present, we need the sticky sidebar to be a bit lower,
843867
so `top` is higher */
844868

845-
.odoc-search + * + .odoc-tocs .odoc-toc {
869+
body.odoc:has( .odoc-search) .odoc-toc {
846870
--toc-top: calc(var(--search-bar-height) + 2 * var(--search-padding-top));
847871
max-height: calc(100vh - 2 * var(--toc-top));
848872
top: var(--toc-top)
@@ -1228,42 +1252,33 @@ td.def-doc *:first-child {
12281252
body.odoc {
12291253
max-width: 132ex;
12301254
grid-template-areas:
1231-
"search-bar nav"
1232-
"sidebar preamble"
1233-
"sidebar content";
1234-
}
1235-
1236-
body.odoc:has(> .odoc-search:focus-within) {
1237-
grid-template-areas:
1238-
"nav nav"
1239-
"search-bar search-bar"
1240-
"sidebar preamble"
1241-
"sidebar content";
1255+
"search-bar nav"
1256+
"sidebar preamble"
1257+
"sidebar content";
12421258
}
1243-
1244-
nav.odoc-nav:has(+ .odoc-search:focus-within) {
1245-
padding-bottom: 0;
1246-
}
1247-
1248-
.odoc-tocs {
1259+
body.odoc .odoc-tocs {
12491260
display: flex;
12501261
grid-area: sidebar;
12511262
flex-direction : column;
12521263
gap: 20px;
12531264
}
1254-
.odoc-toc {
1255-
position: unset;
1256-
max-height: unset;
1265+
body.odoc .odoc-tocs .odoc-toc {
1266+
position: unset;
1267+
max-height: unset;
1268+
}
1269+
body.odoc:has(.odoc-search:focus-within) {
1270+
grid-template-areas:
1271+
"search-bar search-bar"
1272+
". nav"
1273+
"sidebar preamble"
1274+
"sidebar content";
12571275
}
12581276
}
12591277

12601278
@media only screen and (max-width: 110ex) {
1261-
body {
1279+
body.odoc {
12621280
margin: 2em;
12631281
padding: 0;
1264-
}
1265-
1266-
body.odoc {
12671282
grid-template-areas:
12681283
"search-bar"
12691284
"nav"
@@ -1273,10 +1288,9 @@ td.def-doc *:first-child {
12731288
"toc-global";
12741289
grid-template-columns: 1fr;
12751290
}
1276-
12771291
body.odoc:has(> .odoc-search:focus-within) {
12781292
/* This is the same as when there is no focus on the search bar, this is
1279-
just to prevent the full screen rule from changing anything. */
1293+
just to prevent the default "wide layout" rule from changing anything. */
12801294
grid-template-areas:
12811295
"search-bar"
12821296
"nav"
@@ -1286,19 +1300,18 @@ td.def-doc *:first-child {
12861300
"toc-global";
12871301
grid-template-columns: 1fr;
12881302
}
1289-
1290-
1291-
.odoc-search {
1303+
body.odoc .odoc-search {
12921304
position: relative;
1293-
padding-bottom: 0;
1294-
height: calc(var(--search-bar-height) + var(--search-padding-top));
1305+
height: calc(var(--search-bar-height) + 2 * var(--search-padding-top));
12951306
}
1296-
1297-
.odoc-tocs {
1298-
display: contents;
1307+
body.odoc nav.odoc-nav {
1308+
padding-top: 0;
1309+
padding-bottom: var(--search-padding-top);
12991310
}
1300-
1301-
.odoc-toc {
1311+
body.odoc .odoc-tocs {
1312+
display: contents;
1313+
}
1314+
body.odoc .odoc-tocs .odoc-toc {
13021315
position: static;
13031316
width: auto;
13041317
min-width: unset;

test/parent_id/sidebar.t/run.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,4 @@
5656
</ul>
5757

5858
$ odoc support-files -o html
59-
$ cp -r html /tmp/html
59+
$ cp -r html /tmp/html

0 commit comments

Comments
 (0)