Skip to content

Commit

Permalink
fix(focus)!: refactor focus ring to better match component shape
Browse files Browse the repository at this point in the history
- Focus ring now adds offset and width to look spec correct
- Replace `offset-vertical` and `offset-horizontal` tokens with a single `offset` token.

PiperOrigin-RevId: 516361036
  • Loading branch information
dfreedm authored and copybara-github committed Mar 13, 2023
1 parent 8a37ce2 commit 61ff279
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 22 deletions.
3 changes: 1 addition & 2 deletions checkbox/lib/_checkbox.scss
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,7 @@ $_checkmark-bottom-left: 7px, -14px;
md-focus-ring {
@include focus-ring.theme(
(
offset-vertical: -2px,
offset-horizontal: -2px,
offset: -2px,
shape: map.get(tokens.md-sys-shape-values(), corner-full),
)
);
Expand Down
5 changes: 2 additions & 3 deletions fab/lib/_shared.scss
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@

@include focus-ring.theme(
(
shape: shape.corners-to-shape-token(--_container-shape),
shape: shape.corners-to-shape-token('--_container-shape'),
)
);

Expand Down Expand Up @@ -193,8 +193,7 @@
// Adjust the focus ring padding to account for the 1px border in HCM.
@include focus-ring.theme(
(
offset-vertical: 3px,
offset-horizontal: 3px,
offset: 3px,
)
);
border: 1px solid ButtonText;
Expand Down
20 changes: 13 additions & 7 deletions focus/lib/_focus-ring.scss
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,22 @@ $_custom-property-prefix: 'focus-ring';
box-sizing: border-box;
pointer-events: none;
border: var(--_width) solid var(--_color);
border-start-start-radius: var(--_shape-start-start);
border-start-end-radius: var(--_shape-start-end);
border-end-start-radius: var(--_shape-end-start);
border-end-end-radius: var(--_shape-end-end);
border-start-start-radius: calc(
var(--_offset) + var(--_width) + var(--_shape-start-start)
);
border-start-end-radius: calc(
var(--_offset) + var(--_width) + var(--_shape-start-end)
);
border-end-start-radius: calc(
var(--_offset) + var(--_width) + var(--_shape-end-start)
);
border-end-end-radius: calc(
var(--_offset) + var(--_width) + var(--_shape-end-end)
);
// Note that the ring will not respect its parent's border. This will not be
// an issue as long as border is set via a sibling node, similar to ripple
// and touch target.
$vertical-inset: calc(-1 * (var(--_offset-vertical) + var(--_width)));
$horizontal-inset: calc(-1 * (var(--_offset-horizontal) + var(--_width)));
inset: $vertical-inset $horizontal-inset;
inset: calc(-1 * (var(--_offset) + var(--_width)));
}

:host([visible]) {
Expand Down
3 changes: 1 addition & 2 deletions focus/lib/_md-comp-focus-ring.scss
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ $_default: (
null,
map.get($deps, md-sys-shape, corner-full)
),
offset-vertical: if($exclude-hardcoded-values, null, 2px),
offset-horizontal: if($exclude-hardcoded-values, null, 2px),
offset: if($exclude-hardcoded-values, null, 2px),
width: if($exclude-hardcoded-values, null, 3px),
color: map.get($deps, md-sys-color, secondary)
);
Expand Down
3 changes: 1 addition & 2 deletions list/lib/listitem/_list-item.scss
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@

@include focus-ring.theme(
(
offset-vertical: -2px,
offset-horizontal: -3px,
offset: -3px,
shape: map.get(tokens.md-sys-shape-values(), corner-extra-small),
)
);
Expand Down
3 changes: 1 addition & 2 deletions navigationtab/lib/_navigation-tab.scss
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ $_custom-property-prefix: 'navigation-bar';

@include focus-ring.theme(
(
offset-vertical: -2px,
offset-horizontal: -2px,
offset: -2px,
shape: map.get(tokens.md-sys-shape-values(), corner-small),
)
);
Expand Down
3 changes: 1 addition & 2 deletions radio/lib/_radio.scss
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ $_md-sys-motion: tokens.md-sys-motion-values();

@include focus-ring.theme(
(
offset-vertical: -2px,
offset-horizontal: -2px,
offset: -2px,
)
);

Expand Down
3 changes: 1 addition & 2 deletions slider/lib/_slider.scss
Original file line number Diff line number Diff line change
Expand Up @@ -471,8 +471,7 @@
md-focus-ring {
@include focus-ring.theme(
(
offset-vertical: -2px,
offset-horizontal: -2px,
offset: -2px,
shape: map.get(tokens.md-sys-shape-values(), corner-full),
)
);
Expand Down

0 comments on commit 61ff279

Please sign in to comment.