Skip to content

Width for dropdown list and description labels #2050

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

Closed
jasongrout opened this issue Apr 16, 2018 · 11 comments
Closed

Width for dropdown list and description labels #2050

jasongrout opened this issue Apr 16, 2018 · 11 comments
Labels
resolved-locked Closed issues are locked after 30 days inactivity. Please open a new issue for related discussion.
Milestone

Comments

@jasongrout
Copy link
Member

From jasongrout/ipythonwidgets#2:

Hello,
I have been struggling for days on trying to find out a way to:

  1. adjusting the width of the dropdown list to the content of the list (long strings in my case);
  2. increasing the width of the description label (for RadioButtons) in order to see the label on one single line only.

I would be very grateful to receive your help.
Warm regards,
Graziella

@jasongrout
Copy link
Member Author

I appreciate you've been trying to figure this out yourself. Feel free to post a question before struggling for days - often a quick pointer from us can save you a lot of time!

For adusting the width of the dropdown, you can explicitly set the width, or you can set width to initial, which right now makes it expand to the width of the output:

from ipywidgets import *
Dropdown(layout={'width': 'initial'}, options=['very very very very very very very very very very very very very very long option', 'another option'])

For setting the width of the description label, you can set the description_width style attribute:

from ipywidgets import *
RadioButtons(description='Some long description', style={'description_width': 'initial'}, options=['a', 'b', 'c'])

(setting the description width is described in the docs at http://ipywidgets.readthedocs.io/en/latest/examples/Widget%20Styling.html#Description)

@moradza
Copy link

moradza commented Sep 3, 2019

Is there a way to decrease size of the options boxes? The boxes that I use is larger than what I need.
Example

widgets.Dropdown(
            options=[('Y', 1), ('X', 2)],
            value=1,
            description='Type:', style=style)

@jasongrout
Copy link
Member Author

Try this:

widgets.Dropdown(
            options=[('Y', 1), ('X', 2)],
            value=1,
            description='Type:', layout={'width': 'max-content'})

See https://developer.mozilla.org/en-US/docs/Web/CSS/width#max-content

@adam-ah
Copy link
Contributor

adam-ah commented Jan 13, 2020

@jasongrout thanks for the tip, this is what I was looking for.
Could we make layout={'width': 'max-content'} the default? I cannot imagine a scenario where a crippled radio button is better than a wide, readable one.
Thoughts?

@jasongrout
Copy link
Member Author

We've designed the widgets' widths so that they lay out nicely with each other for common cases (they all have approximately the same width), but made it possible to adjust that if necessary.

@adam-ah
Copy link
Contributor

adam-ah commented Jan 13, 2020

@jasongrout I can appreciate that, although some may argue that they are far too narrow for everyday use (in my case, more than half of the radio selectors I use get crippled due to width issue, even though my strings are not that long).

In any case, if the width is fixed, do you think it would be possible to add this layout={'width': 'max-content'} to the examples of radios/dropdowns so it's easier to find?

widgets.RadioButtons(
    options=['pepperoni', 'pineapple', 'anchovies'],
#    value='pineapple',
    description='Pizza topping:',
#    layout={'width': 'max-content'}, # Uncomment if your content gets wrapped
    disabled=False
)

I had to find this GitHub issue via Google to enable this easy fix, so I'm somewhat certain that others would be struggling with this too.

@jasongrout
Copy link
Member Author

do you think it would be possible to add this layout={'width': 'max-content'} to the examples of radios/dropdowns so it's easier to find?

Absolutely! We definitely need better documentation.

And we're open to redesigning how the widgets fit together, or re-examining the tradeoffs and compromises. It's just that a redesign should probably be done comprehensively so that things stay consistent with the overall design goals.

@jasongrout
Copy link
Member Author

do you think it would be possible to add this layout={'width': 'max-content'} to the examples of radios/dropdowns so it's easier to find?

Do you want to make a PR?

@adam-ah
Copy link
Contributor

adam-ah commented Jan 14, 2020

I was expecting that you would say that, @jasongrout :)
Done.

@vidartf
Copy link
Member

vidartf commented Jan 14, 2020

Is this closed by #2735 then?

@jasongrout
Copy link
Member Author

Yes, I think so. Thanks @adam-ah!

@lock lock bot added the resolved-locked Closed issues are locked after 30 days inactivity. Please open a new issue for related discussion. label May 20, 2020
@lock lock bot locked as resolved and limited conversation to collaborators May 20, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
resolved-locked Closed issues are locked after 30 days inactivity. Please open a new issue for related discussion.
Projects
None yet
Development

No branches or pull requests

4 participants