question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItĀ collects links to all the places you might be looking at while hunting down a tough bug.

And, if youā€™re still stuck at the end, weā€™re happy to hop on a call to see how we can help out.

Support replacing icons in various elements

See original GitHub issue
  • I have searched the issues of this repository and believe that this is not a duplicate.

Summary šŸ’”

Some of the components in Material UI ship with built-in icons from the Material Design Icon set and only provide an option to replace them with other icons that donā€™t require a component as Font Awesome does.

Examples šŸŒˆ

In case of Font Awesome, the following would be required to render the icon, but Material UI doesnā€™t allow this.

<Select
  IconComponent={<FontAwesomeIcon icon={faChevronDown} />}
>

These are the places with the behavior Iā€™d expect:

  • Breadcrumbsā€™s seperator property
  • Buttonā€™s startIcon and endIcon property
  • BottomNavigationActionā€™s icon property
  • Tabā€™s icon property
  • AccordionSummaryā€™s expandIcon property
  • Chipā€™s icon and deleteIcon property

These components have icons that either can only be replaced with MUI icons or not at all:

  • StepLabel
  • Select
  • TablePagination

Iā€™m sure I missed of others.

Motivation šŸ”¦

We use MUI, but are not looking to have Material Design as our design system. Weā€™re now stuck with using 2 iconsets; the iconset we use everywhere (being Font Awesome), and the iconset used by Material UI-components that donā€™t allow for icons to be replaced.

My appologies if Iā€™m overlooking something here.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
Studio384commented, Sep 17, 2020

These components have icons that either can only be replaced with MUI icons or not at all:

  • StepLabel icon can be replaced with StepIconComponent prop.
  • Select icon can be replaced with IconComponent prop.
  • TablePagination icons can be replaced with the ActionsComponent prop.

Then Iā€™ve got to say that Iā€™m 100% lost and that this seems like a gap in MUIā€™s documentation on how to do that. Because in regards to Font Awesome; how would I do this? The example given above doesnā€™t work for Selectā€™s while it does work in the components listed in ā€œthese do workā€. This seems just inconsistent and could use some better documentation. Right now, MUI just shorts out with the following error:

Warning: Failed prop type: Invalid prop IconComponent of type object supplied to ForwardRef(Select), expected a single ReactElement type.

Which, of course, is correct. <FontAwesomeIcon /> isnā€™t a ReactElement but a node (which are allowed in the working examples given above) and that limitation currently doesnā€™t allow me to replace these icons with the iconset we use (this was perhaps poorly explained as the issue currently heavily implies that only MUI icons can be used).

0reactions
nuarhucommented, Aug 5, 2022

For anyone looking for a solution for using <FontAwesomeIcon /> as step icon - this might get you started. With these style settings it doesnā€™t look as good as with the default material icons, though.

import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import { faCheck } from '@fortawesome/free-solid-svg-icons/faCheck'
// ... other imports omitted

const SomeStep = () => {
  return (
    return (
      <Step active={false} index={2}>
        <StepLabel StepIconComponent={StepDoneIcon}>
          {title}
        </StepLabel>
        <StepContent>
          <Typography>
            Some Info
          </Typography>
        </StepContent>
      </Step>
    )
}


interface FAStepIconProps extends StepIconProps {
  faIcon: IconDefinition
}

const FAStepIcon = ({faIcon, active}: FAStepIconProps) => {
  const theme = useTheme()

  return (
    <Box sx={{
      backgroundColor: active ? theme.palette.primary.main : theme.palette.grey['300'],
      borderRadius: 9999,
      padding: '2px',
      ml: '-2px'
    }}>
      <FontAwesomeIcon color="white" fixedWidth size="lg" icon={faIcon} />
    </Box>
  )
}

const StepDoneIcon = (props: StepIconProps) => {
  return (
    <FAStepIcon {...props} faIcon={faCheck} />
  )
}

Read more comments on GitHub >

github_iconTop Results From Across the Web

Support replacing icons in various elements #22631 - GitHub
StepLabel icon can be replaced with StepIconComponent prop. Select icon can be replaced with IconComponent prop. TablePagination icons can beĀ ...
Read more >
Change icons for files or folders on Mac - Apple Support
In the Finder on your Mac, change the icon for any file or folder using your own pictures, icons from the web, or...
Read more >
Customizing Icons | Font Awesome Docs
CSS Custom Property Details Accepted Values ā€‘ā€‘faā€‘style Set Font Awesome icon style Any valid Font Awesome style weight ā€‘ā€‘faā€‘display Set display of an icon Any...
Read more >
Custom Icons (Pro) - Elementor
Upload your own custom icons to your website using Elementor Pro's Custom Icons feature. You can use Fontello, Icomoon, or Fontastic for the...
Read more >
How to change the order of custom icons? - WordPress.org
Hi, I added a Xing icon. How can I adjust the order of the icons? greeting Slawek. ... The page I need help...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found