Closed hidde closed 1 year ago
Creating something like this would definitely be beneficial.
Personally, I think that when a developer chooses to use a selectmenu, it will be with the latest browsers in mind and thus could be ignored. But as I stated, that's just my opinion.
In any case, it would make fallbacking a lot easier and could result to faster adaption and reduce of polyfills.
The only thing I'm not sure about is that this could potentially overcomplicate the usage of built in ui. For example: making the selectmenu show the android popup selector or iphone select wheel when on mobile, while having a styled version on desktops.
Sidenote though: Both should be easy to target with JS (something that targets both cases) especially for bigger filter menus.
The Open UI Community Group just discussed [selectmenu] Mechanism to use <select> as progressive enhancement?
.
So the conclusion of the meeting above was that we generally agree that there should be a progressive enhancement mechanism for <selectmenu>
but we're unclear what it should be. Nested <select>
likely has some parser issues, because not all content is allowed inside <select>
. There was a comment (that I agree with) that perhaps HTML needs a better way of feature detection, akin to CSS's @supports
.
The action item here is to suggest a way forward that provides progressive enhancement.
Sidenote though: Both should be easy to target with JS (something that targets both cases) especially for bigger filter menus.
You should be able to do this by checking window.HTMLSelectMenuElement
, right?
The action item here is to suggest a way forward that provides progressive enhancement.
I think that a javascript polyfill like this is good enough: https://jsfiddle.net/jarhar/hdsfpnzj/
if (!window.HTMLSelectMenuElement) {
document.querySelectorAll('selectmenu').forEach(selectmenu => {
const select = document.createElement('select');
while (selectmenu.children.length) {
select.appendChild(selectmenu.firstChild);
}
selectmenu.after(select);
selectmenu.remove();
});
}
I could also add some more code to copy attributes from the selectmenu to the select
When thinking about progressive enhancement, I think the other way around, eg what would a browser do that doesn't know what a selectmenu
is?
With something like
<selectmenu>
<select>
</select>
</selectmenu>
I would expect a browser that doesn't know about selectmenu
would throw that wrapping selectmenu
tag out and/or ignore it, and then it would just render the select
inside, with no JS needed to get that behaviour. Then a browser that does know what selectmenu
is, would throw any select
element inside of it out, as it knows that that is a fallback.
The use of this is probably limited, especially with more advanced use selectmenu use cases. But one “common” use case I can think of is someone who uses selectmenu
just for the purposes of styling. They would prefer to use selectmenu
so that they can style it, and that would work as advertised in any selectmenu
-supporting browser in the future, but at the same time, they could live with an unstyled/default styled select
in older bowser versions.
I would expect a browser that doesn't know about selectmenu would throw that wrapping selectmenu tag out and/or ignore it, and then it would just render the select inside
It would seem that this currently works, which is good because I think we would have a hard time getting safari and firefox to implement this selectmenu-specific behavior
Then a browser that does know what selectmenu is, would throw any select element inside of it out, as it knows that that is a fallback
This does not currently work, it creates a select element in the selectmenu's dropdown. So I guess that the request is to make selectmenu skip select elements...?
Nested
<select>
likely has some parser issues, because not all content is allowed inside<select>
So even if we did make selectmenu try to skip child select elements, it sounds like there could be additional issues and would at least be complicated to put into the browser. I still think that some javascript which turns selectmenu elements into select elements is best.
It would seem that this currently works, which is good because I think we would have a hard time getting safari and firefox to implement this selectmenu-specific behavior
I don't know specifics of how this works, but my understanding is “unknown tags are ignored” is generally how HTML is handled across browsers?
This does not currently work, it creates a select element in the selectmenu's dropdown. So I guess that the request is to make selectmenu skip select elements...?
Yes! I feel it would make sense.
Nested
So even if we did make selectmenu try to skip child select elements, it sounds like there could be additional issues and would at least be complicated to put into the browser.
Would be curious to learn more about the mechanics here!
I still think that some javascript which turns selectmenu elements into select elements is best.
While progressive enhancement doesn't necessarily mean “no JavaScript”, to me requiring JS for backwards compatibility would be less desirable than having some built-in mechanism for provide a fallback for a non-supported feature in non-supporting browsers.
Slight improvement to the JS solution:
if (!window.HTMLSelectMenuElement) {
document.querySelectorAll('selectmenu').forEach(selectmenu => {
const select = document.createElement('select');
select.replaceChildren(...selectmenu.childNodes);
[...selectmenu.attributes].forEach(attr => {
select.setAttribute(attr.nodeName,attr.nodeValue)
});
selectmenu.after(select);
selectmenu.remove();
});
}
The Open UI Community Group just discussed [selectmenu] Mechanism to use as progressive enhancement?
, and agreed to the following:
RESOLVED: Don't support nesting select tags inside selectmenu tags as a progressive enhancement
This was just discussed and resolved not to (see minutes in comment above).
TLDR: beyond the simplest use case of auomatigally making this work for text-only options (which is also trivial to do client side with the few lines of JS above), doing it for more complex cases is impossible to do realibly and developers will likely be in a better position to provide sensible a fallback, eg with a divs based component their design system already has.
From: https://home.social/@ranger/109505541067518807
In browsers that don't support
<selectmenu>
, you could do something like this to fallback to<select>
:(A bit, but probably not the same, like how you could put fallback content in a
<video>
)Should there be a mechanism, when browsers do support
<selectmenu>
, that they ignore any nested<select>
s and assume they are only there as a fallback? Would that even be a safe assumption to make?