Skip to content

Commit 521f727

Browse files
committed
Fixed navigation outlines on focus
1 parent 9dd7511 commit 521f727

File tree

8 files changed

+113
-83
lines changed

8 files changed

+113
-83
lines changed

material/templates/assets/stylesheets/main.821ccc56.min.css

Lines changed: 0 additions & 1 deletion
This file was deleted.

material/templates/assets/stylesheets/main.821ccc56.min.css.map

Lines changed: 0 additions & 1 deletion
This file was deleted.

material/templates/assets/stylesheets/main.82baac91.min.css

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

material/templates/assets/stylesheets/main.82baac91.min.css.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

material/templates/base.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
{% endif %}
4545
{% endblock %}
4646
{% block styles %}
47-
<link rel="stylesheet" href="{{ 'assets/stylesheets/main.821ccc56.min.css' | url }}">
47+
<link rel="stylesheet" href="{{ 'assets/stylesheets/main.82baac91.min.css' | url }}">
4848
{% if config.theme.palette %}
4949
{% set palette = config.theme.palette %}
5050
<link rel="stylesheet" href="{{ 'assets/stylesheets/palette.a5377069.min.css' | url }}">

material/templates/partials/nav-item.html

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,25 +48,26 @@
4848
{% endif %}
4949
{% endfor %}
5050
{% endif %}
51-
{% if "navigation.sections" in features and level == 1 + (
52-
"navigation.tabs" in features
53-
) %}
51+
{% set tabs = "navigation.tabs" in features %}
52+
{% set sections = "navigation.sections" in features %}
53+
{% if tabs and level == 1 or sections and tabs >= level - 1 %}
5454
{% set class = class ~ " md-nav__item--section" %}
55+
{% set is_section = true %}
5556
{% elif not nav_item.active and "navigation.prune" in features %}
5657
{% set class = class ~ " md-nav__item--pruned" %}
57-
{% set prune = true %}
58+
{% set is_pruned = true %}
5859
{% endif %}
5960
<li class="{{ class }} md-nav__item--nested">
60-
{% if not prune %}
61-
{% set expanded = "navigation.expand" in features %}
62-
{% set active = nav_item.active or expanded %}
61+
{% if not is_pruned %}
6362
{% set checked = "checked" if nav_item.active %}
64-
{% if expanded and not checked %}
63+
{% set is_expanded = "navigation.expand" in features %}
64+
{% if is_expanded and not checked %}
6565
{% set indeterminate = "md-toggle--indeterminate" %}
6666
{% endif %}
6767
<input class="md-nav__toggle md-toggle {{ indeterminate }}" type="checkbox" id="{{ path }}" {{ checked }}>
6868
{% if not indexes %}
69-
<label class="md-nav__link" for="{{ path }}" id="{{ path }}_label" tabindex="0">
69+
{% set tabindex = "0" if not is_section %}
70+
<label class="md-nav__link" for="{{ path }}" id="{{ path }}_label" tabindex="{{ tabindex }}">
7071
{{ render_content(nav_item) }}
7172
<span class="md-nav__icon md-icon"></span>
7273
</label>
@@ -78,7 +79,8 @@
7879
{{ render_content(index, nav_item) }}
7980
</a>
8081
{% if nav_item.children | length > 1 %}
81-
<label class="md-nav__link {{ class }}" for="{{ path }}" id="{{ path }}_label" tabindex="0">
82+
{% set tabindex = "0" if not is_section %}
83+
<label class="md-nav__link {{ class }}" for="{{ path }}" id="{{ path }}_label" tabindex="{{ tabindex }}">
8284
<span class="md-nav__icon md-icon"></span>
8385
</label>
8486
{% endif %}

src/templates/assets/stylesheets/main/components/_nav.scss

Lines changed: 85 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -80,16 +80,6 @@
8080
list-style: none;
8181
}
8282

83-
// Navigation item
84-
&__item {
85-
padding: 0 px2rem(12px);
86-
87-
// Navigation item on level 2
88-
& & {
89-
padding-inline-end: 0;
90-
}
91-
}
92-
9383
// Navigation link
9484
&__link {
9585
display: flex;
@@ -122,9 +112,9 @@
122112
position: relative;
123113
}
124114

125-
// Always align navigation icons to the right
115+
// Always align navigation icons to the end
126116
.md-icon:last-child {
127-
margin-left: auto;
117+
margin-inline-start: auto;
128118
}
129119

130120
// Navigation link icon
@@ -289,7 +279,6 @@
289279

