### Problem Description The XUL [MozMenuList](https://searchfox.org/mozilla-central/rev/0e7394a77cdbe1df5e04a1d4171d6da67b57fa17/toolkit/content/widgets/menulist.js#16) implementation has a [setInitialSelection()](https://searchfox.org/mozilla-central/rev/0e7394a77cdbe1df5e04a1d4171d6da67b57fa17/toolkit/content/widgets/menulist.js#291-311) implementation. It gets called [here](https://searchfox.org/mozilla-central/rev/0e7394a77cdbe1df5e04a1d4171d6da67b57fa17/toolkit/content/widgets/menulist.js#113-130) in [menulist.js](https://searchfox.org/mozilla-central/search?q=&path=widgets%2Fmenulist.js&case=false®exp=false). I have a use case for the [Select Translations Panel](https://bugzilla.mozilla.org/show_bug.cgi?id=1870298) in which I want to leave the menulist with no item selected, such as requesting a translation from a language that we do not yet support. There is no valid value that the menulist should have in this case. --- ### Proposal I would like to add a way to allow menulists to remain unselected when initialized. This should be a non-breaking change, and an opt-in experience. My initial approach is to check for an attribute `noinitialselection="true"` (similar to [noautofocus](https://searchfox.org/mozilla-central/rev/0e7394a77cdbe1df5e04a1d4171d6da67b57fa17/xpcom/ds/StaticAtoms.py#725)) in which case the menulist will not default to selecting one of the values when initialized. But I'm certainly open to feedback on other approaches to solve this problem. #### Example ```html <panel> <menulist value="" label="None" noinitialselection="false"> <menupopup> <menuitem value="1" label="One"/> <menuitem value="2" label="Two"/> <menuitem value="3" label="Three"/> </menupopup> </menulist> </panel> ``` ```javascript setInitialSelection() { if (this.getAttribute("noinitialselection") === "true") { return; } // Snip... } ```
Bug 1882835 Comment 0 Edit History
Note: The actual edited comment in the bug view page will always show the original commenter’s name and original timestamp.
### Problem Description The XUL [MozMenuList](https://searchfox.org/mozilla-central/rev/0e7394a77cdbe1df5e04a1d4171d6da67b57fa17/toolkit/content/widgets/menulist.js#16) implementation has a [setInitialSelection()](https://searchfox.org/mozilla-central/rev/0e7394a77cdbe1df5e04a1d4171d6da67b57fa17/toolkit/content/widgets/menulist.js#291-311) implementation. It gets called [here](https://searchfox.org/mozilla-central/rev/0e7394a77cdbe1df5e04a1d4171d6da67b57fa17/toolkit/content/widgets/menulist.js#113-130) in [menulist.js](https://searchfox.org/mozilla-central/search?q=&path=widgets%2Fmenulist.js&case=false®exp=false). I have a use case for the [Select Translations Panel](https://bugzilla.mozilla.org/show_bug.cgi?id=1870298) in which I want to leave the menulist with no item selected, such as requesting a translation from a language that we do not yet support. There is no valid value that the menulist should have in this case. --- ### Proposal I would like to add a way to allow menulists to remain unselected when initialized. This should be a non-breaking change, and an opt-in experience. My initial approach is to check for an attribute `noinitialselection="true"` (similar to [noautofocus](https://searchfox.org/mozilla-central/rev/0e7394a77cdbe1df5e04a1d4171d6da67b57fa17/xpcom/ds/StaticAtoms.py#725)) in which case the menulist will not default to selecting one of the values when initialized. But I'm certainly open to feedback on other approaches to solve this problem. #### Example ```html <panel> <menulist value="" label="None" noinitialselection="true"> <menupopup> <menuitem value="1" label="One"/> <menuitem value="2" label="Two"/> <menuitem value="3" label="Three"/> </menupopup> </menulist> </panel> ``` ```javascript setInitialSelection() { if (this.getAttribute("noinitialselection") === "true") { return; } // Snip... } ```