Skip to content

Commit 1c134c5

Browse files
committed
Make entire list items clickable.
1 parent f465b11 commit 1c134c5

File tree

2 files changed

+40
-20
lines changed

2 files changed

+40
-20
lines changed

demos/nextjs-supabase-todolist/src/components/widgets/ListItemWidget.tsx

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
import React from 'react';
2-
import { ListItem, IconButton, ListItemAvatar, Avatar, ListItemText, Box, Paper, styled } from '@mui/material';
2+
import {
3+
ListItem,
4+
IconButton,
5+
ListItemAvatar,
6+
Avatar,
7+
ListItemText,
8+
Box,
9+
Paper,
10+
styled,
11+
ListItemButton
12+
} from '@mui/material';
313

414
import DeleteIcon from '@mui/icons-material/DeleteOutline';
515
import RightIcon from '@mui/icons-material/ArrowRightAlt';
@@ -8,6 +18,7 @@ import ListIcon from '@mui/icons-material/ListAltOutlined';
818
export type ListItemWidgetProps = {
919
title: string;
1020
description: string;
21+
selected?: boolean;
1122
onDelete: () => void;
1223
onPress: () => void;
1324
};
@@ -16,6 +27,7 @@ export const ListItemWidget: React.FC<ListItemWidgetProps> = (props) => {
1627
return (
1728
<S.MainPaper elevation={1}>
1829
<ListItem
30+
disablePadding
1931
secondaryAction={
2032
<Box>
2133
<IconButton
@@ -39,12 +51,19 @@ export const ListItemWidget: React.FC<ListItemWidgetProps> = (props) => {
3951
</Box>
4052
}
4153
>
42-
<ListItemAvatar>
43-
<Avatar>
44-
<ListIcon />
45-
</Avatar>
46-
</ListItemAvatar>
47-
<ListItemText primary={props.title} secondary={props.description} />
54+
<ListItemButton
55+
onClick={(event) => {
56+
props.onPress();
57+
}}
58+
selected={props.selected}
59+
>
60+
<ListItemAvatar>
61+
<Avatar>
62+
<ListIcon />
63+
</Avatar>
64+
</ListItemAvatar>
65+
<ListItemText primary={props.title} secondary={props.description} />
66+
</ListItemButton>
4867
</ListItem>
4968
</S.MainPaper>
5069
);

demos/nextjs-supabase-todolist/src/components/widgets/TodoItemWidget.tsx

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react';
2-
import { ListItem, IconButton, ListItemAvatar, ListItemText, Box, styled, Paper } from '@mui/material';
2+
import { ListItem, IconButton, ListItemAvatar, ListItemText, Box, styled, Paper, ListItemButton } from '@mui/material';
33

44
import DeleteIcon from '@mui/icons-material/DeleteOutline';
55
import CheckBoxOutlineBlankIcon from '@mui/icons-material/CheckBoxOutlineBlank';
@@ -16,6 +16,7 @@ export const TodoItemWidget: React.FC<TodoItemWidgetProps> = (props) => {
1616
return (
1717
<S.MainPaper elevation={1}>
1818
<ListItem
19+
disablePadding
1920
secondaryAction={
2021
<Box>
2122
<IconButton
@@ -30,18 +31,18 @@ export const TodoItemWidget: React.FC<TodoItemWidgetProps> = (props) => {
3031
</Box>
3132
}
3233
>
33-
<ListItemAvatar>
34-
<IconButton
35-
edge="end"
36-
aria-label="toggle"
37-
onClick={() => {
38-
props.toggleCompletion();
39-
}}
40-
>
41-
{props.isComplete ? <CheckBoxIcon /> : <CheckBoxOutlineBlankIcon />}
42-
</IconButton>
43-
</ListItemAvatar>
44-
<ListItemText primary={props.description} />
34+
<ListItemButton
35+
onClick={() => {
36+
props.toggleCompletion();
37+
}}
38+
>
39+
<ListItemAvatar>
40+
<IconButton edge="end" aria-label="toggle">
41+
{props.isComplete ? <CheckBoxIcon /> : <CheckBoxOutlineBlankIcon />}
42+
</IconButton>
43+
</ListItemAvatar>
44+
<ListItemText primary={props.description} />
45+
</ListItemButton>
4546
</ListItem>
4647
</S.MainPaper>
4748
);

0 commit comments

Comments
 (0)