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.

custom icon for each option

See original GitHub issue

Hello I trying to make custom icon for any of option. http://prntscr.com/n0h6nk

maybe is there possibility to add third key in options array? Or any other possibility?

const statusOptions = [
    { value: 'notStarted', label: 'Nierozpoczęte', icon: 'someIcon' },
    { value: 'started', label: 'Rozpoczęte', icon: 'someIcon' }
];

I need same effect as in home libraby homepage, but my icons will be svg, or jpeg, or png https://react-select.com/home

pic for view => http://prntscr.com/n0u2p2

Thanks!

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:10

github_iconTop GitHub Comments

35reactions
ozgrozercommented, May 18, 2020

If you want to show custom icons both in options and selected value area you can use something like this.

import Select, { components } from 'react-select'

const { Option } = components
const CustomSelectOption = props => (
  <Option {...props}>
    <i className={`icon icon-${props.data.icon}`} />
    {props.data.label}
  </Option>
)

const CustomSelectValue = props => (
  <div>
    <i className={`icon icon-${props.data.icon}`} />
    {props.data.label}
  </div>
)

const options = [
  { value: 'item1', label: 'Item 1', icon: 'bar' },
  { value: 'item2', label: 'Item 2', icon: 'folder' }
]

<Select
  {...}
  options={options}
  components={{ Option: CustomSelectOption, SingleValue: CustomSelectValue }}
/>
32reactions
glapsablecommented, Apr 10, 2019

Hello, Yes, i made it:

You need to make custom component. I found solution in docs. My solution below:

const customSingleValue = ({ data }) => (
    <div className="input-select">
        <div className="input-select__single-value">
            { data.icon && <span className="input-select__icon">{ data.icon }</span> }
            <span>{ data.label }</span>
        </div>
    </div>
);
const statusOptions = [
    { value: "todo", label: "Nierozpoczęte", icon: <IconToDo/> },
    { value: "in_progress", label: "W toku", icon: <IconProgress/> },
    { value: "done", label: "Zalatwione", icon: <IconDone/> },
    { value: "rejected", label: "Odrzucone", icon: <IconRejected/> },
];
        <Select
            defaultValue={ statusOptions [0] }
            options={ statusOptions }
            styles={ selectCustomStyles }
            onChange={ changeSelectHandler }
            components={ {SingleValue: customSingleValue } }
        />

svg icons upload as React Components: import { ReactComponent as IconProgress } from “/icon_in_progress.svg”;

Read more comments on GitHub >

github_iconTop Results From Across the Web

Display custom icons alongside values in list views
This example displays custom icons in a view for the opportunity table, which is available with certain apps, such as Dynamics 365 Sales....
Read more >
How to Customize Any Icon in Windows 10 (or 11) - MakeUseOf
Then right-click each shortcut file, select Properties, and use the Change Icon button to select your new blank icon.
Read more >
Markers With Custom Icons - Leaflet - a JavaScript library for ...
Marker icons in Leaflet are defined by L.Icon objects, which are passed as an option when creating markers. Let's create a green leaf...
Read more >
How to add an icon to the options in react-select?
I found a workaround how to solve it. My technique is similar to @canda: import React, { Component } from "react"; import {...
Read more >
Icons with UI Widgets - Webix
Icons can be nested into all components and their items. ... You can also use any custom font icon pack in your Webix-based...
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