Skip to content
This repository was archived by the owner on Jan 13, 2025. It is now read-only.

Commit 311f29a

Browse files
feat(focus-ring): Update $ring-radius to support list type values so a focus ring can follow custom shapes
PiperOrigin-RevId: 627440155
1 parent 5bebc00 commit 311f29a

File tree

1 file changed

+34
-6
lines changed

1 file changed

+34
-6
lines changed

packages/mdc-focus-ring/_focus-ring.scss

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2020
// THE SOFTWARE.
2121
//
22-
22+
@use 'sass:list';
23+
@use 'sass:math';
24+
@use 'sass:meta';
2325
@use '@material/feature-targeting/feature-targeting';
2426
@use '@material/rtl/rtl';
2527
@use '@material/dom/dom';
@@ -33,7 +35,8 @@ $container-outer-padding-default: 2px !default;
3335

3436
/// Styles applied to the component's inner focus ring element.
3537
///
36-
/// @param $ring-radius [$ring-radius-default] - Focus ring radius.
38+
/// @param $ring-radius [$ring-radius-default] - Focus ring radius, either a
39+
/// single value or a list of radius values to apply.
3740
/// @param $inner-ring-width [$inner-ring-width-default] - Inner focus ring width.
3841
/// @param $inner-ring-color [$inner-ring-color-default] - Inner focus ring color.
3942
/// @param $outer-ring-width [$outer-ring-width-default] - Outer focus ring width.
@@ -62,7 +65,7 @@ $container-outer-padding-default: 2px !default;
6265
@include feature-targeting.targets($feat-structure) {
6366
pointer-events: none;
6467
border: $inner-ring-width solid $inner-ring-color;
65-
border-radius: calc($ring-radius - $outer-ring-width);
68+
border-radius: _inner-ring-radius($ring-radius, $outer-ring-width);
6669
box-sizing: content-box;
6770
position: absolute;
6871
top: 50%;
@@ -159,7 +162,8 @@ $container-outer-padding-default: 2px !default;
159162

160163
/// Customizes the border radius of the button focus ring.
161164
///
162-
/// @param {Number} $ring-radius - The border radius of the focus ring.
165+
/// @param {Number|List} $ring-radius - The border radius of the focus ring,
166+
///. either a single value or a list of radius values to apply.
163167
/// @param {Number} $outer-ring-width [$outer-ring-width] - Width of the outer
164168
/// ring, required to compute the radius for the inner ring.
165169
@mixin focus-ring-radius(
@@ -170,10 +174,34 @@ $container-outer-padding-default: 2px !default;
170174
$feat-structure: feature-targeting.create-target($query, structure);
171175

172176
@include feature-targeting.targets($feat-structure) {
173-
border-radius: calc($ring-radius - $outer-ring-width);
174-
177+
border-radius: _inner-ring-radius($ring-radius, $outer-ring-width);
175178
&::after {
176179
border-radius: $ring-radius;
177180
}
178181
}
179182
}
183+
184+
/// Returns the inner focus ring's border radius given the outer ring's radius.
185+
///
186+
/// @param {Number|List} $ring-radius - The border radius of the focus ring,
187+
///. either a single value or a list of radius values to apply.
188+
/// @param {Number} $outer-ring-width [$outer-ring-width] - Width of the outer
189+
/// ring, required to compute the radius for the inner ring.
190+
/// @return {Number|List} the inner focus ring's border radius.
191+
@function _inner-ring-radius($ring-radius, $outer-ring-width) {
192+
$inner-ring-radius: null;
193+
@if (meta.type-of($ring-radius) == 'list') {
194+
$inner-ring-radius: ();
195+
@each $radius in $ring-radius {
196+
$inner-radius: math.max($radius - $outer-ring-width, 0);
197+
$inner-ring-radius: list.append(
198+
$inner-ring-radius,
199+
$inner-radius,
200+
$separator: space
201+
);
202+
}
203+
} @else {
204+
$inner-ring-radius: calc($ring-radius - $outer-ring-width);
205+
}
206+
@return $inner-ring-radius;
207+
}

0 commit comments

Comments
 (0)