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

Commit c0dfb94

Browse files
태재영Matt Goo
authored andcommitted
feat(list): add ripple to list-item (#894)
1 parent 4d64627 commit c0dfb94

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

packages/list/ListItem.tsx

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,21 @@
2222

2323
import React from 'react';
2424
import classnames from 'classnames';
25+
import {closest} from '@material/dom/ponyfill';
26+
import {withRipple, InjectedProps} from '@material/react-ripple';
2527
import {MDCListFoundation} from '@material/list/foundation';
28+
2629
import {ListItemContext, ListItemContextShape} from './index';
27-
import {closest} from '@material/dom/ponyfill';
2830

2931
export interface ListItemProps<T extends HTMLElement = HTMLElement>
30-
extends React.HTMLProps<T>,
31-
ListItemContextShape {
32+
extends React.HTMLProps<T>, ListItemContextShape, InjectedProps<T> {
3233
checkboxList?: boolean;
3334
radioList?: boolean;
3435
tag?: string;
3536
activated?: boolean;
3637
selected?: boolean;
3738
ref?: React.Ref<any>;
39+
initRipple?: (surface: T) => void;
3840
}
3941

4042
export interface ListItemState {
@@ -87,9 +89,12 @@ export class ListItemBase<
8789

8890
componentDidMount() {
8991
this.initializeTabIndex();
92+
if (this.props.initRipple) {
93+
this.props.initRipple(this.listItemElement.current as T);
94+
}
9095
}
9196

92-
componentDidUpdate(prevProps: ListItemProps) {
97+
componentDidUpdate(prevProps: ListItemProps<T>) {
9398
if (prevProps.tabIndex !== this.props.tabIndex) {
9499
this.setState({tabIndex: this.props.tabIndex});
95100
}
@@ -176,6 +181,7 @@ export class ListItemBase<
176181
className,
177182
children,
178183
role,
184+
initRipple,
179185
checkboxList,
180186
radioList,
181187
onDestroy,
@@ -224,4 +230,5 @@ const ListItem: React.FunctionComponent<ListItemProps> = (props) => {
224230
);
225231
};
226232

227-
export default ListItem;
233+
// export default ListItem;
234+
export default withRipple<ListItemProps, HTMLElement>(ListItem);

packages/list/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"@material/list": "^1.0.0",
2121
"@material/react-checkbox": "^0.10.0",
2222
"@material/react-radio": "^0.10.0",
23+
"@material/react-ripple": "^0.12.0",
2324
"classnames": "^2.2.6",
2425
"memoize-one": "^5.0.4",
2526
"react": "^16.4.2"

packages/menu/MenuListItem.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,14 @@ class MenuListItem<T extends HTMLElement = HTMLElement> extends React.Component<
3333
{}
3434
> {
3535
render() {
36-
const {role = 'menuitem', children, ...otherProps} = this.props;
36+
const {
37+
role = 'menuitem',
38+
children,
39+
/* eslint-disable no-unused-vars */
40+
computeBoundingRect,
41+
/* eslint-disable no-unused-vars */
42+
...otherProps
43+
} = this.props;
3744

3845
return (
3946
<ListItem role={role} {...otherProps}>

0 commit comments

Comments
 (0)