I have a select menu like:
<select>
<option value="1">New York</option>
<option value="2">Los Angeles</option>
</select>
On small screens, I would prefer to use abbreviations
<select>
<option value="1">NY</option>
<option value="2">LA</option>
</select>
How can I switch between the short and long text dynamically?
My first thought was to use media queries on <span> elements inside the <option> tags, but that doesn't work because <option> can only have text as children:
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet"/>
<select>
<option value="1"><span class="d-md-none">NY</span><span class="d-none d-md-inline-block">New York</span></option>
<option value="2"><span class="d-md-none">LA</span><span class="d-none d-md-inline-block">Los Angeles<span></option>
</select>
I could also imagine having different <option> tags show/hide based on media queries:
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet"/>
<select>
<option value="1-small" class="d-md-none">NY</option>
<option value="1-large" class="d-none d-md-block">New York</option>
<option value="2-small" class="d-md-none">LA</option>
<option value="2-large" class="d-none d-md-block">Los Angeles</option>
</select>
That kind of works, but it is a bit messy when you consider what it needs to do when the user resizes a window and the currently-selected value needs to switch between "-small" and "-large" - not impossible with some JS I guess, but it doesn't feel right that JS would be required to achieve this. Also feels messy that whatever code is consuming this would then need to be aware of the "-small" and "-large" suffixes in the value.
I know I could use some custom HTML/JS select menu component, but I'd prefer not to do that because using a native select menu has a lot of advantages.
It feels like there should be some better answer, but I haven't been able to figure it out. Any ideas?