290280
// Navigation item
291281
.md-nav__item {
292-
padding: 0;
293282
border-top: px2rem(1px) solid var(--md-default-fg-color--lightest);
294283

295284
// Navigation link in active navigation
@@ -474,51 +463,89 @@
474463

475464
// [tablet landscape +]: Tree-like table of contents
476465
@include break-from-device(tablet landscape) {
466+
margin-bottom: px2rem(-8px);
477467

478-
// Navigation title
479-
&--secondary &__title {
480-
position: sticky;
481-
top: 0;
482-
// Hack: because of the hack that we need to make .md-ellipsis work in
483-
// Safari, we need to set `z-index` here as - see https://bit.ly/3s5M2jm
484-
z-index: 1;
485-
background: var(--md-default-bg-color);
486-
box-shadow: 0 0 px2rem(8px) px2rem(8px) var(--md-default-bg-color);
468+
// Table of contents
469+
&--secondary {
470+
471+
// Navigation title
472+
.md-nav__title {
473+
position: sticky;
474+
top: 0;
475+
// Hack: because of the hack that we need to make .md-ellipsis work in
476+
// Safari, we need to set `z-index` here as - see https://bit.ly/3s5M2jm
477+
z-index: 1;
478+
background: var(--md-default-bg-color);
479+
box-shadow: 0 0 px2rem(8px) px2rem(8px) var(--md-default-bg-color);
480+
481+
// Adjust snapping behavior
482+
&[for="__toc"] {
483+
scroll-snap-align: start;
484+
}
487485

488-
// Adjust snapping behavior
489-
&[for="__toc"] {
490-
scroll-snap-align: start;
486+
// Hide navigation icon
487+
.md-nav__icon {
488+
display: none;
489+
}
491490
}
492491

493-
// Hide navigation icon
494-
.md-nav__icon {
495-
display: none;
492+
// Adjust spacing for navigation list - same reason as below
493+
.md-nav__list {
494+
padding-inline-start: px2rem(12px);
495+
padding-bottom: px2rem(8px);
496+
}
497+
498+
// Adjust spacing for navigation link - before this change, we set spacing
499+
// on the left and right of a navigation item, but this led to the problem
500+
// of cropped focus outlines, because we must set `overflow: hidden` on
501+
// the navigation list for smooth expand and collapse transitions.
502+
.md-nav__item > .md-nav__link {
503+
margin-inline-end: px2rem(8px);
496504
}
497505
}
498506
}
499507

500508
// [screen +]: Tree-like navigation
501509
@include break-from-device(screen) {
510+
margin-bottom: px2rem(-8px);
502511
transition: max-height 250ms cubic-bezier(0.86, 0, 0.07, 1);
503512

504-
// Navigation title
505-
&--primary &__title {
506-
position: sticky;
507-
top: 0;
508-
// Hack: because of the hack that we need to make .md-ellipsis work in
509-
// Safari, we need to set `z-index` here as - see https://bit.ly/3s5M2jm
510-
z-index: 1;
511-
background: var(--md-default-bg-color);
512-
box-shadow: 0 0 px2rem(8px) px2rem(8px) var(--md-default-bg-color);
513+
// Primary navigation
514+
&--primary {
513515

514-
// Adjust snapping behavior
515-
&[for="__drawer"] {
516-
scroll-snap-align: start;
516+
// Navigation title
517+
.md-nav__title {
518+
position: sticky;
519+
top: 0;
520+
// Hack: because of the hack that we need to make .md-ellipsis work in
521+
// Safari, we need to set `z-index` here as - see https://bit.ly/3s5M2jm
522+
z-index: 1;
523+
background: var(--md-default-bg-color);
524+
box-shadow: 0 0 px2rem(8px) px2rem(8px) var(--md-default-bg-color);
525+
526+
// Adjust snapping behavior
527+
&[for="__drawer"] {
528+
scroll-snap-align: start;
529+
}
530+
531+
// Hide navigation icon
532+
.md-nav__icon {
533+
display: none;
534+
}
517535
}
518536

519-
// Hide navigation icon
520-
.md-nav__icon {
521-
display: none;
537+
// Adjust spacing for navigation list - same reason as below
538+
.md-nav__list {
539+
padding-inline-start: px2rem(12px);
540+
padding-bottom: px2rem(8px);
541+
}
542+
543+
// Adjust spacing for navigation link - before this change, we set spacing
544+
// on the left and right of a navigation item, but this led to the problem
545+
// of cropped focus outlines, because we must set `overflow: hidden` on
546+
// the navigation list for smooth expand and collapse transitions.
547+
.md-nav__item > .md-nav__link {
548+
margin-inline-end: px2rem(8px);
522549
}
523550
}
524551

@@ -588,6 +615,7 @@
588615
// Navigation
589616
> .md-nav {
590617
display: block;
618+
margin-inline-start: px2rem(-12px);
591619
visibility: visible;
592620
opacity: 1;
593621

@@ -641,8 +669,7 @@
641669
// Modifier for when navigation tabs are rendered
642670
&--lifted {
643671

644-
// Hide nested level 0 navigation items and site title
645-
> .md-nav__list > .md-nav__item--nested,
672+
// Hide site title
646673
> .md-nav__title {
647674
display: none;
648675
}
@@ -654,46 +681,45 @@
654681
// Active parent navigation item
655682
&--active {
656683
display: block;
657-
padding: 0;
658684

659685
// Show navigation link as title
660686
> .md-nav__link {
661687
position: sticky;
662688
top: 0;
663689
z-index: 1;
664-
padding: 0 px2rem(12px);
665690
margin-top: 0;
666-
font-weight: 700;
667691
background: var(--md-default-bg-color);
668692
box-shadow: 0 0 px2rem(8px) px2rem(8px) var(--md-default-bg-color);
669693

670694
// Omit clicks if not a section index page
671695
&:not(.md-nav__container) {
672696
pointer-events: none;
673697
}
698+
}
674699

675-
// Hide naviation icon
676-
.md-nav__icon {
677-
display: none;
678-
}
700+
// Adjust spacing for navigation section
701+
&.md-nav__item--section {
702+
margin: 0;
679703
}
680704
}
681705

706+
// Adjust spacing for nested navigation
707+
> .md-nav {
708+
margin-inline-start: px2rem(-12px);
709+
}
710+
682711
// Make labels discernable from links
683712
> [for] {
684713
color: var(--md-default-fg-color--light);
685714
}
686715
}
687716

688717
// Hack: Always show active navigation tab on breakpoint screen, despite
689-
// of checkbox being checked or not. Fixes #1655.
718+
// of checkbox being checked or not - see https://t.ly/Qc311
690719
.md-nav[data-md-level="1"] {
691-
display: block;
692-
693-
// Adjust spacing for level 1 navigation items
694-
> .md-nav__list > .md-nav__item {
695-
padding-inline-end: px2rem(12px);
696-
}
720+
grid-template-rows: 1fr;
721+
visibility: visible;
722+
opacity: 1;
697723
}
698724
}
699725

src/templates/partials/nav-item.html

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -101,26 +101,26 @@
101101
{% endif %}
102102

103103
<!-- Determine whether to render item as a section -->
104-
{% if "navigation.sections" in features and level == 1 + (
105-
"navigation.tabs" in features
106-
) %}
104+
{% set tabs = "navigation.tabs" in features %}
105+
{% set sections = "navigation.sections" in features %}
106+
{% if tabs and level == 1 or sections and tabs >= level - 1 %}
107107
{% set class = class ~ " md-nav__item--section" %}
108+
{% set is_section = true %}
108109

109110
<!-- Determine whether to prune inactive item -->
110111
{% elif not nav_item.active and "navigation.prune" in features %}
111112
{% set class = class ~ " md-nav__item--pruned" %}
112-
{% set prune = true %}
113+
{% set is_pruned = true %}
113114
{% endif %}
114115

115116
<!-- Nested navigation item -->
116117
<li class="{{ class }} md-nav__item--nested">
117-
{% if not prune %}
118-
{% set expanded = "navigation.expand" in features %}
119-
{% set active = nav_item.active or expanded %}
118+
{% if not is_pruned %}
119+
{% set checked = "checked" if nav_item.active %}
120120

121121
<!-- Determine checked and indeterminate state -->
122-
{% set checked = "checked" if nav_item.active %}
123-
{% if expanded and not checked %}
122+
{% set is_expanded = "navigation.expand" in features %}
123+
{% if is_expanded and not checked %}
124124
{% set indeterminate = "md-toggle--indeterminate" %}
125125
{% endif %}
126126

@@ -134,11 +134,12 @@
134134

135135
<!-- Toggle to expand nested items -->
136136
{% if not indexes %}
137+
{% set tabindex = "0" if not is_section %}
137138
<label
138139
class="md-nav__link"
139140
for="{{ path }}"
140141
id="{{ path }}_label"
141-
tabindex="0"
142+
tabindex="{{ tabindex }}"
142143
>
143144
{{ render_content(nav_item) }}
144145
<span class="md-nav__icon md-icon"></span>
@@ -158,11 +159,12 @@
158159

159160
<!-- Only render toggle if there's at least one more page -->
160161
{% if nav_item.children | length > 1 %}
162+
{% set tabindex = "0" if not is_section %}
161163
<label
162164
class="md-nav__link {{ class }}"
163165
for="{{ path }}"
164166
id="{{ path }}_label"
165-
tabindex="0"
167+
tabindex="{{ tabindex }}"
166168
>
167169
<span class="md-nav__icon md-icon"></span>
168170
</label>

0 commit comments

Comments
 (0)