Is there a way to make a select2 work like a normal select in terms of width? E.g. the selected element is as wide as the widest element in the list and vice versa. I want to avoid setting a fixed or 100% width. I found a way to get the selected element and the dropdown to adjust automatically each on their own, but not working as a pair. Ideas?
Can you provide a few more details of your use case?
- Is the data in your widget static, or dynamic?
- Does the data exist in the DOM before you initialize the Select2, or is it constructed from a data object, or by Select2’s AJAX capability?
- What method did you find to make the dropdown fit its contents? What method did you find to make the selected item (I assume you mean the display when the dropdown is closed an an item has been selected) fit its contents? What issues did you encounter when you tried to use both methods at the same time?
Is your code available on codepen.io or a similar site where I could take a look at it? I do have a couple of ideas, but I’d rather have some more details about your situation before I suggest them (and in fact they might not be applicable, depending on your answers to the questions above).