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
useTransition
with multiple targets within a controller
#160
Comments
Hello I have an on going refactoring of useTransition that will transition on multiple targets. The API looks like that currently ....
static targets = ['item']
....
connect(){
useTransition(this, {
elements: "item",
hiddenClass: 'hidden'
});
} We can pass the target name of the In your case each item has a different animation. This should be possible by adding the the transition information as data attributes to the html mark up. I don't have a firm ETA yet hopefully within 2 weeks 🤷♂️ .... |
Hi Adrien, great to hear it's something that Just wanted to share that in the meantime I went with el-transition package, which has the following API (the animations are specified via data-attributes Alpine.js-style). import { Controller } from "stimulus"
import {enter, leave } from 'el-transition'
export default class extends Controller {
static targets = ['backdrop', 'dialog']
close() {
leave(this.backdropTarget);
leave(this.dialogTarget);
}
open() {
enter(this.backdropTarget);
enter(this.dialogTarget);
}
} While in this case I'm animating both targets at the same time, I like the offered flexibility of being able to animate them separately via |
Forgot to mention that In case of the closing modal, I can wait for backdrop and dialog animation to finish to then hide the whole modal as well: close() {
Promise.all([leave(this.backdropTarget), leave(this.dialogTarget)]).then(() => {
this.element.classList.add('hidden');
});
} Just thought I'd share in case it's valuable for the next iteration of |
I am also doing a modal with Tailwind and I have the same problem. |
I would be very interested in this feature as well. Anything we could help you with? :) |
Just wondering, any progress here? |
In a mean time backdrop can live a separate controller that responds to some events. |
Just got bit by this. Without support for multiple targets within a controller, you can't really leverage |
Same here, was writing a Stimulus component for a modal and realized I needed to add transitions to more than one target. @adrienpoly I know it's been a while, but are you still working on this? If you could open even a draft PR, I think that'd be very helpful. |
What are the benefits of having this behaviour at all actually? I'm using el-transition directly in controllers and it works great. I haven't had a situation when Transition was required as dedicated feature decoupled from something more concrete like Modal or Disclosure. |
I was able to get this working by also exporting the helper function within |
@pySilver Ya, I guess since I'm already importing use-stimulus for a bunch of other features in my app, duplicating functionality that is right there with another import "feels" wrong. But ya. |
@aviflombaum I'm just not sure about implementation. How would control |
I mean I got it working with that temp hack but I can do it properly. Basically I'm thinking that every transition target should be storing whether it is transitionsed and not the parent controller. So take what it's doing right now and bind on multiple targets instead of just one, rescope transitioned to the target and that should do it. No matter what it's sort of nice to expose the lower level transition function to the mixing. It'd also be nice to have a method added to the target that can return the various classes for the target, it's called getAttribute in the library but it's too low level. It took me a min to get comfortable with the tests and tbh, like 2nd time playing with TS and tailwind transitions but I can do this is now and sounds fun. |
Would love to see an API like this, which would also allow for multiple element transitions.
|
It seems the current architecture of
userTransition
doesn't support multiple animated elements within a controller.Was trying to implement Tailwind UI's modal component, which animates the backdrop separately from the modal dialog. However calling
this.leave()
only animates the last element passed touseTransition
. In my case thedialog
:Was wondering whether it's a use case
useTransition
would want to support in the future or whether it's intended to be used with just one element per controller?The text was updated successfully, but these errors were encountered: