I am trying to build a simple webpage to display a map I built in an Observable notebook. I would like to use this website template. The problem I am running into is how to get the viewof components to render properly, specifically the radio buttons:
The dropdown menu is just fine, but the radio buttons do not look anything like the radio buttons on the website template (which you can also see by navigating to the ‘Elements’ page in the menu at the website template):
Oh, OK. The radio elements get added to the page by Javascript from the imported “Inputs” notebook so indeed, you don’t have to write them separately.
One thing I noticed is that the radio and label elements get added to your notebook like this (you can see this if you open your browser’s “inspector”):
In particular, note that the <input> element is nested inside the <label> element.
This differs from the HTML on the template website where the <input> and <label> elements are siblings.
Now let’s look at the CSS provided in the “Phantom” template files, namely the file assets/css/main.css (the only relevant CSS file used in elements.html). If you search for “radio”, you’ll find a bunch of rules that take this form:
input[type="radio"] + label {
/* stuff */
}
/* and some more rules that look the same except with various additional selectors
like :checked, :before, etc. */
The + combinator means that all these rules only apply when the <input> and <label> show up in order as siblings as in elements.html.
To get these rules to apply to the nested elements generated by your notebook, you’ll need to edit all these rules so that they use the > combinator like this:
label > input[type="radio"] {
/* stuff */
}
Warning: I haven’t tested this change out, so let me know if it works…
I see what you are saying with regards to the way in which the radio and label elements get added.
I tried changing the css rules as you pointed out, but I think that there are some other rules in the scss files located in assets/sass/components/_form.scss that might also need editing to make things work right and I don’t really have the know how to do that.
However, I started to look at how the radio input was defined in
which is where I got the input from in the first place. It seems like I might be able to change the definition of the radio input to have the <input> element not be nested inside the <label> element.
Yes, editing the JS should work as well. The only slightly tricky thing will be figuring out the best way to automatically add id attributes to the input elements and corresponding for attributes to their label elements.