Skip to content

Commit ea98807

Browse files
committed
fix(material/chips): adds border on chip-action focus
Updates Angular Material Chips component so that when mat-mdc-chip-action is focused on a border appears around either the text of the chip or the action icon, whichever is being focused. This improves the accessibility by aiding the user in seeing which element/action is being focused on. Fixes b/286103414
1 parent 8523397 commit ea98807

File tree

1 file changed

+27
-12
lines changed

1 file changed

+27
-12
lines changed

src/material/chips/chip.scss

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -659,15 +659,36 @@ $fallbacks: m3-chip.get-tokens();
659659
left: 0;
660660
pointer-events: none;
661661
}
662+
663+
}
662664

665+
// Targets .mdc-evolution-chip__cell
666+
.mat-mdc-chip-action .mat-focus-indicator::before,
667+
// Targets mdc-evolution-chip__icon
668+
.mat-mdc-chip-action.mat-focus-indicator::before {
663669
// For the chip element, default inset/offset values are necessary to ensure that
664670
// the focus indicator is sufficiently contrastive and renders appropriately.
665-
.mat-focus-indicator::before {
666-
$default-border-width: focus-indicators-private.$default-border-width;
667-
$border-width: var(--mat-focus-indicator-border-width, #{$default-border-width});
668-
$offset: calc(#{$border-width} + 2px);
669-
margin: calc(#{$offset} * -1);
670-
}
671+
$default-border-width: focus-indicators-private.$default-border-width;
672+
$border-width: var(--mat-focus-indicator-border-width, #{$default-border-width});
673+
$offset: calc(#{$border-width} + 2px);
674+
675+
content: '';
676+
display: block;
677+
position: absolute;
678+
padding: $offset;
679+
margin: calc(#{$offset} * -1);
680+
border-width: $border-width;
681+
border: solid;
682+
border-color: var(--mat-focus-indicator-border-color), black;
683+
opacity: 0;
684+
height: auto;
685+
}
686+
687+
// The chip has multiple focus targets so we have to put the indicator on
688+
// a separate element, rather than on the focusable element itself.
689+
.mat-mdc-chip-action:focus .mat-focus-indicator::before,
690+
.mat-mdc-chip-action.mat-focus-indicator:focus::before {
691+
opacity: 1;
671692
}
672693

673694
.mat-mdc-chip-edit, .mat-mdc-chip-remove {
@@ -725,12 +746,6 @@ $fallbacks: m3-chip.get-tokens();
725746
}
726747
}
727748

728-
// The chip has multiple focus targets so we have to put the indicator on
729-
// a separate element, rather than on the focusable element itself.
730-
.mat-mdc-chip-action:focus .mat-focus-indicator::before {
731-
content: '';
732-
}
733-
734749
// Prevents icon from being cut off when text spacing is increased.
735750
// .mat-mdc-chip-remove selector necessary for remove button with icon.
736751
// Fixes b/250063405.

0 commit comments

Comments
 (0)