|
6 | 6 | @import '@material/theme/functions.import'; |
7 | 7 | @import '@material/theme/variables.import'; |
8 | 8 | @import '@material/typography/variables.import'; |
| 9 | +@import '../../material/core/style/layout-common'; |
9 | 10 | @import '../../material/core/theming/theming'; |
10 | 11 | @import '../../material/core/typography/typography'; |
11 | 12 |
|
@@ -211,3 +212,74 @@ $mat-typography-level-mappings: ( |
211 | 212 | // Reset the original values. |
212 | 213 | $mdc-typography-styles: $orig-mdc-typography-styles !global; |
213 | 214 | } |
| 215 | + |
| 216 | +/// Mixin that turns on strong focus indicators. |
| 217 | +/// |
| 218 | +/// @example |
| 219 | +/// .my-app { |
| 220 | +/// @include mat-mdc-strong-focus-indicators(); |
| 221 | +/// } |
| 222 | +@mixin mat-mdc-strong-focus-indicators() { |
| 223 | + // Base styles for the focus indicators. |
| 224 | + .mat-mdc-focus-indicator::before { |
| 225 | + @include mat-fill(); |
| 226 | + |
| 227 | + border-radius: $mat-focus-indicator-border-radius; |
| 228 | + border: $mat-focus-indicator-border-width $mat-focus-indicator-border-style transparent; |
| 229 | + box-sizing: border-box; |
| 230 | + pointer-events: none; |
| 231 | + } |
| 232 | + |
| 233 | + // By default, all focus indicators are flush with the bounding box of their |
| 234 | + // host element. For particular elements (listed below), default inset/offset |
| 235 | + // values are necessary to ensure that the focus indicator is sufficiently |
| 236 | + // contrastive and renders appropriately. |
| 237 | + |
| 238 | + .mat-mdc-focus-indicator.mdc-button::before, |
| 239 | + .mat-mdc-focus-indicator.mdc-fab::before, |
| 240 | + .mat-mdc-focus-indicator.mdc-icon-button::before { |
| 241 | + margin: $mat-focus-indicator-border-width * -2; |
| 242 | + } |
| 243 | + |
| 244 | + .mat-mdc-focus-indicator.mat-mdc-tab::before, |
| 245 | + .mat-mdc-focus-indicator.mat-mdc-tab-link::before { |
| 246 | + margin: $mat-focus-indicator-border-width * 2; |
| 247 | + } |
| 248 | + |
| 249 | + // Render the focus indicator on focus. Defining a pseudo element's |
| 250 | + // content will cause it to render. |
| 251 | + |
| 252 | + // For checkboxes and slide toggles, render the focus indicator when we know the hidden input |
| 253 | + // is focused (slightly different for each control). |
| 254 | + .mdc-checkbox__native-control:focus ~ .mat-mdc-focus-indicator::before, |
| 255 | + .mat-mdc-slide-toggle-focused .mat-mdc-focus-indicator::before, |
| 256 | + |
| 257 | + // For all other components, render the focus indicator on focus. |
| 258 | + .mat-mdc-focus-indicator:focus::before { |
| 259 | + content: ''; |
| 260 | + } |
| 261 | +} |
| 262 | + |
| 263 | +/// Mixin that sets the color of the focus indicators. |
| 264 | +/// |
| 265 | +/// @param {color|map} $themeOrMap |
| 266 | +/// If theme, focus indicators are set to the primary color of the theme. If |
| 267 | +/// color, focus indicators are set to that color. |
| 268 | +/// |
| 269 | +/// @example |
| 270 | +/// .demo-dark-theme { |
| 271 | +/// @include mat-mdc-strong-focus-indicators-theme($darkThemeMap); |
| 272 | +/// } |
| 273 | +/// |
| 274 | +/// @example |
| 275 | +/// .demo-red-theme { |
| 276 | +/// @include mat-mdc-strong-focus-indicators-theme(#F00); |
| 277 | +/// } |
| 278 | +@mixin mat-mdc-strong-focus-indicators-theme($themeOrColor) { |
| 279 | + .mat-mdc-focus-indicator::before { |
| 280 | + border-color: if( |
| 281 | + type-of($themeOrColor) == 'map', |
| 282 | + mat-color(map_get($themeOrColor, primary)), |
| 283 | + $themeOrColor); |
| 284 | + } |
| 285 | +} |
0 commit comments