|
8 | 8 | /// }
|
9 | 9 |
|
10 | 10 | @mixin mat-strong-focus-indicators() {
|
11 |
| - $border-width: 2px; |
| 11 | + // Reference to the root selector, used to simplify the nested selectors |
| 12 | + // in this mixin. |
| 13 | + $root-selector: #{&}; |
12 | 14 |
|
13 |
| - // Base styles for focus indicators. |
14 |
| - & .mat-focus-indicator::before { |
15 |
| - border-radius: 4px; |
16 |
| - border: $border-width solid transparent; |
17 |
| - box-sizing: border-box; |
18 |
| - position: absolute; |
19 |
| - pointer-events: none; |
20 |
| - top: 0; |
21 |
| - right: 0; |
22 |
| - bottom: 0; |
23 |
| - left: 0; |
24 |
| - } |
| 15 | + // Border width of the focus indicators. |
| 16 | + $border-width: 2px; |
25 | 17 |
|
| 18 | + @at-root .mat-focus-indicator { |
| 19 | + // Base styles for the focus indicators. |
| 20 | + #{$root-selector} &::before { |
| 21 | + border: $border-width solid transparent; |
| 22 | + border-radius: 4px; |
| 23 | + box-sizing: border-box; |
| 24 | + pointer-events: none; |
| 25 | + position: absolute; |
| 26 | + top: 0; |
| 27 | + right: 0; |
| 28 | + bottom: 0; |
| 29 | + left: 0; |
| 30 | + } |
| 31 | + |
| 32 | + // By default, all focus indicators are flush with the bounding box of their |
| 33 | + // host element. For particular elements (listed below), default inset/offset |
| 34 | + // values are necessary to ensure that the focus indicator is sufficiently |
| 35 | + // contrastive and renders appropriately. |
26 | 36 |
|
27 |
| - // By default, all focus indicators are flush with the bounding box of their |
28 |
| - // host element. For particular elements (listed below), default inset/offset |
29 |
| - // values are necessary to ensure that the focus indicator is sufficiently |
30 |
| - // contrastive and renders appropriately. |
31 |
| - & .mat-focus-indicator { |
32 |
| - &.mat-button-base::before, |
33 |
| - &.mat-card::before, |
34 |
| - &.mat-sort-header-button::before { |
| 37 | + #{$root-selector} &.mat-button-base::before, |
| 38 | + #{$root-selector} &.mat-card::before, |
| 39 | + #{$root-selector} &.mat-sort-header-button::before { |
35 | 40 | margin: $border-width * -2;
|
36 | 41 | }
|
37 | 42 |
|
38 |
| - &.mat-calendar-body-cell::before { |
| 43 | + #{$root-selector} &.mat-calendar-body-cell::before { |
39 | 44 | margin: $border-width * -1;
|
40 | 45 | }
|
41 | 46 |
|
42 |
| - &.mat-tab-link::before, |
43 |
| - &.mat-tab-label::before { |
| 47 | + #{$root-selector} &.mat-tab-link::before, |
| 48 | + #{$root-selector} &.mat-tab-label::before { |
44 | 49 | margin: $border-width * 2;
|
45 | 50 | }
|
46 |
| - } |
47 | 51 |
|
48 |
| - // On focus, actually render the focus indicators. Defining a pseudo |
49 |
| - // element's content will cause it to render. |
50 |
| - & .mat-focus-indicator { |
51 |
| - // Checkbox, Option, Slide Toggle |
52 |
| - .cdk-focused.mat-checkbox &::before, |
53 |
| - .cdk-focused.mat-radio-button &::before, |
54 |
| - .cdk-focused.mat-slide-toggle &::before, |
| 52 | + // Render the focus indicator on focus. Defining a pseudo element's |
| 53 | + // content will cause it to render. |
| 54 | + |
| 55 | + // For checkboxes, radios, and slide toggles, render the focus indicator |
| 56 | + // when the class .cdk-focused is present. |
| 57 | + #{$root-selector} .cdk-focused.mat-checkbox &::before, |
| 58 | + #{$root-selector} .cdk-focused.mat-radio-button &::before, |
| 59 | + #{$root-selector} .cdk-focused.mat-slide-toggle &::before, |
55 | 60 |
|
56 |
| - // Option |
57 |
| - &.mat-option.mat-active::before, |
| 61 | + // For options, render the focus indicator when the class .mat-active |
| 62 | + // is present. |
| 63 | + #{$root-selector} &.mat-active.mat-option::before, |
58 | 64 |
|
59 |
| - // All other components |
60 |
| - &:focus::before { |
| 65 | + // For all other components, render the focus indicator on focus. |
| 66 | + #{$root-selector} &:focus::before { |
61 | 67 | content: '';
|
62 |
| - } |
| 68 | + } |
63 | 69 | }
|
64 | 70 | }
|
65 | 71 |
|
|
80 | 86 | /// }
|
81 | 87 |
|
82 | 88 | @mixin mat-strong-focus-indicators-theme($themeOrColor) {
|
83 |
| - & .mat-focus-indicator::before { |
| 89 | + .mat-focus-indicator::before { |
84 | 90 | border-color: if(
|
85 | 91 | type-of($themeOrColor) == 'map',
|
86 | 92 | mat-color(map_get($themeOrColor, primary)),
|
|
0 commit comments