Skip to content

Wrapper API - error_class is ignored in div wrapper #1727

Open
@abevoelker

Description

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.

Activity

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

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions