views:

1147

answers:

7

What kinds of options do I have when a dropdown menu is faced with text that is so wide that extending the menu's width to accommodate is not feasible? i.e. It breaks the page layout, or just looks too ugly if the dropdown is adjusted to fit the long item.

Truncation? Truncation plus full hover text? Don't allow items that long?

Anyone encountered any elegant solutions to this?

Thanks.

A: 

I've been using commercial ASP.NET control that is implemented using <div> rather than <select>. This way we could put multiline elements on it, style it as we wanted and do some other stuff.

Migol
+2  A: 

Truncation with tooltip would be my choice....

The last time i had to do that i used a telerik control, which was quite UI rich.

GordonB
+1  A: 

Most browsers show the options at full width regardless of the dropdown's actual width whereas IE crops them to the width of the select box. So the problem is really browser specific.

I've made a solution using absolute positioning on the dropdown so that I could extend it's width on hover in IE without breaking my layout. A bit hacky but it's one option.

sanchothefat
+1  A: 

I agree with GordonB regarding truncating the options. Excessively long options can be hard to read, and as you mentioned it looks horrible.

If your dropdown is populated from user input, however, I'd restrict the length. What can be said with 15 words should be said with 5 ... if it can't, then perhaps a dropdown isn't your best option.

For example, if your options are the titles of research papers and their authors, you can probably abbreviate them down to a few key words ("String Theory and You [Brown 2008]"). On the other hand, if the options themselves differ by only a few words and lose meaning if they are truncated (e.g. a list of options like "Peanut butter and grape jelly sandwich with carrot sticks and soy milk" and "Peanut butter and boysenberry jelly sandwith with carrot sticks and 2% milk") maybe you would be better served by displaying all the options sequentially, accompanied by a checkbox or radio button as appropriate.

(If you're using ASP.NET, basically I'm saying using a repeater instead of a DropDownList)

This second approach might also allow you to incorporate other elements that you wouldn't be able to in a dropdown. Take a look at this Amazon search result page for ideas.

Cal Jacobson
Thanks! The dropdown text is from user input, so barring some flash of insight, it looks like I'll have to use truncation or length restriction...or both.
ntownsend
A: 

Depends how wide you are talking, what the context is. Often this comes down to a design problem rather than a coding problem. If the text is really long you will have usability problems regardless because reading long text in a dropdown is difficult. My options would be:

If the dropdown is really narrow and the longest items aren't very long (eg 3-4 words) change the design to accommodate it.

If the text is really long (eg sentences) then truncate it if you can. Sometimes text isn't amenable to this (eg. you may end up with multiple items with the same text). You can't really put tooltips on select list items.

If the text is really long and can't be truncated, you may want to consider a different UI option.

mdja
A: 

Give the element a maximum width with the CSS property max-width.

Gumbo
+1  A: 

I realise I'm fairly late to this question, but I've been hunting for an answer and I may have found a fairly elegant solution.

Have a look here:

The first link talks about a couple of solutions before recommending a solution based on the second link.

The idea is that on click, you change the width of the <select> tag such that it is big enough to show the full text of the options. By keeping the <select> tag inside a div with overflow set to 'hidden', it doesn't screw with the rest of the page.

Try it out - it's a pretty good solution.

Damovisa