Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SwitchCheckboxInput renders duplicate Labels #124

Open
reedrolemodel opened this issue Aug 7, 2024 · 0 comments
Open

SwitchCheckboxInput renders duplicate Labels #124

reedrolemodel opened this issue Aug 7, 2024 · 0 comments

Comments

@reedrolemodel
Copy link
Member

reedrolemodel commented Aug 7, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant