Skip to content
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

[Tooltip] Expose Composable Tooltip component #2230

Closed
1 task
SPAHI4 opened this issue Nov 20, 2015 · 32 comments
Closed
1 task

[Tooltip] Expose Composable Tooltip component #2230

SPAHI4 opened this issue Nov 20, 2015 · 32 comments
Labels
component: tooltip This is the name of the generic UI component, not the React module! new feature New feature or request

Comments

@SPAHI4
Copy link

SPAHI4 commented Nov 20, 2015

Where i can find example of usage tooltip component without icon-button?

@alitaheri
Copy link
Member

Tooltip isn't documented. That means it's Implementation Detail. In other words, it can change api as frequently as the other components might need features from it. Use it at you own risk.
But if you're ok with that the code from icon-button might help.

@oliviertassinari
Copy link
Member

That's true. I think that exposing a composable Tooltip component would be great.
But that will require some work.

@evelant
Copy link

evelant commented Jan 6, 2016

+1 for exposing a composable tooltip component.

In the mean time here is some rough code I made from pulling apart icon-button. Entirely untested but seems to work in basic cases in my app.

Tooltip = React.createClass({
    propTypes: {
        tooltip: React.PropTypes.string,
        tooltipPosition: React.PropTypes.string,
        tooltipStyles: React.PropTypes.object,
        touch: React.PropTypes.bool
    },
    getDefaultProps(){
        return {
            tooltipPosition: 'bottom-center'
        };
    },
    getInitialState(){
        return{
            tooltipShown: false
        };
    },
    getStyles() {
        let styles = {
            root: {
                position: 'relative',
                boxSizing: 'border-box'
            },
            tooltip: {
                boxSizing: 'border-box'
            }
        };
        return styles;
    },

    _showTooltip() {
        this.setState({tooltipShown: true});
    },

    _hideTooltip() {
        this.setState({tooltipShown: false});
    },

    _handleBlur(e) {
        this._hideTooltip();
        if (this.props.onBlur) this.props.onBlur(e);
    },

    _handleFocus(e) {
        this._showTooltip();
        if (this.props.onFocus) this.props.onFocus(e);
    },

    _handleMouseLeave(e) {
        this._hideTooltip();
        if (this.props.onMouseLeave) this.props.onMouseLeave(e);
    },

    _handleMouseEnter(e) {
        this._showTooltip();
        if (this.props.onMouseEnter) this.props.onMouseEnter(e);
    },
    mergeStyles(obj1, obj2){
        for (var attrname in obj2) { obj1[attrname] = obj2[attrname]; }
        return obj1;
    },
    render(){
        let {
            tooltip,
            touch,
            ...other,
            } = this.props;
        let tooltipPosition = this.props.tooltipPosition.split('-');
        let styles = this.getStyles();
        return(
            <div
                style={this.mergeStyles(styles.root, this.props.style)}
                onBlur={this._handleBlur}
                onFocus={this._handleFocus}
                onMouseLeave={this._handleMouseLeave}
                onMouseEnter={this._handleMouseEnter}>

                <MUI.Tooltip
                    ref="tooltip"
                    label={tooltip}
                    show={this.state.tooltipShown}
                    touch={touch}
                    style={this.mergeStyles(styles.tooltip, this.props.tooltipStyles)}
                    verticalPosition={tooltipPosition[0]}
                    horizontalPosition={tooltipPosition[1]}/>
                {this.props.children}
            </div>
        );

    }
});

@newoga newoga changed the title how to use tooltip? [Tooltip] Expose Composable Tooltip component Jan 9, 2016
@andrejunges
Copy link
Contributor

Wouldn't be better we use the Popover component to display the tooltip?
I had cases where the tooltips were being hidden per other absolute components (Header)..

@alitaheri
Copy link
Member

It would be better indeed. Care to submit a PR? 😁

@andrejunges
Copy link
Contributor

I'm gonna try to work on it over the weekend

@oliviertassinari
Copy link
Member

I'm not sure using Popover is a good idea. That seems overkill. RenderToLayer would be better.
They seems to have an interesting solution https://github.com/react-toolbox/react-toolbox/blob/dev/components/tooltip/Tooltip.jsx.

@kybarg
Copy link
Contributor

kybarg commented Mar 8, 2017

Has somebody started on porting it to next? How about this repo as example?

@kazazor
Copy link
Contributor

kazazor commented Jun 18, 2017

Same here, in the 0.18.3 version I had a tool tip on a TableHeader component which was great! Now I cannot display my tooltips in an easy way :/

@IzaGz
Copy link

IzaGz commented Sep 23, 2017

Its a shame such widely used repo, and such necessary thing as tooltip still doesn't work currently! Maybe someone can fix and commit it to make it work!? also tooltips does not work on popup menus. nothing helps(

@oliviertassinari
Copy link
Member

@IzaGz Haters are always the sign that a project is successful. Also, you can find the Tooltip component on the v1-beta branch.

@rodrigocfd
Copy link

Just in case anyone is still struggling with this, I created a component wrapper that solved my problem of having a tooltip in a FAB. I'm sharing it here if anyone is interested.

melissachang added a commit to DataBiosphere/data-explorer that referenced this issue Mar 30, 2018
FAB tooltips aren't implemented until Material v1
(mui/material-ui#2230 (comment))
so let's leave out tooltip for now.
melissachang added a commit to DataBiosphere/data-explorer that referenced this issue Mar 31, 2018
FAB tooltips aren't implemented until Material v1
(mui/material-ui#2230 (comment))
so let's leave out tooltip for now.
@oliviertassinari oliviertassinari added the component: tooltip This is the name of the generic UI component, not the React module! label Aug 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: tooltip This is the name of the generic UI component, not the React module! new feature New feature or request
Projects
None yet
Development

No branches or pull requests