Skip to content

Losing slots after reflex #95

Description

@omarluq

In my app I have the following dropdown menu component
when the open function is triggered the menu component is losing all of its slots, am I missing something? I've never encountered this issue before

module Ui
  module Dropdown
    class MenuComponent < ApplicationComponent
      renders_one :trigger, -> { Ui::Dropdown::TriggerComponent.new(data: reflex_data_attributes(:open).merge({ action: 'keydown->application-controller#stopProp' })) }
      renders_many :sections, ->(**system_arguments) { Ui::Dropdown::SectionComponent.new(**system_arguments) }

      def initialize(classes: '')
        @classes = classes
        @role = 'menu'
        @hidden = 'hidden'
        @transition = 'transition ease-out duration-300'
        @transform = 'translate-y-2 opacity-0 scale-95'
      end

      def collection_key
        SecureRandom.hex(16)
      end

      def open
        @hidden = ''
        @transition = 'transition ease-in duration-600'
        @transform = 'translate-y-0 opacity-100 scale-100'
      end

      def close
        @hidden = 'hidden'
        @transition = 'transition ease-out duration-300'
        @transform = 'translate-y-2 opacity-0 scale-95'
      end

      def menu_key
        "menu_for_#{key}"
      end
    end
  end
end
<%= component_controller do %>
  <div class="relative inline-block text-left">
    <%= trigger %>
    <div id="<%= menu_key %>" class="<%= "#{@hidden} #{@transition} #{@transform} absolute right-0 mt-2 origin-top-right divide-y divide-gray-100 rounded-md bg-white shadow-lg ring-1 ring-black ring-opacity-5 focus:outline-none w-max" %>" role="menu" aria-orientation="vertical" aria-labelledby="user-menu-button" tabindex="-1" style="z-index:999999">
        <% sections.each do |section| %>
          <%= section %>
        <% end %>
    </div>
    <div id='hidden-close-button-for-active-dropdown' class="<%= "#{@hidden} fixed inset-0 w-full h-full" %>" data-reflex="click->Ui::Dropdown::MenuComponent#close" data-key="<%= key %>" style="z-index:9997"></div>
  </div>
<% end %>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions