Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix top navbar style #1719

Merged
merged 4 commits into from
Apr 16, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 2 additions & 76 deletions templates/header/topbar_begin.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
The only piece of context it can take is `search_query`, which should
be a string and will populate the search field if it exists
#}

{%- import "macros.html" as macros -%}

<div class="nav-container">
<div class="container">
<div class="pure-menu pure-menu-horizontal" role="navigation" aria-label="Main navigation">
Expand All @@ -14,82 +11,11 @@
class="landing-search-form-nav {%
if is_latest_version is defined and not is_latest_version %}not-latest{% endif
%} {% if metadata.yanked %}yanked{% endif %}">
{# The search bar #}
<div id="search-input-nav" class="pure-menu-right">
<label for="nav-search">
{{ "search" | fas }}
</label>

{# If there is a search query, put it in the search bar #}
{# The tabindex="-1" is used to prevent it to be the first input focused on the page when using the browser shortcut #}
<input id="nav-search" name="query" type="text" aria-label="Find crate by search query" tabindex="-1"
placeholder="Find crate" {%- if search_query %} value="{{ search_query }}" {%- endif %}>
</div>

{# The top-left logo and name #}
<a href="/" class="pure-menu-heading pure-menu-link" aria-label="Docs.rs">
<a href="/" class="pure-menu-heading pure-menu-link docsrs-logo" aria-label="Docs.rs">
<span title="Docs.rs">{{ "cubes" | fas }}</span>
<span class="title">Docs.rs</span>
</a>{#

#}<ul class="pure-menu-list pure-menu-right">
<li class="pure-menu-item pure-menu-has-children pure-menu-allow-hover pure-menu-opt-children">
<a href="/releases" class="pure-menu-link">
<span title="Releases">{{ "leaf" | fas }}</span>
<span class="title">Releases</span>
</a>

<ul class="pure-menu-children">
{{ macros::menu_link(href="/releases/stars", text="Releases by Stars") }}
{{ macros::menu_link(href="/releases/recent-failures", text="Recent Build Failures") }}
{{ macros::menu_link(href="/releases/failures", text="Build Failures by Stars") }}
{{ macros::menu_link(href="/releases/activity", text="Release Activity") }}
</ul>
</li>{#

The Rust dropdown menu
#}<li class="pure-menu-item pure-menu-has-children pure-menu-allow-hover pure-menu-opt">
<a href="https://www.rust-lang.org/" target="_blank" class="pure-menu-link">
Rust
</a>

<ul class="pure-menu-children">
{{ macros::menu_link(
href="https://doc.rust-lang.org/book/",
text="The Book",
target="_blank"
) }}

{{ macros::menu_link(
href="https://doc.rust-lang.org/std/",
text="Standard Library API Reference",
target="_blank"
) }}

{{ macros::menu_link(
href="https://doc.rust-lang.org/rust-by-example/",
text="Rust by Example",
target="_blank"
) }}

{{ macros::menu_link(
href="https://rust-lang-nursery.github.io/rust-cookbook/",
text="Rust Cookbook",
target="_blank",
extra_classes="menu-item-divided"
) }}

{{ macros::menu_link(
href="https://crates.io",
text="Crates.io",
target="_blank"
) }}

{{ macros::menu_link(
href="http://doc.crates.io/guide.html",
text="The Cargo Guide",
target="_blank"
) }}
</ul>
</li>
</ul>
#}
75 changes: 75 additions & 0 deletions templates/header/topbar_end.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,81 @@
{%- import "macros.html" as macros -%}

<div class="spacer"></div>
{# The global alert, if there is one #}
{% include "header/global_alert.html" -%}

<ul class="pure-menu-list">
<li class="pure-menu-item pure-menu-has-children pure-menu-allow-hover pure-menu-opt-children">
<a href="/releases" class="pure-menu-link">
<span title="Releases">{{ "leaf" | fas }}</span>
<span class="title">Releases</span>
</a>

<ul class="pure-menu-children">
{{ macros::menu_link(href="/releases/stars", text="Releases by Stars") }}
{{ macros::menu_link(href="/releases/recent-failures", text="Recent Build Failures") }}
{{ macros::menu_link(href="/releases/failures", text="Build Failures by Stars") }}
{{ macros::menu_link(href="/releases/activity", text="Release Activity") }}
</ul>
</li>{#

The Rust dropdown menu
#}<li class="pure-menu-item pure-menu-has-children pure-menu-allow-hover pure-menu-opt">
<a href="https://www.rust-lang.org/" target="_blank" class="pure-menu-link">
Rust
</a>

<ul class="pure-menu-children">
{{ macros::menu_link(
href="https://doc.rust-lang.org/book/",
text="The Book",
target="_blank"
) }}

{{ macros::menu_link(
href="https://doc.rust-lang.org/std/",
text="Standard Library API Reference",
target="_blank"
) }}

{{ macros::menu_link(
href="https://doc.rust-lang.org/rust-by-example/",
text="Rust by Example",
target="_blank"
) }}

{{ macros::menu_link(
href="https://rust-lang-nursery.github.io/rust-cookbook/",
text="Rust Cookbook",
target="_blank",
extra_classes="menu-item-divided"
) }}

{{ macros::menu_link(
href="https://crates.io",
text="Crates.io",
target="_blank"
) }}

{{ macros::menu_link(
href="http://doc.crates.io/guide.html",
text="The Cargo Guide",
target="_blank"
) }}
</ul>
</li>
</ul>
{# The search bar #}
<div id="search-input-nav">
<label for="nav-search">
{{ "search" | fas }}
</label>

{# If there is a search query, put it in the search bar #}
{# The tabindex="-1" is used to prevent it to be the first input focused on the page when using the browser shortcut #}
<input id="nav-search" name="query" type="text" aria-label="Find crate by search query" tabindex="-1"
placeholder="Find crate" {%- if search_query %} value="{{ search_query }}" {%- endif %}>
</div>
</form>
</div>
</div>
Expand Down
35 changes: 27 additions & 8 deletions templates/style/_navbar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ div.nav-container {
color: var(--color-navbar-standard);
/* The font size must be specified in pixels because the height is specified in pixels. */
font: 16px $font-family-sans;
position: relative;

.container, .pure-menu-horizontal {
position: relative;
height: 100%;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are the position: relative and height: 100% needed for here? I think they are unnecessary.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's because with this, we can set the element of the navbar to height: 100%. It prevents the bottom margin to disappear in case the font size is too big.

}

li {
border-left: 1px solid var(--color-border);
Expand Down Expand Up @@ -73,18 +79,18 @@ div.nav-container {
}
}

.pure-menu-right {
float: right;
}

form.landing-search-form-nav {
max-width: 1200px;
height: 100%;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can get rid of this height: 100%. That makes the search field vertically misaligned, but you can fix that by also removing the height: 100% on line 92.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without the height: 100%:

Screenshot from 2022-04-13 16-56-07

display: flex;
flex-direction: row;

#search-input-nav {
float: right;
max-width: 150px;
display: none;
border-left: 1px solid var(--color-border);
height: 100%;
overflow-x: hidden;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need overflow-x: hidden here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a trick I used to fix the scrollbar issue when the font-size is too big. I thought flex-shrink: 1 would do it but apparently it doesn't...


@media #{$media-sm} {
display: block;
Expand All @@ -107,7 +113,7 @@ div.nav-container {
font-size: 0.8em;
box-shadow: none;
background-color: var(--color-background);
height: 31px;
height: 100%;
}
}

Expand All @@ -122,8 +128,21 @@ div.nav-container {
See https://github.com/rust-lang/docs.rs/issues/1669.
*/
.pure-menu-item a {
/* 0.5 em is the padding */
max-height: calc(#{$top-navbar-height} - 0.5em * 2);
max-height: 100%;
overflow-x: hidden;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these lines are unnecessary. When I remove these properties locally, the unwanted grey rectangles (which are tiny vertical scrollbars) go away. Also, with these properties removed, even if the menu items' font size is weird, it doesn't interfere with the main page.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fact, I think this whole CSS rule (including the comment about what happens with a locally installed old Fira Sans) should get deleted. Switching to the flex layout seems like it sufficed to fix the issue with overflowing menu titles, even without this rule.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(I just tested in a locally installed Firefox, with the Fira Sans from #1669 (comment), at these commits:

  1. ad8d4fe (i.e. right before Set overflow-y: hidden on navbar #1711)
  2. 0ae5807 (this branch)
  3. 0ae5807 with this CSS rule removed

And I can confirm that at (1) I have the overflow issue. Both (2) and (3) fix the overflow issue, and (3) additionally fixes the scrollbar issue introduced in this branch.

BTW the scrollbar issue seems to be Chrome-only.

Copy link
Member Author

@GuillaumeGomez GuillaumeGomez Apr 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without this change:

Screenshot from 2022-04-13 16-51-54

With this change:

Screenshot from 2022-04-13 16-52-21

So we definitely need it.

text-overflow: ellipsis;
}

.docsrs-logo, .pure-menu-item a {
padding: 8px 1em;
}

.pure-menu-item {
height: 100%;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is also unnecessary.

}

.spacer {
flex-grow: 1;
}
}

Expand Down