-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SpeedDial] Allow tooltip to always be displayed #12590
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
549fb8d
Allow tooltip to always be displayed
hashwin 85de5ad
Run auto docs and prettier
hashwin c0724f8
Review fixes
hashwin 7167178
Add documentation
hashwin 6c2335f
Update docs
hashwin 916dccb
Full yarn run prettier to fix tests
hashwin fb70993
Merge branch 'master' into hashwin/alwaysDisplayTooltip
hashwin 1eb1068
Merge remote-tracking branch 'upstream/master' into hashwin/alwaysDis…
hashwin 589de75
Update doc
hashwin 5292527
Use getDerivedStateFromProps for closing tooltip
hashwin 9d463dc
prettier
hashwin fe60a87
Merge remote-tracking branch 'upstream/master' into hashwin/alwaysDis…
hashwin 645a59e
Better doc note
hashwin 82dffc2
Review fixes
hashwin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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,110 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { withStyles } from '@material-ui/core/styles'; | ||
import Button from '@material-ui/core/Button'; | ||
import SpeedDial from '@material-ui/lab/SpeedDial'; | ||
import SpeedDialIcon from '@material-ui/lab/SpeedDialIcon'; | ||
import SpeedDialAction from '@material-ui/lab/SpeedDialAction'; | ||
import FileCopyIcon from '@material-ui/icons/FileCopyOutlined'; | ||
import SaveIcon from '@material-ui/icons/Save'; | ||
import PrintIcon from '@material-ui/icons/Print'; | ||
import ShareIcon from '@material-ui/icons/Share'; | ||
import DeleteIcon from '@material-ui/icons/Delete'; | ||
|
||
const styles = theme => ({ | ||
root: { | ||
height: 380, | ||
}, | ||
speedDial: { | ||
position: 'absolute', | ||
bottom: theme.spacing.unit * 2, | ||
right: theme.spacing.unit * 3, | ||
}, | ||
}); | ||
|
||
const actions = [ | ||
{ icon: <FileCopyIcon />, name: 'Copy' }, | ||
{ icon: <SaveIcon />, name: 'Save' }, | ||
{ icon: <PrintIcon />, name: 'Print' }, | ||
{ icon: <ShareIcon />, name: 'Share' }, | ||
{ icon: <DeleteIcon />, name: 'Delete' }, | ||
]; | ||
|
||
class SpeedDialTooltipOpen extends React.Component { | ||
state = { | ||
open: false, | ||
hidden: false, | ||
}; | ||
|
||
handleVisibility = () => { | ||
this.setState(state => ({ | ||
open: false, | ||
hidden: !state.hidden, | ||
})); | ||
}; | ||
|
||
handleClick = () => { | ||
this.setState(state => ({ | ||
open: !state.open, | ||
})); | ||
}; | ||
|
||
handleOpen = () => { | ||
if (!this.state.hidden) { | ||
this.setState({ | ||
open: true, | ||
}); | ||
} | ||
}; | ||
|
||
handleClose = () => { | ||
this.setState({ | ||
open: false, | ||
}); | ||
}; | ||
|
||
render() { | ||
const { classes } = this.props; | ||
const { hidden, open } = this.state; | ||
|
||
let isTouch; | ||
if (typeof document !== 'undefined') { | ||
isTouch = 'ontouchstart' in document.documentElement; | ||
} | ||
|
||
return ( | ||
<div className={classes.root}> | ||
<Button onClick={this.handleVisibility}>Toggle Speed Dial</Button> | ||
<SpeedDial | ||
ariaLabel="SpeedDial example" | ||
className={classes.speedDial} | ||
hidden={hidden} | ||
icon={<SpeedDialIcon />} | ||
onBlur={this.handleClose} | ||
onClick={this.handleClick} | ||
onClose={this.handleClose} | ||
onFocus={isTouch ? undefined : this.handleOpen} | ||
onMouseEnter={isTouch ? undefined : this.handleOpen} | ||
onMouseLeave={this.handleClose} | ||
open={open} | ||
> | ||
{actions.map(action => ( | ||
<SpeedDialAction | ||
key={action.name} | ||
icon={action.icon} | ||
tooltipTitle={action.name} | ||
tooltipOpen | ||
onClick={this.handleClick} | ||
/> | ||
))} | ||
</SpeedDial> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
SpeedDialTooltipOpen.propTypes = { | ||
classes: PropTypes.object.isRequired, | ||
}; | ||
|
||
export default withStyles(styles)(SpeedDialTooltipOpen); |
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
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hashwin I was just looking at this and this seems brittle since other methods can still change the state of tooltipOpen. Not sure if we can do anything about this though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see your point, but yeah I don't really see another way of handling this without the state and state itself can be changed from anywhere in the component. In fact, we need to manually set the state here for this feature to work: https://github.com/mui-org/material-ui/pull/12590/files#diff-3c8c197bf9114d5f5a42f05daae04497R59
One thing we can maybe do here is to change the method name from
handleTooltipOpen
to something likeonHover
so that it explicitly says that nothing should be done on hover if the proptooltipOpen
is given. Thoughts?