forked from mui/material-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BottomNavigation] onClick does not fire if tapped while scrolling (m…
- Loading branch information
1 parent
394f214
commit 0652c2c
Showing
7 changed files
with
506 additions
and
25 deletions.
There are no files selected for viewing
121 changes: 121 additions & 0 deletions
121
docs/src/pages/components/bottom-navigation/FixedBottomNavigation.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
/* eslint-disable @typescript-eslint/no-use-before-define */ | ||
import React from 'react'; | ||
import { makeStyles } from '@material-ui/core/styles'; | ||
import CssBaseline from '@material-ui/core/CssBaseline'; | ||
import BottomNavigation from '@material-ui/core/BottomNavigation'; | ||
import BottomNavigationAction from '@material-ui/core/BottomNavigationAction'; | ||
import RestoreIcon from '@material-ui/icons/Restore'; | ||
import FavoriteIcon from '@material-ui/icons/Favorite'; | ||
import ArchiveIcon from '@material-ui/icons/Archive'; | ||
import Paper from '@material-ui/core/Paper'; | ||
import List from '@material-ui/core/List'; | ||
import ListItem from '@material-ui/core/ListItem'; | ||
import ListItemAvatar from '@material-ui/core/ListItemAvatar'; | ||
import ListItemText from '@material-ui/core/ListItemText'; | ||
import Avatar from '@material-ui/core/Avatar'; | ||
|
||
const useStyles = makeStyles({ | ||
root: { | ||
paddingBottom: 56, | ||
}, | ||
bottomNav: { | ||
position: 'fixed', | ||
bottom: 0, | ||
left: 0, | ||
right: 0, | ||
}, | ||
}); | ||
|
||
function refreshMessages() { | ||
const getRandomInt = (max) => Math.floor(Math.random() * Math.floor(max)); | ||
|
||
return Array.from(new Array(50)).map( | ||
() => messageExamples[getRandomInt(messageExamples.length)], | ||
); | ||
} | ||
|
||
export default function FixedBottomNavigation() { | ||
const classes = useStyles(); | ||
const [value, setValue] = React.useState(0); | ||
const ref = React.useRef(null); | ||
const [messages, setMessages] = React.useState(() => refreshMessages()); | ||
|
||
React.useEffect(() => { | ||
ref.current.ownerDocument.body.scrollTop = 0; | ||
setMessages(refreshMessages()); | ||
}, [value, setMessages]); | ||
|
||
return ( | ||
<div className={classes.root} ref={ref}> | ||
<CssBaseline /> | ||
<List> | ||
{messages.map(({ primary, secondary, person }, index) => ( | ||
<ListItem button key={index + person}> | ||
<ListItemAvatar> | ||
<Avatar alt="Profile Picture" src={person} /> | ||
</ListItemAvatar> | ||
<ListItemText primary={primary} secondary={secondary} /> | ||
</ListItem> | ||
))} | ||
</List> | ||
<Paper elevation={3} className={classes.bottomNav}> | ||
<BottomNavigation | ||
showLabels | ||
value={value} | ||
onChange={(event, newValue) => { | ||
setValue(newValue); | ||
}} | ||
> | ||
<BottomNavigationAction label="Recents" icon={<RestoreIcon />} /> | ||
<BottomNavigationAction label="Favorites" icon={<FavoriteIcon />} /> | ||
<BottomNavigationAction label="Archive" icon={<ArchiveIcon />} /> | ||
</BottomNavigation> | ||
</Paper> | ||
</div> | ||
); | ||
} | ||
|
||
const messageExamples = [ | ||
{ | ||
primary: 'Brunch this week?', | ||
secondary: | ||
"I'll be in the neighbourhood this week. Let's grab a bite to eat", | ||
person: '/static/images/avatar/5.jpg', | ||
}, | ||
{ | ||
primary: 'Birthday Gift', | ||
secondary: `Do you have a suggestion for a good present for John on his work | ||
anniversary. I am really confused & would love your thoughts on it.`, | ||
person: '/static/images/avatar/1.jpg', | ||
}, | ||
{ | ||
primary: 'Recipe to try', | ||
secondary: | ||
'I am try out this new BBQ recipe, I think this might be amazing', | ||
person: '/static/images/avatar/2.jpg', | ||
}, | ||
{ | ||
primary: 'Yes!', | ||
secondary: 'I have the tickets to the ReactConf for this year.', | ||
person: '/static/images/avatar/3.jpg', | ||
}, | ||
{ | ||
primary: "Doctor's Appointment", | ||
secondary: | ||
'My appointment for the doctor was rescheduled for next Saturday.', | ||
person: '/static/images/avatar/4.jpg', | ||
}, | ||
{ | ||
primary: 'Discussion', | ||
secondary: `Menus that are generated by the bottom app bar (such as a bottom | ||
navigation drawer or overflow menu) open as bottom sheets at a higher elevation | ||
than the bar.`, | ||
person: '/static/images/avatar/5.jpg', | ||
}, | ||
{ | ||
primary: 'Summer BBQ', | ||
secondary: `Who wants to have a cookout this weekend? I just got some furniture | ||
for my backyard and would love to fire up the grill.`, | ||
person: '/static/images/avatar/1.jpg', | ||
}, | ||
]; |
128 changes: 128 additions & 0 deletions
128
docs/src/pages/components/bottom-navigation/FixedBottomNavigation.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
/* eslint-disable @typescript-eslint/no-use-before-define */ | ||
import React from 'react'; | ||
import { makeStyles } from '@material-ui/core/styles'; | ||
import CssBaseline from '@material-ui/core/CssBaseline'; | ||
import BottomNavigation from '@material-ui/core/BottomNavigation'; | ||
import BottomNavigationAction from '@material-ui/core/BottomNavigationAction'; | ||
import RestoreIcon from '@material-ui/icons/Restore'; | ||
import FavoriteIcon from '@material-ui/icons/Favorite'; | ||
import ArchiveIcon from '@material-ui/icons/Archive'; | ||
import Paper from '@material-ui/core/Paper'; | ||
import List from '@material-ui/core/List'; | ||
import ListItem from '@material-ui/core/ListItem'; | ||
import ListItemAvatar from '@material-ui/core/ListItemAvatar'; | ||
import ListItemText from '@material-ui/core/ListItemText'; | ||
import Avatar from '@material-ui/core/Avatar'; | ||
|
||
const useStyles = makeStyles({ | ||
root: { | ||
paddingBottom: 56, | ||
}, | ||
bottomNav: { | ||
position: 'fixed', | ||
bottom: 0, | ||
left: 0, | ||
right: 0, | ||
}, | ||
}); | ||
|
||
function refreshMessages(): MessageExample[] { | ||
const getRandomInt = (max: number) => | ||
Math.floor(Math.random() * Math.floor(max)); | ||
|
||
return Array.from(new Array(50)).map( | ||
() => messageExamples[getRandomInt(messageExamples.length)], | ||
); | ||
} | ||
|
||
export default function FixedBottomNavigation() { | ||
const classes = useStyles(); | ||
const [value, setValue] = React.useState(0); | ||
const ref = React.useRef<HTMLDivElement>(null); | ||
const [messages, setMessages] = React.useState(() => refreshMessages()); | ||
|
||
React.useEffect(() => { | ||
(ref.current as HTMLDivElement).ownerDocument.body.scrollTop = 0; | ||
setMessages(refreshMessages()); | ||
}, [value, setMessages]); | ||
|
||
return ( | ||
<div className={classes.root} ref={ref}> | ||
<CssBaseline /> | ||
<List> | ||
{messages.map(({ primary, secondary, person }, index) => ( | ||
<ListItem button key={index + person}> | ||
<ListItemAvatar> | ||
<Avatar alt="Profile Picture" src={person} /> | ||
</ListItemAvatar> | ||
<ListItemText primary={primary} secondary={secondary} /> | ||
</ListItem> | ||
))} | ||
</List> | ||
<Paper elevation={3} className={classes.bottomNav}> | ||
<BottomNavigation | ||
showLabels | ||
value={value} | ||
onChange={(event, newValue) => { | ||
setValue(newValue); | ||
}} | ||
> | ||
<BottomNavigationAction label="Recents" icon={<RestoreIcon />} /> | ||
<BottomNavigationAction label="Favorites" icon={<FavoriteIcon />} /> | ||
<BottomNavigationAction label="Archive" icon={<ArchiveIcon />} /> | ||
</BottomNavigation> | ||
</Paper> | ||
</div> | ||
); | ||
} | ||
|
||
interface MessageExample { | ||
primary: string; | ||
secondary: string; | ||
person: string; | ||
} | ||
|
||
const messageExamples: MessageExample[] = [ | ||
{ | ||
primary: 'Brunch this week?', | ||
secondary: | ||
"I'll be in the neighbourhood this week. Let's grab a bite to eat", | ||
person: '/static/images/avatar/5.jpg', | ||
}, | ||
{ | ||
primary: 'Birthday Gift', | ||
secondary: `Do you have a suggestion for a good present for John on his work | ||
anniversary. I am really confused & would love your thoughts on it.`, | ||
person: '/static/images/avatar/1.jpg', | ||
}, | ||
{ | ||
primary: 'Recipe to try', | ||
secondary: | ||
'I am try out this new BBQ recipe, I think this might be amazing', | ||
person: '/static/images/avatar/2.jpg', | ||
}, | ||
{ | ||
primary: 'Yes!', | ||
secondary: 'I have the tickets to the ReactConf for this year.', | ||
person: '/static/images/avatar/3.jpg', | ||
}, | ||
{ | ||
primary: "Doctor's Appointment", | ||
secondary: | ||
'My appointment for the doctor was rescheduled for next Saturday.', | ||
person: '/static/images/avatar/4.jpg', | ||
}, | ||
{ | ||
primary: 'Discussion', | ||
secondary: `Menus that are generated by the bottom app bar (such as a bottom | ||
navigation drawer or overflow menu) open as bottom sheets at a higher elevation | ||
than the bar.`, | ||
person: '/static/images/avatar/5.jpg', | ||
}, | ||
{ | ||
primary: 'Summer BBQ', | ||
secondary: `Who wants to have a cookout this weekend? I just got some furniture | ||
for my backyard and would love to fire up the grill.`, | ||
person: '/static/images/avatar/1.jpg', | ||
}, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.