-
Notifications
You must be signed in to change notification settings - Fork 424
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
Make selector for Outlets API optional #647
base: main
Are you sure you want to change the base?
Make selector for Outlets API optional #647
Conversation
4daf034
to
f2dcda4
Compare
cff5e39
to
c64775d
Compare
I think I've encountered a scenario where having a default selector (the way it's proposed here) could have destructive side effects. It's common for me to introduce an Imagine another controller that retains access to an If I were to typo the The side effects could range from (best case scenario) a bunch of Without this change, a typo'd Outlet selector would silently fail. |
@seanpdoyle I feel like this is kind of an "edge case" scenario. Of course you need to be careful about spelling the attribute right, but I would also argue that this could be the case for other Stimulus APIs, depending what kind of actions you perform in your controller actions. But agreed, maybe it wouldn't be as "destructive" as in your example in those cases. I feel like defining the attribute and leaving it without a value for it to fallback to the <div data-[identifier]-[outlet]-outlet></div> Because that would still require you to "write out and declare" the attribute, which is what we want to optimize with this change. Do you have an idea how we could improve this so that something simple like typos wouldn't hurt that much? |
The ability to - by default - reference all other controllers of type x on a page is super cool. It also matches how I tend to use outlets - I often invent a CSS class that I can use solely to find the other controllers, which have a name that matches the outlet. I see the concern with the potential typo, though it does feel a bit edge-case-y to me too. Another idea is to make this opt-in - i.e. move towards options when declaring
|
This pull request adds a fallback selector for outlets so you don't have necessarily provide a selector in the
data-[identifier]-[outlet name]-outlet="[selector]"
attribute.The selector will default to
[data-controller~=[outlet name]]
.So an example like:
With a controller like:
Can now be rewritten as:
Of course you can still declare a selector to refine the selection of outlets.