Closed Bug 1942342 Opened 28 days ago Closed 22 days ago

It's not possible to set value on moz-radio-group via an attribute, and setting it via a property only works asynchronously

Categories

(Toolkit :: UI Widgets, defect, P2)

defect

Tracking

()

RESOLVED FIXED
136 Branch
Tracking Status
firefox136 --- fixed

People

(Reporter: hjones, Assigned: hjones)

References

(Blocks 1 open bug)

Details

(Whiteboard: [recomp])

Attachments

(1 file)

Recent attempts to use moz-radio-group in about:preferences uncovered a couple of issues with setting value that we should address before people attempt to use the element more widely. These are really kind of two distinct, but related bugs.

For one thing it's not currently possible to set an initial value via an attribute in the markup. This is somewhat expected since we currently only expose value via a getter/setter, instead of as a reactive Lit property. We should fix this, so that the following code will work as expected to update the checked/unchecked state of the moz-radio items:

<moz-radio-group name="greeting" label="Select a preferred greeting" value="hola">
  <moz-radio value="hi" label="Hi"></moz-radio>
  <moz-radio value="hello" label="Hello"></moz-radio>
  <moz-radio value="hola" label="Hola"></moz-radio>
</moz-radio-group>

A second issue that came up related to value is that it doesn't currently work if you try to set it synchronously via JS, e.g. something like this:

let myRadio = document.createElement("moz-radio-group");
myRadio.value = "foo";

will not reliably update the checked/unchecked state of the contained moz-radio items. This seems to be due to some assumptions being made about when value will be set, as well as how we're querying for related moz-radio elements. The logic relies on this.#radioButtons being set, but this only happens either in the firstUpdated call or once the slotchange event has fired. If we try to set value before either of those things have happened it wont propagate properly.

It seems reasonable to expect to be able to set value via an attribute and/or synchronously in JS code.

Assignee: nobody → hjones
Status: NEW → ASSIGNED
Attachment #9460262 - Attachment description: Bug 1942342 - fix issues with setting value on moz-radio-group r=mstriemer → WIP: Bug 1942342 - fix issues with setting value on moz-radio-group r=mstriemer
Attachment #9460262 - Attachment description: WIP: Bug 1942342 - fix issues with setting value on moz-radio-group r=mstriemer → Bug 1942342 - fix issues with setting value on moz-radio-group r=mstriemer
Severity: -- → S3
Priority: -- → P2
Pushed by hjones@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/61bb1d30e5ab fix issues with setting value on moz-radio-group r=mstriemer,reusable-components-reviewers
Status: ASSIGNED → RESOLVED
Closed: 22 days ago
Resolution: --- → FIXED
Target Milestone: --- → 136 Branch
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: