Skip to content

Commit

Permalink
feat(list): add ripple to list-item (#894)
Browse files Browse the repository at this point in the history
  • Loading branch information
태재영 authored and Matt Goo committed May 30, 2019
1 parent 4d64627 commit c0dfb94
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
17 changes: 12 additions & 5 deletions packages/list/ListItem.tsx
Expand Up @@ -22,19 +22,21 @@

import React from 'react';
import classnames from 'classnames';
import {closest} from '@material/dom/ponyfill';
import {withRipple, InjectedProps} from '@material/react-ripple';
import {MDCListFoundation} from '@material/list/foundation';

import {ListItemContext, ListItemContextShape} from './index';
import {closest} from '@material/dom/ponyfill';

export interface ListItemProps<T extends HTMLElement = HTMLElement>
extends React.HTMLProps<T>,
ListItemContextShape {
extends React.HTMLProps<T>, ListItemContextShape, InjectedProps<T> {
checkboxList?: boolean;
radioList?: boolean;
tag?: string;
activated?: boolean;
selected?: boolean;
ref?: React.Ref<any>;
initRipple?: (surface: T) => void;
}

export interface ListItemState {
Expand Down Expand Up @@ -87,9 +89,12 @@ export class ListItemBase<

componentDidMount() {
this.initializeTabIndex();
if (this.props.initRipple) {
this.props.initRipple(this.listItemElement.current as T);
}
}

componentDidUpdate(prevProps: ListItemProps) {
componentDidUpdate(prevProps: ListItemProps<T>) {
if (prevProps.tabIndex !== this.props.tabIndex) {
this.setState({tabIndex: this.props.tabIndex});
}
Expand Down Expand Up @@ -176,6 +181,7 @@ export class ListItemBase<
className,
children,
role,
initRipple,
checkboxList,
radioList,
onDestroy,
Expand Down Expand Up @@ -224,4 +230,5 @@ const ListItem: React.FunctionComponent<ListItemProps> = (props) => {
);
};

export default ListItem;
// export default ListItem;
export default withRipple<ListItemProps, HTMLElement>(ListItem);
1 change: 1 addition & 0 deletions packages/list/package.json
Expand Up @@ -20,6 +20,7 @@
"@material/list": "^1.0.0",
"@material/react-checkbox": "^0.10.0",
"@material/react-radio": "^0.10.0",
"@material/react-ripple": "^0.12.0",
"classnames": "^2.2.6",
"memoize-one": "^5.0.4",
"react": "^16.4.2"
Expand Down
9 changes: 8 additions & 1 deletion packages/menu/MenuListItem.tsx
Expand Up @@ -33,7 +33,14 @@ class MenuListItem<T extends HTMLElement = HTMLElement> extends React.Component<
{}
> {
render() {
const {role = 'menuitem', children, ...otherProps} = this.props;
const {
role = 'menuitem',
children,
/* eslint-disable no-unused-vars */
computeBoundingRect,
/* eslint-disable no-unused-vars */
...otherProps
} = this.props;

return (
<ListItem role={role} {...otherProps}>
Expand Down

0 comments on commit c0dfb94

Please sign in to comment.