Closed Bug 1486487 Opened 6 years ago Closed 6 years ago

<label control> for a <checkbox> only focuses the control instead of checking it

Categories

(Toolkit :: UI Widgets, enhancement, P3)

enhancement

Tracking

()

RESOLVED FIXED
mozilla64
Tracking Status
firefox64 --- fixed

People

(Reporter: ehsan.akhgari, Assigned: ehsan.akhgari)

Details

Attachments

(1 file, 1 obsolete file)

See this code: https://searchfox.org/mozilla-central/rev/e126996d9b0a3d7653de205898517f4f5b632e7f/toolkit/content/widgets/text.xml#285

This makes the following code snippet not behave as expected:

  <label for="checkbox"/>
  <checkbox id="checkbox"/>

since clicking on the label only focuses the checkbox, and we don't even draw the focus rect by default, so it seems like nothing happens when clicking on the label.  It is much better to try to detect the type of the control here and check the checkbox if the type of the control is indeed a checkbox.
Blocks: 1487453
Attachment #9005517 - Flags: review?(mconley)
Comment on attachment 9005517 [details] [diff] [review]
Toggle a label's control in case it's a checkbox

>       <handler event="click" action="if (this.disabled) return;
>                                      var controlElement = this.labeledControlElement;
>-                                     if(controlElement)
>+                                     if(controlElement) {
>                                        controlElement.focus();
>+                                       if (controlElement.localName === 'checkbox' &amp;&amp;
>+                                           controlElement.namespaceURI === 'http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul') {
>+                                         controlElement.checked = !controlElement.checked;
>+                                       }
>+                                     }
>                                     "/>

Please stop using the action attribute for this as it's getting overly long:

      <handler event="click"><![CDATA[
         // code goes here
      ]]></handler>
Attachment #9005517 - Attachment is obsolete: true
Attachment #9005517 - Flags: review?(mconley)
Assignee: nobody → ehsan
Summary: <labal control> for a <checkbox> only focuses the control instead of checking it → <label control> for a <checkbox> only focuses the control instead of checking it
No longer blocks: 1487453
Attachment #9005930 - Attachment is obsolete: true
Attachment #9005930 - Attachment is obsolete: false
Comment on attachment 9005930 [details]
Bug 1486487 - Toggle a label's control in case it's a checkbox; r=dao

Dão Gottwald [::dao] has approved the revision.
Attachment #9005930 - Flags: review+
Pushed by eakhgari@mozilla.com:
https://hg.mozilla.org/integration/mozilla-inbound/rev/dbb51f1914eb
Toggle a label's control in case it's a checkbox; r=dao
Priority: -- → P3
https://hg.mozilla.org/mozilla-central/rev/dbb51f1914eb
Status: NEW → RESOLVED
Closed: 6 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla64
Target Milestone: mozilla64 → mozilla63
Target Milestone: mozilla63 → mozilla64
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: