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

Wrapper API - error_class is ignored in div wrapper #1727

Open
abevoelker opened this issue Feb 16, 2021 · 4 comments
Open

Wrapper API - error_class is ignored in div wrapper #1727

abevoelker opened this issue Feb 16, 2021 · 4 comments

Comments

@abevoelker
Copy link

Environment

  • Ruby 2.7.2
  • Rails 6.1.1
  • Simple Form 5.1.0

Current behavior

I wrote the following wrapper to create a Tailwind text input:

config.wrappers :tailwind_text_input, tag: 'div', class: '', error_class: '', valid_class: '' do |b|
  b.use :html5
  b.use :placeholder
  b.optional :maxlength
  b.optional :minlength
  b.optional :pattern
  b.optional :min_max
  b.optional :readonly

  b.use :label, class: "block text-sm font-medium text-gray-700"
  b.wrapper tag: 'div', class: 'mt-1', error_class: 'relative rounded-md shadow-sm' do |c|
    c.use :input,
      class: 'appearance-none block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm placeholder-gray-400 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm',
      error_class: 'block w-full pr-10 border-red-300 text-red-900 placeholder-red-300 focus:outline-none focus:ring-red-500 focus:border-red-500 sm:text-sm rounded-md'
    c.use :full_error, wrap_with: { tag: 'p', class: 'mt-2 text-sm text-red-600' }
  end
end

However, when my input has an error, the b.wrapper tag: 'div' 's error_class is ignored - I only see the mt-1 class. If I add an error_class to the :label definition, I get error classes added to the <label> just fine.

I've had some other stumbling points with adding Tailwind support to Simple Form out of the box, but I'll put those comments under #1723.

Expected behavior

I would expect the error classes to be added to the div.

@carlosantoniodasilva
Copy link
Member

I don't believe the wrapper there accepts the error_class and similar options, it seems to be only possible to add those to the label/input, and to the main wrappers builder around it, but not to inner wrappers like that.

@abevoelker
Copy link
Author

Ah I see. I got this working how I wanted with a custom input so I no longer need this feature. So I don't mind if this were to get closed.

@lafeber
Copy link

lafeber commented Mar 3, 2021

Changing one method in many.rb would fix this issue, I might make a MR for this since we need this as well.

  def html_classes(input, options)
    classes = []
    classes << @defaults[:class].dup
    classes << @defaults[:error_class].dup if input.has_errors?
    classes
  end

@yordis
Copy link

yordis commented May 23, 2021

Any update on this one?

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

No branches or pull requests

4 participants