Class: Mayu::VDOM::SpecialElements::Select

Inherits:
Component::Base show all
Defined in:
lib/mayu/vdom/special_elements.rb

Defined Under Namespace

Classes: InvalidNestingError

Constant Summary

Constants inherited from Component::Base

Component::Base::INLINE_CSS_ASSETS

Instance Method Summary collapse

Methods inherited from Component::Base

__mayu_resource!, __mayu_resource?, assets, #async, #children, #did_update, get_derived_state_from_props, get_initial_state, #handler, #initialize, initialize, #mayu, #mount, #props, setup_component, #should_update?, #state, styles, #styles, stylesheet, stylesheet!, #unmount, #update, #vnode_id

Constructor Details

This class inherits a constructor from Mayu::Component::Base

Instance Method Details

#renderObject



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/mayu/vdom/special_elements.rb', line 62

def render
  value = props[:value]

  options =
    Array(children).flatten.compact.map do |descriptor|
      unless descriptor.type == :option
        raise InvalidNestingError,
              "Only option are valid children for select, you passed #{descriptor.type}"
      end

      T.unsafe(VDOM::H)[
        descriptor.type,
        *descriptor.children,
        **descriptor.props,
        key: descriptor.key,
        selected: !value.nil? && value == descriptor.props[:value]
      ]
    end

  T.unsafe(VDOM::H)[:__mayu_select, *options, **props.except(:value)]
end