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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove forced widths in order to get responsive dropdown menus #2091

Closed
wants to merge 4 commits into from

Conversation

elboletaire
Copy link

As the title suggests, I've removed the forced widths used when creating chosen objects. Now the width of the select menus depends on their wrapper.

I've uploaded it to gh-pages so you can see it working: http://elboletaire.github.io/chosen/

Obviously, resize the window to see it in action 馃槂

Now chosen is fully responsive. The input width comes from
their parent's width.

Cleaned up index files removing the old width behavior + styling
a little bit all that.
@albertboada
Copy link

needed!

@@ -44,7 +44,7 @@ $chosen-sprite-retina: image-url('chosen-sprite@2x.png') !default;
display: block;
overflow: hidden;
padding: 0 0 0 8px;
height: 25px;
// height: 25px;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why commenting this ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've commented it for testing purposes and I forgot to uncomment it. Removed on commit 626dd51

@dixhuit
Copy link

dixhuit commented Nov 3, 2014

+1 Would love to see this merged.

@dixhuit
Copy link

dixhuit commented Nov 4, 2014

Just tested this PR on a project and it works great. Thanks.

@cfbauer
Copy link

cfbauer commented Jan 3, 2015

Would love to see this merged, it allows us to use our own width where necessary. Works great applied manually.

@elboletaire
Copy link
Author

I would love it too... 馃槄

@joerideg
Copy link

Would love to see this merged. Style should not be determined via the js or html. At least set no width style by default if width is not provided as an option.

@pfiller
Copy link
Contributor

pfiller commented Mar 4, 2015

Chosen specifically tries to match the width of the select it's replacing. The reason for this is to match the behavior browsers exhibit when sizing selects (which is to make the select the appropriate width for the content). In most cases, we've preferred to keep Chosen's behavior in line with what the browser will do and width is not going to be an exception.

Browsers offer you a way to work around the default behavior by using css ... and so does Chosen! You can also specify a width for Chosen to use. If you'd like Chosen to be 100%, you just need to specify a width of 100%:

$("select").chosen({ width: '100%' });

Thanks, @elboletaire

Edit: Updated example to have quotes

@pfiller pfiller closed this Mar 4, 2015
@pfiller
Copy link
Contributor

pfiller commented Mar 4, 2015

The above example is missing quotes:

$("select").chosen({ width: '100%' });

@elboletaire
Copy link
Author

Well, that's not the answer I was looking for ... and I'm sure it's neither the solution for the people who commented this PR.

I'll do my own fork then. Thanks for your help :)

@cfbauer
Copy link

cfbauer commented Mar 5, 2015

@pfiller It's my understanding that Chosen sets widths inline. Is that correct? If so, setting the width with css would require the !important hack which isn't a good practice.

@cfbauer
Copy link

cfbauer commented Mar 5, 2015

To add: It's rare I would want to universally set the width of select boxes to 100%. Most of the time I would use media queries in css to make select boxes on mobile devices 100%, which would get tricky fast having to use !important.

@joerideg
Copy link

joerideg commented Mar 6, 2015

So @pfiller if chosen is trying to match the width of the select element, and width is not specitied in the options object, does that mean I can set width styles on the select with css and chosen will (on pageload) use that width?

@pfiller
Copy link
Contributor

pfiller commented Mar 6, 2015

It's my understanding that Chosen sets widths inline. Is that correct? If so, setting the width with css would require the !important hack which isn't a good practice.

You can set the width of the select in CSS and Chosen will try to match!

if chosen is trying to match the width of the select element, and width is not specitied in the options object, does that mean I can set width styles on the select with css and chosen will (on pageload) use that width?

Yes, as long as the width is in px. If you need a percentage width, you need to specify it in the options object.

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 this pull request may close these issues.

None yet

7 participants