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.

Can't use IconComponent to set a custom icon for Select Components

See original GitHub issue

I am trying to change the default icon used for a select drop down by setting IconComponent to a string in the props for the select component but I get the error: React does not recognize the IconComponent prop on a DOM element. If you intentionally want it to appear in the DOM as a custom attribute, spell it as lowercase iconcomponent instead. If you accidentally passed it from a parent component, remove it from the DOM element.

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

Expected Behavior

The icon should get set to the icon provided in the props.

Current Behavior

I get the error: React does not recognize the IconComponent prop on a DOM element. If you intentionally want it to appear in the DOM as a custom attribute, spell it as lowercase iconcomponent instead. If you accidentally passed it from a parent component, remove it from the DOM element.

Steps to Reproduce (for bugs)

const selectFieldProps = {
      autoWidth: true,
      IconComponent: "<i className='material-icons'>more_vert</i>"
}
<Select
   value={this.state.depth} 
   onChange={this.handleChange}
   inputProps={{
      name: "depth",
      id: "depth"
    }}
    {...selectFieldProps}
>
    {children}
</Select>

Context

Your Environment

Tech Version
Material-UI v1.0.0-rc.0
React 16.3.2
browser Chrome 66.0.3

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

24reactions
oliviertassinaricommented, May 14, 2018

@UsamaHameed Your example is incorrect. Please ask this type of question on StackOverflow. You need to provide a React component not a React element. Something like:

      <Select
        IconComponent={props => (
          <i {...props} className={`material-icons ${props.className}`}>
            more_vert
          </i>
        )}

capture d ecran 2018-05-14 a 19 30 43

https://codesandbox.io/s/km61o51785

16reactions
paddotkcommented, Jun 12, 2019

I have the same issue. I think the documentation isn’t clear enough as to what is expected; what is meant by elementType exactly? I’d expect to be able to use something like a custom SVG icon but that does not work. @oliviertassinari I’ve tried your example too, doesn’t work either.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can't use IconComponent to set a custom icon for Select ...
I am trying to change the default icon used for a select drop down by setting IconComponent to a string in the props...
Read more >
Select is not working onClick IconComponent(dropdown ...
In SelectInput.js (which Select leverages) the icon is rendered as follows: <IconComponent className={classes.icon} />.
Read more >
Icon - Chakra UI
Chakra provides two methods for creating your custom icons: Using the Icon component; Using the createIcon function. They can be imported from @chakra-ui/react ......
Read more >
How To Use Font Awesome icons in Angular Applications
In this tutorial I will explain how to use Font Awesome icons in Angular applications using @fortawesome/angular-fontawesome package.
Read more >
Creating Custom Icon Fonts in React Native and Expo
Icon fonts are still a great choice for large-scale custom icon sets to scale over time. They: Automatically scale. Can be referenced directly ......
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