Your shortcode snippet is incomplete. It’s not clear what HTML the shortcode is to output.
In any case, if you go with Eshaan’s suggestion of <summary>
and <detail>
elements, it cannot be in a <select><option>
dropdown field like you have now. It’s also not a form element so you’d need to send the user selection through different means, which would involve JavaScript.
To get the behavior you want in the current dropdown field, you’ll need to use JavaScript. I’m not sure how well this would work. It’d be difficult to discern a click that selects a top level element from a click meant to expand the element. And relying on a hover event to expand would not be mobile compatible. I suppose the expansion content could also contain the top level element again so clicking on that would be a selection. Clicking on the unexpanded element would not be a selection but only a request to expand/close the sub-elements. I think this could confuse users. It’s not the most elegant approach, but it’s all I can think of if you stay with a dropdown category list.
So your shortcode would only output top level elements. You’d install JavaScript listeners on each of the elements. On click, the listener callback would insert the elements that users would click on to select. I’m not sure the browser will immediately display <option>
elements added by script. I advise developing a minimal proof of concept test before spending a lot of time developing a full solution.