Skip to content

Commit

Permalink
🐛 [open-formulieren/open-forms#3577] Fix checkbox/radio buttons on we…
Browse files Browse the repository at this point in the history
…bkit

The label in our Open Forms theme stretches to the left side of the
checkbox, where the padding overlays the checkbox itself. On WebKit,
this blocks the click event/pointer event to the checkbox itself
(Chrome/Firefox are okay with this).

Swapping the order of the elements in the DOM still visually
positions them correctly while now allowing the input the lay
on top of the div/paragraph/label because it comes later in
the document tree.

Backport-of: 5e10f86
  • Loading branch information
sergei-maertens committed Nov 9, 2023
1 parent b646d30 commit d07d0dd
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 23 deletions.
10 changes: 5 additions & 5 deletions src/components/forms/Checkbox/Checkbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ const Checkbox = ({
return (
<Wrapper>
<FormField type="checkbox" invalid={invalid} className="utrecht-form-field--openforms">
<div className="utrecht-form-field__label utrecht-form-field__label--checkbox">
<LabelContent id={id} isRequired={isRequired} disabled={disabled} type="checkbox">
{label}
</LabelContent>
</div>
<Field
name={name}
as={UtrechtCheckbox}
Expand All @@ -38,11 +43,6 @@ const Checkbox = ({
appearance="custom"
{...inputProps}
/>
<div className="utrecht-form-field__label utrecht-form-field__label--checkbox">
<LabelContent id={id} isRequired={isRequired} disabled={disabled} type="checkbox">
{label}
</LabelContent>
</div>
<HelpText>{description}</HelpText>
{touched && <ValidationErrors error={error} />}
</FormField>
Expand Down
21 changes: 11 additions & 10 deletions src/formio/templates/checkbox.ejs
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
<input
ref="input"
id="{{ctx.instance.id}}-{{ctx.component.key}}"

{% for (var attr in ctx.input.attr) { %}
{{attr}}="{{ctx.input.attr[attr]}}"
{% } %}

{% if (ctx.checked) { %}checked=true{% } %}
>

<p class="utrecht-form-field__label utrecht-form-field__label--checkbox">
<label
Expand All @@ -20,3 +10,14 @@
{% } %}
</label>
</p>

<input
ref="input"
id="{{ctx.instance.id}}-{{ctx.component.key}}"

{% for (var attr in ctx.input.attr) { %}
{{attr}}="{{ctx.input.attr[attr]}}"
{% } %}

{% if (ctx.checked) { %}checked=true{% } %}
>
16 changes: 8 additions & 8 deletions src/formio/templates/radio.ejs
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
<!-- rendered by both radio and selectboxes component -->
{% ctx.values.forEach(function(item) { %}
<div class="utrecht-form-field utrecht-form-field--{{ctx.component.inputType}} utrecht-form-field--openforms">
<p class="utrecht-paragraph utrecht-form-field__label utrecht-form-field__label--{{ctx.component.inputType}}">
<label
for="{{ctx.id}}{{ctx.row}}-{{item.value}}"
class="utrecht-form-label utrecht-form-label--{{ctx.component.inputType}} {% if (ctx.disabled) { %}utrecht-form-label--disabled{% } %}"
>
{{ item.label }}
</label>
</p>
<input
ref="input"
value="{{item.value}}"
Expand All @@ -14,13 +22,5 @@
checked=true
{% } %}
>
<p class="utrecht-paragraph utrecht-form-field__label utrecht-form-field__label--{{ctx.component.inputType}}">
<label
for="{{ctx.id}}{{ctx.row}}-{{item.value}}"
class="utrecht-form-label utrecht-form-label--{{ctx.component.inputType}} {% if (ctx.disabled) { %}utrecht-form-label--disabled{% } %}"
>
{{ item.label }}
</label>
</p>
</div>
{% }) %}

0 comments on commit d07d0dd

Please sign in to comment.