Skip to content

Commit 57f7ae2

Browse files
Elliott Marquezcopybara-github
authored andcommitted
feat(listitem): add noninteractive to list item
PiperOrigin-RevId: 532595788
1 parent b1e9c4a commit 57f7ae2

File tree

8 files changed

+80
-11
lines changed

8 files changed

+80
-11
lines changed

list/demo/demo.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ const collection =
4040

4141
new Knob('md-list-item', {ui: title()}),
4242
new Knob('disabled', {ui: boolInput(), defaultValue: false}),
43+
new Knob('noninteractive', {ui: boolInput(), defaultValue: false}),
4344
new Knob('active', {ui: boolInput(), defaultValue: false}),
4445
new Knob(
4546
'multiLineSupportingText', {ui: boolInput(), defaultValue: false}),

list/demo/stories.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export interface StoryKnobs {
1919

2020
'md-list-item': void;
2121
disabled: boolean;
22+
noninteractive: boolean;
2223
active: boolean;
2324
multiLineSupportingText: boolean;
2425
headline: string;
@@ -65,6 +66,7 @@ const standard: MaterialStoryInit<StoryKnobs> = {
6566
const {
6667
listTabIndex,
6768
disabled,
69+
noninteractive,
6870
active,
6971
multiLineSupportingText,
7072
headline,
@@ -86,6 +88,7 @@ const standard: MaterialStoryInit<StoryKnobs> = {
8688
.multiLineSupportingText=${multiLineSupportingText}
8789
.trailingSupportingText=${trailingSupportingText}
8890
.disabled=${disabled}
91+
.noninteractive=${noninteractive}
8992
.itemTabIndex=${itemTabIndex}
9093
.active=${active}>
9194
</md-list-item>
@@ -96,6 +99,7 @@ const standard: MaterialStoryInit<StoryKnobs> = {
9699
.multiLineSupportingText=${multiLineSupportingText}
97100
.trailingSupportingText=${trailingSupportingText}
98101
.disabled=${disabled}
102+
.noninteractive=${noninteractive}
99103
.itemTabIndex=${itemTabIndex}
100104
.active=${active}>
101105
<md-icon data-variant="icon" slot="start">
@@ -112,6 +116,7 @@ const standard: MaterialStoryInit<StoryKnobs> = {
112116
.multiLineSupportingText=${multiLineSupportingText}
113117
.trailingSupportingText=${trailingSupportingText}
114118
.disabled=${disabled}
119+
.noninteractive=${noninteractive}
115120
.itemTabIndex=${itemTabIndex}
116121
.href=${href}
117122
.target=${target}
@@ -128,6 +133,7 @@ const standard: MaterialStoryInit<StoryKnobs> = {
128133
.multiLineSupportingText=${multiLineSupportingText}
129134
.trailingSupportingText=${trailingSupportingText}
130135
.disabled=${disabled}
136+
.noninteractive=${noninteractive}
131137
.itemTabIndex=${itemTabIndex}
132138
.active=${active}>
133139
<img src=${knobs['avatar img']} slot="start" data-variant="avatar">
@@ -139,6 +145,7 @@ const standard: MaterialStoryInit<StoryKnobs> = {
139145
.multiLineSupportingText=${multiLineSupportingText}
140146
.trailingSupportingText=${trailingSupportingText}
141147
.disabled=${disabled}
148+
.noninteractive=${noninteractive}
142149
.itemTabIndex=${itemTabIndex}
143150
.active=${active}>
144151
<span slot="start" data-variant="avatar">
@@ -152,6 +159,7 @@ const standard: MaterialStoryInit<StoryKnobs> = {
152159
.multiLineSupportingText=${multiLineSupportingText}
153160
.trailingSupportingText=${trailingSupportingText}
154161
.disabled=${disabled}
162+
.noninteractive=${noninteractive}
155163
.itemTabIndex=${itemTabIndex}
156164
.active=${active}>
157165
<img .src=${image} data-variant="image" slot="start">
@@ -163,6 +171,7 @@ const standard: MaterialStoryInit<StoryKnobs> = {
163171
.multiLineSupportingText=${multiLineSupportingText}
164172
.trailingSupportingText=${trailingSupportingText}
165173
.disabled=${disabled}
174+
.noninteractive=${noninteractive}
166175
.itemTabIndex=${itemTabIndex}
167176
.active=${active}>
168177
<video

list/lib/listitem/_list-item.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
// hide android tap color since we have ripple
7777
-webkit-tap-highlight-color: transparent;
7878

79-
&:not(.disabled) {
79+
&:not(.disabled):not(.noninteractive) {
8080
cursor: pointer;
8181
}
8282

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* @license
3+
* Copyright 2023 Google LLC
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
import {nothing} from 'lit';
8+
import {property} from 'lit/decorators.js';
9+
10+
import {ListItemEl} from './list-item.js';
11+
12+
// tslint:disable-next-line:enforce-comments-on-exported-symbols
13+
export class ListItemOnly extends ListItemEl {
14+
/**
15+
* Removes the hover and click ripples from the item when true.
16+
*/
17+
@property() noninteractive = false;
18+
19+
override getRenderClasses() {
20+
return {
21+
...super.getRenderClasses(),
22+
'noninteractive': this.noninteractive,
23+
};
24+
}
25+
26+
override renderRipple() {
27+
return this.noninteractive ? nothing : super.renderRipple();
28+
}
29+
}

list/lib/listitem/list-item.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ export class ListItemEl extends LitElement implements ListItem {
100100
return this.ripple;
101101
};
102102

103-
private isFirstUpdate = true;
103+
protected isFirstUpdate = true;
104104

105105
protected override willUpdate(changed: PropertyValues<this>) {
106106
if (changed.has('active') && !this.disabled) {
@@ -149,7 +149,7 @@ export class ListItemEl extends LitElement implements ListItem {
149149
/**
150150
* Handles rendering of the ripple element.
151151
*/
152-
private renderRipple() {
152+
protected renderRipple() {
153153
return this.showRipple ?
154154
html`<md-ripple ?disabled="${this.disabled}"></md-ripple>` :
155155
nothing;
@@ -158,7 +158,7 @@ export class ListItemEl extends LitElement implements ListItem {
158158
/**
159159
* Handles rendering of the focus ring.
160160
*/
161-
private renderFocusRing() {
161+
protected renderFocusRing() {
162162
return html`<md-focus-ring class="focus-ring" for="item"></md-focus-ring>`;
163163
}
164164

@@ -179,14 +179,14 @@ export class ListItemEl extends LitElement implements ListItem {
179179
/**
180180
* The content rendered at the start of the list item.
181181
*/
182-
private renderStart() {
182+
protected renderStart() {
183183
return html`<div class="start"><slot name="start"></slot></div>`;
184184
}
185185

186186
/**
187187
* Handles rendering the headline and supporting text.
188188
*/
189-
private renderBody() {
189+
protected renderBody() {
190190
const supportingText =
191191
this.supportingText !== '' ? this.renderSupportingText() : '';
192192

@@ -197,7 +197,7 @@ export class ListItemEl extends LitElement implements ListItem {
197197
/**
198198
* Renders the one-line supporting text.
199199
*/
200-
private renderSupportingText() {
200+
protected renderSupportingText() {
201201
return html`<span
202202
class="supporting-text ${classMap(this.getSupportingTextClasses())}"
203203
>${this.supportingText}</span>`;
@@ -206,7 +206,7 @@ export class ListItemEl extends LitElement implements ListItem {
206206
/**
207207
* Gets the classes for the supporting text node
208208
*/
209-
private getSupportingTextClasses() {
209+
protected getSupportingTextClasses() {
210210
return {'supporting-text--multi-line': this.multiLineSupportingText};
211211
}
212212

@@ -224,7 +224,7 @@ export class ListItemEl extends LitElement implements ListItem {
224224
/**
225225
* Renders the supporting text at the end of the list item.
226226
*/
227-
private renderTrailingSupportingText() {
227+
protected renderTrailingSupportingText() {
228228
return html`<span class="trailing-supporting-text"
229229
>${this.trailingSupportingText}</span>`;
230230
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* @license
3+
* Copyright 2023 Google LLC
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
import {nothing} from 'lit';
8+
import {property} from 'lit/decorators.js';
9+
10+
import {ListItemLink} from './list-item-link.js';
11+
12+
// tslint:disable-next-line:enforce-comments-on-exported-symbols
13+
export class ListItemLinkOnly extends ListItemLink {
14+
/**
15+
* Removes the hover and click ripples from the item when true. Clicking the
16+
* link will still cause link navigation.
17+
*/
18+
@property() noninteractive = false;
19+
20+
override getRenderClasses() {
21+
return {
22+
...super.getRenderClasses(),
23+
'noninteractive': this.noninteractive,
24+
};
25+
}
26+
27+
override renderRipple() {
28+
return this.noninteractive ? nothing : super.renderRipple();
29+
}
30+
}

list/list-item-link.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {customElement} from 'lit/decorators.js';
88

99
import {styles as forcedColors} from './lib/listitem/forced-colors-styles.css.js';
1010
import {styles} from './lib/listitem/list-item-styles.css.js';
11-
import {ListItemLink} from './lib/listitemlink/list-item-link.js';
11+
import {ListItemLinkOnly as ListItemLink} from './lib/listitemlink/list-item-link-only.js';
1212

1313
declare global {
1414
interface HTMLElementTagNameMap {

list/list-item.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import {customElement} from 'lit/decorators.js';
88

99
import {styles as forcedColors} from './lib/listitem/forced-colors-styles.css.js';
10-
import {ListItemEl as ListItem} from './lib/listitem/list-item.js';
10+
import {ListItemOnly as ListItem} from './lib/listitem/list-item-only.js';
1111
import {styles} from './lib/listitem/list-item-styles.css.js';
1212

1313
declare global {

0 commit comments

Comments
 (0)