Skip to content

Commit 8d908e5

Browse files
committed
bug(focus indicators): Move style for focus indicators to
1 parent 660a14a commit 8d908e5

File tree

10 files changed

+46
-35
lines changed

10 files changed

+46
-35
lines changed

src/dev-app/theme.scss

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
@include angular-material-mdc-typography();
1616
@include mat-edit-typography(mat-typography-config());
1717

18+
// MDC does not yet have an equivalent to `mat-core` to include this in.
19+
@include mat-mdc-strong-focus-indicators-base();
20+
1821
// Include base styles for strong focus indicators.
1922
.demo-strong-focus {
2023
@include mat-strong-focus-indicators();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343

4444
// The focus indicator should match the bounds of the entire button.
4545
.mat-mdc-focus-indicator {
46-
@include mat-fill;
46+
@include mat-fill();
4747
}
4848
}
4949

src/material-experimental/mdc-helpers/_mdc-helpers.scss

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -234,16 +234,12 @@ $mat-typography-level-mappings: (
234234
$border-radius: map-get($config, border-radius);
235235

236236
// Base styles for focus indicators.
237-
.mat-mdc-focus-indicator {
238-
position: relative;
239-
240-
&::before {
241-
@include mat-fill();
242-
box-sizing: border-box;
243-
pointer-events: none;
244-
border: $border-width $border-style transparent;
245-
border-radius: $border-radius;
246-
}
237+
.mat-mdc-focus-indicator::before {
238+
@include mat-fill();
239+
box-sizing: border-box;
240+
pointer-events: none;
241+
border: $border-width $border-style transparent;
242+
border-radius: $border-radius;
247243
}
248244

249245
// By default, all focus indicators are flush with the bounding box of their
@@ -313,3 +309,13 @@ $mat-typography-level-mappings: (
313309
$theme-or-color);
314310
}
315311
}
312+
313+
/// Mixin that applies base styles required for focus indicators to render appropriately.
314+
/// Should be included once in your app.
315+
@mixin mat-mdc-strong-focus-indicators-base() {
316+
// Ensure that focus indicator host elements are positioned so that the focus indicator
317+
// pseudo element within is positioned relatively to the host.
318+
.mat-mdc-focus-indicator {
319+
position: relative;
320+
}
321+
}

src/material/core/_core.scss

Lines changed: 2 additions & 0 deletions
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';
@@ -14,6 +15,7 @@
1415
@mixin mat-core($typography-config: null) {
1516
@include angular-material-typography($typography-config);
1617
@include mat-ripple();
18+
@include mat-strong-focus-indicators-base();
1719
@include cdk-a11y();
1820
@include cdk-overlay();
1921
@include cdk-text-field();

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

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,12 @@
2222
$border-radius: map-get($config, border-radius);
2323

2424
// Base styles for focus indicators.
25-
.mat-focus-indicator {
26-
position: relative;
27-
28-
&::before {
29-
@include mat-fill();
30-
box-sizing: border-box;
31-
pointer-events: none;
32-
border: $border-width $border-style transparent;
33-
border-radius: $border-radius;
34-
}
25+
.mat-focus-indicator::before {
26+
@include mat-fill();
27+
box-sizing: border-box;
28+
pointer-events: none;
29+
border: $border-width $border-style transparent;
30+
border-radius: $border-radius;
3531
}
3632

3733
// By default, all focus indicators are flush with the bounding box of their
@@ -103,3 +99,13 @@
10399
$theme-or-color);
104100
}
105101
}
102+
103+
/// Mixin that applies base styles required for focus indicators to render appropriately.
104+
/// Automatically included within `mat-core`, should not be directly included in your app.
105+
@mixin mat-strong-focus-indicators-base() {
106+
// Ensure that focus indicator host elements are positioned so that the focus indicator
107+
// pseudo element within is positioned relatively to the host.
108+
.mat-focus-indicator {
109+
position: relative;
110+
}
111+
}

src/material/datepicker/calendar-body.scss

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -152,12 +152,6 @@ $mat-calendar-range-end-body-cell-size:
152152
cursor: default;
153153
}
154154

155-
// Apply this style with additional specificity to override the focus indicator's relative
156-
// positioning.
157-
.mat-calendar-body-cell .mat-calendar-body-cell-content {
158-
position: absolute;
159-
}
160-
161155
.mat-calendar-body-cell-content {
162156
top: $mat-calendar-body-cell-content-margin;
163157
left: $mat-calendar-body-cell-content-margin;
@@ -180,6 +174,12 @@ $mat-calendar-range-end-body-cell-size:
180174
// Choosing a value clearly larger than the height ensures we get the correct capsule shape.
181175
border-radius: $mat-calendar-body-cell-radius;
182176

177+
// Apply this style with additional specificity to override the focus indicator's relative
178+
// positioning.
179+
.mat-calendar-body-cell & {
180+
position: absolute;
181+
}
182+
183183
@include cdk-high-contrast(active, off) {
184184
border: none;
185185
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
align-items: center;
55
padding: 0 24px;
66
border-radius: inherit;
7-
position: relative; // Necessary for the strong focus indication.
87

98
&:focus,
109
&:hover {

src/material/expansion/expansion-panel.scss

Lines changed: 2 additions & 1 deletion
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

Lines changed: 0 additions & 3 deletions
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

Lines changed: 0 additions & 3 deletions
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)