Skip to content

Commit c05a07e

Browse files
authored
fix(material): Focus indicators are now positioned (angular#19345)
Position all focus indicator host elements & quick fix date picker focus indicator bug.
1 parent bfaa272 commit c05a07e

File tree

9 files changed

+45
-17
lines changed

9 files changed

+45
-17
lines changed

src/material-experimental/mdc-button/_button-base.scss

+5
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@
4040
.mdc-button__label {
4141
z-index: 1;
4242
}
43+
44+
// The focus indicator should match the bounds of the entire button.
45+
.mat-mdc-focus-indicator {
46+
@include mat-fill();
47+
}
4348
}
4449

4550
// MDC's disabled buttons define a default cursor with pointer-events none. However, they select

src/material-experimental/mdc-helpers/_focus-indicators.scss

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
@import '../../material/core/style/layout-common';
33
@import '../../material/core/focus-indicators/focus-indicators';
44

5-
65
/// Mixin that turns on strong focus indicators.
76
///
87
/// @example

src/material/core/_core.scss

+18
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
// Core styles that can be used to apply material design treatments to any element.
66
@import './style/elevation';
77
@import './ripple/ripple';
8+
@import './focus-indicators/focus-indicators';
89
@import './option/option-theme';
910
@import './option/optgroup-theme';
1011
@import './selection/pseudo-checkbox/pseudo-checkbox-theme';
@@ -17,6 +18,9 @@
1718
@include cdk-a11y();
1819
@include cdk-overlay();
1920
@include cdk-text-field();
21+
22+
@include _mat-strong-focus-indicators-positioning();
23+
@include _mat-mdc-core();
2024
}
2125

2226
@mixin mat-core-color($config-or-theme) {
@@ -67,3 +71,17 @@
6771
}
6872
}
6973
}
74+
75+
// Mixin that renders all of the core MDC styles. Private mixin included with `mat-core`.
76+
@mixin _mat-mdc-core() {
77+
@include _mat-mdc-strong-focus-indicators-positioning();
78+
}
79+
80+
// Mixin that ensures focus indicator host elements are positioned so that the focus indicator
81+
// pseudo element within is positioned relative to the host. Private mixin included within
82+
// `_mat-mdc-core`.
83+
@mixin _mat-mdc-strong-focus-indicators-positioning() {
84+
.mat-mdc-focus-indicator {
85+
position: relative;
86+
}
87+
}

src/material/core/focus-indicators/_focus-indicators.scss

+14-7
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,11 @@
4545
margin: -($border-width + 2px);
4646
}
4747

48-
.mat-focus-indicator.mat-stroked-button::before {
48+
.mat-focus-indicator.mat-stroked-button::before,
49+
.mat-focus-indicator.mat-calendar-body-cell-content::before {
4950
margin: -($border-width + 3px);
5051
}
5152

52-
.mat-focus-indicator.mat-calendar-body-cell::before {
53-
margin: -$border-width;
54-
}
55-
5653
.mat-focus-indicator.mat-tab-link::before,
5754
.mat-focus-indicator.mat-tab-label::before {
5855
margin: 5px;
@@ -71,8 +68,9 @@
7168
// is present.
7269
.mat-focus-indicator.mat-option.mat-active::before,
7370

74-
// The focus indicator in the calendar is placed on an element inside the cell.
75-
.mat-calendar-body-active .mat-focus-indicator::before,
71+
// For calendar cells, render the focus indicator when the parent cell is
72+
// focused.
73+
.mat-calendar-body-cell:focus .mat-focus-indicator::before,
7674

7775
// For all other components, render the focus indicator on focus.
7876
.mat-focus-indicator:focus::before {
@@ -122,3 +120,12 @@
122120
}
123121
}
124122
}
123+
124+
// Mixin that ensures focus indicator host elements are positioned so that the focus indicator
125+
// pseudo element within is positioned relative to the host. Private mixin included within
126+
// `mat-core`.
127+
@mixin _mat-strong-focus-indicators-positioning() {
128+
.mat-focus-indicator {
129+
position: relative;
130+
}
131+
}

src/material/datepicker/calendar-body.scss

+6-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,6 @@ $mat-calendar-range-end-body-cell-size:
153153
}
154154

155155
.mat-calendar-body-cell-content {
156-
position: absolute;
157156
top: $mat-calendar-body-cell-content-margin;
158157
left: $mat-calendar-body-cell-content-margin;
159158
z-index: 1;
@@ -175,6 +174,12 @@ $mat-calendar-range-end-body-cell-size:
175174
// Choosing a value clearly larger than the height ensures we get the correct capsule shape.
176175
border-radius: $mat-calendar-body-cell-radius;
177176

177+
// Increase specificity because focus indicator styles are part of the `mat-core` mixin and can
178+
// potentially overwrite the absolute position of the container.
179+
&.mat-focus-indicator {
180+
position: absolute;
181+
}
182+
178183
@include cdk-high-contrast(active, off) {
179184
border: none;
180185
}

src/material/expansion/expansion-panel-header.scss

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
align-items: center;
77
padding: 0 24px;
88
border-radius: inherit;
9-
position: relative; // Necessary for the strong focus indication.
109
transition: height $mat-expansion-panel-header-transition;
1110

1211
// If the `NoopAnimationsModule` is used, disable the height transition.

src/material/expansion/expansion-panel.scss

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
transition: margin 225ms $mat-fast-out-slow-in-timing-function,
1414
mat-elevation-transition-property-value();
1515

16-
// Required so that the `box-shadow` works after we add `position: relative` to the header.
16+
// Required so that the `box-shadow` works after the focus indicator relatively positions the
17+
// header.
1718
position: relative;
1819

1920
.mat-accordion & {

src/material/list/list.scss

-3
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,6 @@ $mat-list-item-inset-divider-offset: 72px;
4848
width: 100%;
4949
padding: 0;
5050

51-
// Required for focus indicator.
52-
position: relative;
53-
5451
.mat-list-item-content {
5552
display: flex;
5653
flex-direction: row;

src/material/sort/sort-header.scss

-3
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,6 @@ $mat-sort-header-arrow-hint-opacity: 0.38;
3232
font: inherit;
3333
color: currentColor;
3434

35-
// Required for focus indicator.
36-
position: relative;
37-
3835
// Usually we could rely on the arrow showing up to be focus indication, but if a header is
3936
// active, the arrow will always be shown so the user has no way of telling the difference.
4037
[mat-sort-header].cdk-keyboard-focused &,

0 commit comments

Comments
 (0)