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

fontSize style not applied on FontIcon inside a IconButton #4718

Closed
nzeugaa opened this issue Jul 14, 2016 · 15 comments
Closed

fontSize style not applied on FontIcon inside a IconButton #4718

nzeugaa opened this issue Jul 14, 2016 · 15 comments
Labels
component: icon button This is the name of the generic UI component, not the React module!

Comments

@nzeugaa
Copy link

nzeugaa commented Jul 14, 2016

Problem description

Hello everyone.
I have encountered a problem applying fontSize style on FontIcon. FontIcon is inside a IconButton.
The icon size is still the default size (24).

Steps to reproduce

import React, { Component } from 'react';
import IconButton from 'material-ui/IconButton';
import FontIcon from 'material-ui/FontIcon';

export default class Test extends Component {
  getStyles() {
    const styles = {
      iconStyles: {
        fontSize: 16,
      },
    };
    return styles;
  }

  render() {
    const styles = this.getStyles();
    return (
        <IconButton tooltip="Add">
          <FontIcon className="material-icons" style={styles.iconStyles}>add_box</FontIcon>
        </IconButton>
    );
  }
}

Versions

  • Material-UI: ^0.15.2
  • React: ^15.2.1
  • Browser: Chrome
@caseychoiniere
Copy link

caseychoiniere commented Jul 29, 2016

I found this looking for something else but I think I can answer your question. If you take a look at the docs for <IconButton /> it looks like you can change the size using the iconStyle property in addition to the style property. Like so.

const styles = {
  smallIcon: {
    width: 36,
    height: 36,
  },
  small: {
    width: 72,
    height: 72,
    padding: 16,
  },
};

const IconButtonExampleSize = () => (
  <div>
    <IconButton
      iconStyle={styles.smallIcon}
      style={styles.small}>
         <ActionHome />
    </IconButton>
  </div>
);

@nzeugaa
Copy link
Author

nzeugaa commented Aug 1, 2016

@caseychoiniere This will works only for SVG icons but not for Font icons. FontIcon has a fontSize attribute but this attribute is ignored when FontIcon is a child of IconButton. Anyway the workaround is to use SVG icons like y've described.

@mpontikes mpontikes mentioned this issue Aug 5, 2016
13 tasks
@jsamr
Copy link

jsamr commented Aug 17, 2016

+1, this is quite frustrating! Thanks tho' for the amazing job.

@aahan96
Copy link
Contributor

aahan96 commented Aug 17, 2016

Looks like we can close this issue

@aahan96 aahan96 closed this as completed Aug 17, 2016
@caseychoiniere
Copy link

Has it been fixed?

@jsamr
Copy link

jsamr commented Aug 17, 2016

I am still having the issue with react 15.3.0 and material-ui 0.15.4

@nzeugaa
Copy link
Author

nzeugaa commented Aug 18, 2016

@aahan96 Please re-open this issue since it's not already fixed.

@MaffooBristol
Copy link

The docs themselves at http://www.material-ui.com/#/components/raised-button list the following code:

import FontIcon from 'material-ui/FontIcon';
<RaisedButton
      href="https://github.com/callemall/material-ui"
      target="_blank"
      secondary={true}
      icon={<FontIcon className="muidocs-icon-custom-github" />}
      style={style}
/>

And yet it doesn't work and there's nothing explaining how to get it to work. The <FontIcon> element seems to not even add the required font-family attribute for icons to work if manually adding them to the head, either.

@MaffooBristol
Copy link

Including the font css then makes it work with icon={<i className="material-icons">edit</i>}, however it doesn't inherit the same colour as the text along with it, which is problematic with theming. Adding it directly into the label is not very accessible and causing styling issues.

Basically, the way the docs describe it, this should be super easy and require no extra work, yet there are several threads about this spanning years that have people in it who are completely lost!

@ts-ign0re
Copy link

@aahan96 not fixed. Reopen issues, plz.

@je553
Copy link

je553 commented Jun 1, 2017

Also voting to reopen the issue. For now I copied the FontIcon component and referenced it in my own project rather than material-ui, and I've just passed getStyles a fontSize prop that it puts in its root styling if it exists, else use the default.

function getStyles(props, context, state) {
    const {color, hoverColor, fontSize} = props;

    const {baseTheme} = context.muiTheme;
    const offColor = color || baseTheme.palette.textColor;
    const onColor = hoverColor || offColor;

    return {
        root: {
            color: state.hovered
                ? onColor
                : offColor,
            position: 'relative',
            fontSize: fontSize || baseTheme.spacing.iconSize,
            display: 'inline-block',
            userSelect: 'none',
            transition: transitions.easeOut()
        }
    };
}

@mbrookes
Copy link
Member

mbrookes commented Jun 1, 2017

Not sure why this was ever closed. @aahan96?

Preaching to the choir, but - the best way to get an issue fixed is (after discussing your approach) to submit a PR.

@mbrookes mbrookes reopened this Jun 1, 2017
@jgreubel
Copy link

jgreubel commented Jun 5, 2017

I still agree that FontIcon's style prop should still be the ideal way to set the FontIcon's style inside of a IconButton, however we were able to get the FontIcon size working properly on our project like this:

<IconButton
    onTouchTap={this.handleTouchTap}
    iconStyle={{fontSize: '18px'}}>

        <FontIcon className="fa fa-filter" color={accentBlue}/>

</IconButton>

Material-UI v0.18.0

@chalisegrogan
Copy link

Thank you @jgreubel! That workaround is rather simple and gets the job done.

@oliviertassinari
Copy link
Member

We have been porting the component on the v1-beta branch. We reimplemented it from the ground-up. While we haven't tested it, I think that the issue is most likely fixed on that branch. Hence, I'm closing it.
Still, we will accept PR fixes until v1-beta takes over the master branch.

@oliviertassinari oliviertassinari added the component: icon button This is the name of the generic UI component, not the React module! label Jul 28, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: icon button This is the name of the generic UI component, not the React module!
Projects
None yet
Development

No branches or pull requests