|
| 1 | +/*! |
| 2 | + * Copyright 2026 Google LLC |
| 3 | + * SPDX-License-Identifier: Apache-2.0 |
| 4 | + */ |
| 5 | + |
| 6 | +// go/keep-sorted start by_regex='(.+) prefix_order=sass: |
| 7 | +@use '../../../../tokens/versions/latest/sass/md-sys-state-focus-indicator'; |
| 8 | +// go/keep-sorted end |
| 9 | + |
| 10 | +@layer md.sys; |
| 11 | +@layer md.comp.focus-ring { |
| 12 | + .focus-ring-outer, |
| 13 | + .focus-ring-inner { |
| 14 | + --focus-ring-outline: none; |
| 15 | + --focus-ring-offset: 0; |
| 16 | + --focus-ring-animation: none; |
| 17 | + |
| 18 | + outline: var(--focus-ring-outline); |
| 19 | + outline-offset: var(--focus-ring-offset); |
| 20 | + animation: var(--focus-ring-animation), var(--ripple-animation, none); |
| 21 | + } |
| 22 | + |
| 23 | + // Focus rings support the following DOM use cases: |
| 24 | + // 1. Focus ring and interactive element are the same. |
| 25 | + // 2. Focus ring is a parent of a child interactive `.focus-ring-target`. |
| 26 | + // 3. Focus ring is a child of a parent interactive `.focus-ring-target`. |
| 27 | + // 4. Focus ring has `.focus-ring-host` and is a within an interactive shadow DOM host. |
| 28 | + // |
| 29 | + // Pseudo class emulation is only needed for the focus ring element, not for |
| 30 | + // the target or host elements. |
| 31 | + |
| 32 | + .focus-ring-outer { |
| 33 | + &:is(:focus-visible, .focus-visible), |
| 34 | + &:has(.focus-ring-target:focus-visible), |
| 35 | + .focus-ring-target:focus-visible &, |
| 36 | + :host(:focus-visible) &.focus-ring-host { |
| 37 | + --focus-ring-outline: #{md-sys-state-focus-indicator.$thickness} solid var(--md-sys-color-secondary); |
| 38 | + --focus-ring-offset: #{md-sys-state-focus-indicator.$outer-offset}; |
| 39 | + --focus-ring-animation: focus-ring-outer-grow 150ms |
| 40 | + cubic-bezier(0.2, 0, 0, 1), |
| 41 | + focus-ring-outer-shrink 450ms 150ms cubic-bezier(0.2, 0, 0, 1); |
| 42 | + } |
| 43 | + } |
| 44 | + |
| 45 | + .focus-ring-inner { |
| 46 | + &:is(:focus-visible, .focus-visible), |
| 47 | + &:has(.focus-ring-target:focus-visible), |
| 48 | + .focus-ring-target:focus-visible &, |
| 49 | + :host(:focus-visible) &.focus-ring-host { |
| 50 | + --focus-ring-outline: #{md-sys-state-focus-indicator.$thickness} solid var(--md-sys-color-secondary); |
| 51 | + --focus-ring-offset: #{md-sys-state-focus-indicator.$inner-offset}; |
| 52 | + --focus-ring-animation: focus-ring-inner-grow 150ms |
| 53 | + cubic-bezier(0.2, 0, 0, 1), |
| 54 | + focus-ring-inner-shrink 450ms 150ms cubic-bezier(0.2, 0, 0, 1); |
| 55 | + } |
| 56 | + } |
| 57 | + |
| 58 | + @keyframes focus-ring-outer-grow { |
| 59 | + from { |
| 60 | + outline-width: 0; |
| 61 | + } |
| 62 | + |
| 63 | + to { |
| 64 | + outline-width: 8px; |
| 65 | + } |
| 66 | + } |
| 67 | + |
| 68 | + @keyframes focus-ring-outer-shrink { |
| 69 | + from { |
| 70 | + outline-width: 8px; |
| 71 | + } |
| 72 | + } |
| 73 | + |
| 74 | + @keyframes focus-ring-inner-grow { |
| 75 | + from { |
| 76 | + outline-width: 0; |
| 77 | + outline-offset: 0; |
| 78 | + } |
| 79 | + to { |
| 80 | + outline-width: 8px; |
| 81 | + outline-offset: -8px; |
| 82 | + } |
| 83 | + } |
| 84 | + |
| 85 | + @keyframes focus-ring-inner-shrink { |
| 86 | + from { |
| 87 | + outline-width: 8px; |
| 88 | + outline-offset: -8px; |
| 89 | + } |
| 90 | + } |
| 91 | +} |
0 commit comments