commit fa7d7f5d1670205ba97e19879f0df7718e18f7e4 parent a0d863ae052c99ee8acb5acbcb990d42abd33e2d Author: Julien Wajsberg <felash@gmail.com> Date: Wed, 17 Dec 2025 15:56:59 +0000 Bug 2005536 - Fix <moz-select> throwing when there's no <moz-option> children r=hjones Differential Revision: https://phabricator.services.mozilla.com/D276004 Diffstat:
| M | toolkit/content/tests/widgets/test_moz_select.html | | | 7 | +++++++ |
| M | toolkit/content/widgets/moz-select/moz-select.mjs | | | 6 | ++++++ |
2 files changed, 13 insertions(+), 0 deletions(-)
diff --git a/toolkit/content/tests/widgets/test_moz_select.html b/toolkit/content/tests/widgets/test_moz_select.html @@ -231,6 +231,13 @@ mozOptions[0].disabled = false; mozOptions[1].hidden = false; }); + + add_task(async function testEmptyMozSelect() { + // The only thing we test is that this doesn't throw. + await testHelpers.renderTemplate( + testHelpers.html`<moz-select></moz-select>` + ); + }); </script> </head> <body></body> diff --git a/toolkit/content/widgets/moz-select/moz-select.mjs b/toolkit/content/widgets/moz-select/moz-select.mjs @@ -108,6 +108,12 @@ export default class MozSelect extends MozBaseInputElement { * Internal - populates the select element with options from the light DOM slot. */ populateOptions() { + if (!this.slotRef.value) { + this.options = []; + this.usePanelList = false; + return; + } + let options = []; for (const node of this.slotRef.value.assignedNodes()) {