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

Include host component ID in default outlet selector #7

Merged
merged 1 commit into from
Feb 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions lib/vident/root_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,14 @@ def target_data_attribute(name)
build_target_data_attributes([target(name)])
end

def build_outlet_selector(outlet_selector)
"##{@id} [data-controller~=#{outlet_selector}]"
end

def outlet(css_selector: nil)
controller = implied_controller_name
if css_selector.nil?
[controller, "[data-controller~=#{controller}]"]
[controller, build_outlet_selector(controller)]
else
[controller, css_selector]
end
Expand Down Expand Up @@ -153,13 +157,13 @@ def outlet_list

@outlets.each_with_object({}) do |outlet_config, obj|
identifier, css_selector = if outlet_config.is_a?(String)
[outlet_config, "[data-controller~=#{outlet_config}]"]
[outlet_config, build_outlet_selector(outlet_config)]
elsif outlet_config.is_a?(Array)
outlet_config[..1]
elsif outlet_config.respond_to?(:stimulus_identifier) # Is a Component
[outlet_config.stimulus_identifier, "[data-controller~=#{outlet_config.stimulus_identifier}]"]
[outlet_config.stimulus_identifier, build_outlet_selector(outlet_config.stimulus_identifier)]
elsif outlet_config.send(:implied_controller_name) # Is a RootComponent ?
[outlet_config.send(:implied_controller_name), "[data-controller~=#{outlet_config.send(:implied_controller_name)}]"]
[outlet_config.send(:implied_controller_name), build_outlet_selector(outlet_config.send(:implied_controller_name))]
else
raise ArgumentError, "Invalid outlet config: #{outlet_config}"
end
Expand Down
Loading