Skip to content

SwitchCheckboxInput renders duplicate Labels #124

@reedrolemodel

Description

@reedrolemodel

One label is visible and the other is hidden. This makes testing difficult.
image

If you use the capybara check 'Approve' matcher, it fails saying "2 matching elements found". As a workaround you can use find('label', text: 'Approve', match: :first).click. It also seems not very accessible to have two labels for the same input.

The code does add label twice:

    switch_group = template.content_tag(:div, class: "switch #{'switch--small' if options[:small]}") do
      if include_hidden?
        build_check_box(unchecked_value, merged_input_options)
      else
        build_check_box_without_hidden_field(merged_input_options)
      end + label(wrapper_options)
    end

    if options[:label_after_input]
      switch_group + label(wrapper_options)
    else
      label(wrapper_options) + switch_group
    end

But if you remove the first one, the label is invisible. If you remove the other, the switch is invisible. So I can see how this issue arose, but there must be an accessible way to implement this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions