To prevent the popup from appearing in two places, you can use the TWCore qualify macro to generate the popup
and state
titles used by the $button
and $reveal
widgets. This macro automatically appends a “magic number” to the end of the specified text and ensures that the resulting title is unique to the tiddler in which it occurs.
Thus, change
<$button popup="$:/state/custom/dropdown-menu"
to
<$button popup=<<qualify "$:/state/custom/dropdown-menu">>
and
<$reveal state="$:/state/custom/dropdown-menu"
to
<$reveal state=<<qualify "$:/state/custom/dropdown-menu">>
That will solve your “popup shows in two places” problem, since each tiddler will now be using distinct values for the popup
and state
parameters.
There is also another refinement to your code that will greatly simplify your menu implementation…
Instead of repeating similar wikitext code for the $button
and $reveal
widgets in each menu/submenu tiddler, you can define a single \procedure
that contains the needed wikitext code with some parameters, and then just invoke that procedure everywhere you need to display a menu/submenu.
Give this a try…
In “MenuContainer”, write:
\procedure menuitem(label,tag,class)
<div class=<<class>>>
<$let popid=<<qualify "$:/state/custom/dropdown-menu">>>
<$button popup=<<popid>> class=tc-btn-invisible><<label>></$button>
<$reveal state=<<popid>> type=popup position=below class=tc-popup-keep>
<div class=tc-drop-down>
<$list filter="[tag<tag>!has[draft.of]]"><$transclude/></$list>
</div>
</$reveal>
</$let>
</div>
\end
<<menuitem "☰ Menú" "Menu-Level1">>
Then, in “MenuItemA”, you can replace the entire contents with:
<<menuitem "Opción A" "Menu-Level2-ItemA" "menu-item">>
and in “MenuItemB”, you can replace the entire contents with:
<<menuitem "Opción B" "Menu-Level2-ItemB" "menu-item">>
Notes:
- In the
menuitem()
procedure, we use a $let
widget to get the qualified value that will be used for the <<$button popup=...>
and <<$reveal state=...>
parameters. We then simply refer to <<popid>>
instead of repeating the <<qualify>>
macro in each widget.
- Note also that the
popid
assignment doesn’t need to use a different tiddler title for each menu/submenu tiddler, because the results of the <<qualify "$:/state/custom/dropdown-menu">>
macro are automatically uniquely based on the tiddler in which the <<menuitem>>
macro is called from.
Let me know how it goes…
enjoy,
-e