Skip to content

Commit 4ae2d93

Browse files
committed
feat(material-experimental/mdc-list): add support for strong focus indicators
Adds support for strong focus indicators to the MDC-based list. Also simplifies SCSS code for the hover/focus/selected styles.
1 parent 98d4799 commit 4ae2d93

File tree

5 files changed

+26
-13
lines changed

5 files changed

+26
-13
lines changed

src/material-experimental/mdc-helpers/_focus-indicators.scss

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,10 @@
7373
.mat-mdc-slide-toggle-focused .mat-mdc-focus-indicator::before,
7474
.mat-mdc-radio-button.cdk-focused .mat-mdc-focus-indicator::before,
7575

76-
// For buttons, render the focus indicator when the parent button is focused.
76+
// For buttons and list items, render the focus indicator when the parent
77+
// button or list item is focused.
7778
.mat-mdc-button-base:focus .mat-mdc-focus-indicator::before,
79+
.mat-mdc-list-item:focus > .mat-mdc-focus-indicator::before,
7880

7981
// For options, render the focus indicator when the class .mat-mdc-option-active is present.
8082
.mat-mdc-focus-indicator.mat-mdc-option-active::before,

src/material-experimental/mdc-list/list-base.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,6 @@ export abstract class MatListItemBase implements AfterContentInit, OnDestroy, Ri
8080
this._initInteractiveListItem();
8181
}
8282

83-
// Only interactive list items are commonly focusable, but in some situations,
84-
// consumers provide a custom tabindex. We still would want to have strong focus
85-
// indicator support in such scenarios.
86-
this._hostElement.classList.add('mat-mdc-focus-indicator');
87-
8883
// If no type attribute is specified for a host `<button>` element, set it to `button`. If a
8984
// type attribute is already specified, we do nothing. We do this for backwards compatibility.
9085
// TODO: Determine if we intend to continue doing this for the MDC-based list.

src/material-experimental/mdc-list/list-item.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,9 @@
1515
</span>
1616

1717
<ng-content select="mat-divider"></ng-content>
18+
19+
<!--
20+
Strong focus indicator element. MDC uses the `::before` pseudo element for the default
21+
focus/hover/selected state, so we need a separate element.
22+
-->
23+
<div class="mat-mdc-focus-indicator"></div>

src/material-experimental/mdc-list/list-option.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,9 @@
5050

5151
<!-- Divider -->
5252
<ng-content select="mat-divider"></ng-content>
53+
54+
<!--
55+
Strong focus indicator element. MDC uses the `::before` pseudo element for the default
56+
focus/hover/selected state, so we need a separate element.
57+
-->
58+
<div class="mat-mdc-focus-indicator"></div>

src/material-experimental/mdc-list/list.scss

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,18 @@
9797
}
9898
}
9999

100-
// MDC's state styles are included with their ripple which we don't use. Instead we add
101-
// the focus and hover styles ourselves using this pseudo-element
100+
// MDC's hover and focus state styles are included with their ripple which we don't use.
101+
// Instead we add the focus, hover and selected styles ourselves using this pseudo-element
102102
.mat-mdc-list-item-interactive::before {
103+
@include mat-fill();
103104
content: '';
104-
position: absolute;
105-
top: 0;
106-
left: 0;
107-
bottom: 0;
108-
right: 0;
109105
opacity: 0;
110106
}
107+
108+
// The MDC-based list items already use the `::before` pseudo element for the standard
109+
// focus/selected/hover state. Hence, we need to have a separate list-item spanning
110+
// element that can be used for strong focus indicators.
111+
.mat-mdc-list-item > .mat-mdc-focus-indicator {
112+
@include mat-fill();
113+
pointer-events: none;
114+
}

0 commit comments

Comments
 (0)