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

Icon for the selected option is not shown in selection Dropdowns #4346

Open
mfen opened this issue Mar 22, 2022 · 3 comments · May be fixed by #4347
Open

Icon for the selected option is not shown in selection Dropdowns #4346

mfen opened this issue Mar 22, 2022 · 3 comments · May be fixed by #4347

Comments

@mfen
Copy link

mfen commented Mar 22, 2022

Bug Report

Steps

  • Create a <Dropdown selection /> with icon set in the options.
  • Select an option (or pass in a controlled selected value).

Expected Result

The icon for the selected option should be displayed to the left of the Dropdown text, similar to how it is shown in the dropdown menu items or how the Flag or Image for a selected option is shown.

Actual Result

No icon is shown for the selected option in the collapsed Dropdown, only the option's text is shown.

Version

2.1.2

Testcase

https://codesandbox.io/s/semantic-ui-react-forked-g2lci9

This is essentially the same issue as #1147, but that issue seems to have been mistakenly closed with #4003. While the original #3980 had included support for Icons alongside Flags and Images, the code for Icon support was omitted in this eventual commit of #4003 (@layershifter).

@welcome
Copy link

welcome bot commented Mar 22, 2022

👋 Thanks for opening your first issue here! If you're reporting a 🐞 bug, please make sure you've completed all the fields in the issue template so we can best help.

We get a lot of issues on this repo, so please be patient and we will get back to you as soon as we can.

Fox32 added a commit to Fox32/Semantic-UI-React that referenced this issue Mar 24, 2022
Fox32 added a commit to Fox32/Semantic-UI-React that referenced this issue Mar 24, 2022
@Fox32
Copy link

Fox32 commented Mar 24, 2022

Just came along the same issue today, so I created #4347

@Fox32
Copy link

Fox32 commented Mar 24, 2022

Btw, there is a possible workaround:

  1. You can extend the option text to include the icon:
        {
          key: 'my-user',
          text: (
            <>
              <Icon name="user" />
              My User
            </>
          ),
          searchText: 'My User',
          value: 'my-user',
        },
  1. However, this breaks search. That's why I added a custom searchText field in the option and included custom search function in the <Dropdown>:
<Dropdown
  options={options}
  search={(options, query) => {
    const re = new RegExp(escapeRegExp(query), 'i');
    return options.filter((opt) => re.test(opt.searchText));
  }}
  

This is cumbersome, but an option for everyone that can't wait for a fix 😉.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants