Skip to content

Rails Component interface kwargs uniformity #54

@mvkampen

Description

@mvkampen

Given the following class hierarchy:

Superform::Rails::Component < ApplicationComponent
Superform::Rails::Form < Superform::Rails::Component
Superform::Rails::Form::Components::BaseComponent < Superform::Rails::Component

Superform::Rails::Form::Components::BaseComponent deviated its interface for attributes from the Superform::Rails::Component.
Where as Component assigns all remaining plat kwargs as attributes, in Components::BaseComponent it required the keyword :attributes.

def initialize(field, attributes: {})

Suggestion to keep components interface consistent across the board and change this in Components::BaseComponent:

class Components::BaseComponent
      def initialize(field, **attributes)
        @field = field
        @attributes = attributes
      end

class Superform::Rails::Field
        def input(**attributes)
          Components::InputComponent.new(self, **attributes)
        end

This still allows you to pass attributes explicitly, should you want to:

def initialize(field, attributes: {})

But allows us to use keywords as expected in other components.
To make attributes required or give them default values, yet open for additional html attributes:

def initialize(field, selected: false, value:, **attributes)
end

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