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

[Dropdown] Reset / Clear icon for Semantic UI single selection dropdown. #3635

Open
kmd1970 opened this issue Feb 1, 2016 · 13 comments
Open

Comments

@kmd1970
Copy link

kmd1970 commented Feb 1, 2016

I needed an easy way to clear a single selection dropdown, so I came up with this example (select an option, then click the remove icon on the left to clear the selected value) :

https://jsfiddle.net/kmd1970/hgufwj03/

I wish this feature was included in Semantic UI. Users need a way to clear/reset a non-required dropdown field.

@kmd1970
Copy link
Author

kmd1970 commented Feb 5, 2016

Yes, as shown in my example?

@jokeronaldo
Copy link
Member

Unusual but functional. Add to enhancement.

@xDaizu
Copy link

xDaizu commented Feb 18, 2016

It looks nice, could be useful as an option. I added a couple of suggestions to consider:

  1. The click event doesn't bubble so clearing doesnt open the select
$('.ui.dropdown .remove.icon').on('click', function(e){
      $(this).parent('.dropdown').dropdown('clear');
    console.log('clear');
    e.stopPropagation();
}); 
  1. new CSS rule so the x is not shown when nothing is selected
.ui.dropdown input[value=''] ~ .remove.icon, .ui.dropdown input:not([value]) ~ .remove.icon
{
   opacity: 0.0;
}

https://jsfiddle.net/dbr26njq/1/

@martin-koroudjiev
Copy link

Thanks for the work. I noticed it doesn't work if the dropdown is searchable so I added some CSS rules to move the search input a bit to the right and to align nicely the default text:

.ui.dropdown input.search {
  margin-left:15px;
}
.ui.dropdown .text.default{
  margin-left:-15px;
}
.ui.dropdown input[value=''] ~ input.search, .ui.dropdown input:not([value]) ~ input.search {
  margin-left:0;
}

I also added support when the dropdown is in loading state. The problem was that the CSS loading rules applied to both icons thus resulting in two spinning circles.

.ui.dropdown.loading .remove.icon:after, .ui.dropdown.loading .remove.icon:before {
  content:none;
}
.ui.dropdown.loading .text {
  margin-left:-15px;
}

https://jsfiddle.net/dbr26njq/3/

@GuillaumeSTEIN
Copy link

We definitively need this as an option :)

@kmd1970 kmd1970 changed the title Reset / Clear icon for Semantic UI single selection dropdown. [Dropdown] Reset / Clear icon for Semantic UI single selection dropdown. Feb 28, 2017
@larvanitis
Copy link

larvanitis commented Mar 15, 2017

I prefer it on the right side, before the dropdown icon. It simplifies the styling as well.

https://jsfiddle.net/dbr26njq/287/

Edit:
Even cleaner CSS https://jsfiddle.net/dbr26njq/288/

@musicao
Copy link

musicao commented Mar 24, 2017

Using only js/jquery
var elemento = $("idElementoSelect).next().next();
elemento.html('text';)

@dlynchcodes
Copy link

This is dope. I'm using this in my project. It would be very cool to have this as an official option.

@stale
Copy link

stale bot commented Apr 9, 2018

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 30 days if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Apr 9, 2018
@designosis
Copy link

Bump ... This is a necessary enhancement.

@stale stale bot removed the stale label Apr 10, 2018
@miguelcaravantes
Copy link

i wanna this feature too, something like react-select will be cool

@Dr-Horv
Copy link

Dr-Horv commented Sep 19, 2018

Has this been included in the react-version yet?

@lubber-de

This comment was marked as spam.

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

No branches or pull requests