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
🎛️ Create a Stimulus controller w-init
to support initial classes
#11071
Comments
Flagging as a good first issue for someone keen to write their first Stimulus controller, the scope is small but it will need unit tests and the code snippet above has not been manually validated so may not work as is. Some experience with TypeScript and a willingness to read the Stimulus documentation will be required though. This new controller will need to be imported and registered in Finally, it's recommended that anyone doing this read about Stimulus order & timing here - https://stimulus.hotwired.dev/reference/lifecycle-callbacks#order-and-timing & the linked article about microtasks https://jakearchibald.com/2015/tasks-microtasks-queues-and-schedules/ |
Do you recommend I go for it, or leave it for someone who hasn't yet had a first issue and then help out that person instead? |
Hey guys, I'm with a team from my school. We are looking for a good contribution to do in this project. Can you guide us on this issue? |
Can you do that please, I wanted to get started with open source in python and it would give me good head start. |
@GetRohitansh This particular issue is going to require you to know some Javascript and probably Jest testing. Chances are, you might really struggle if you don't have those two requirements covered. If you do, though, then are you on the Wagtail Slack? If so, I could reach out to you there so we don't clutter this comment section. |
Is your proposal related to a problem?
We have a small bit of JS that adds the class
'ready'
to thebody
element when the DOM has loaded, this is useful for a few things such as styling elements as hidden until we know the JS is ready.This pattern is used in a few places, such as the side panel JS where we want the panels to be hidden until we know the logic of the JS is loaded.
I propose a simple Stimulus solution to this that's similar to
x-init
andx-cloak
from Alpine.js - where we use a controller to trigger this behaviour.Describe the solution you'd like
InitController
that adds initial classes and also removes some classes based on data attributes when the JS is ready.wagtail/admin/templates/wagtailadmin/skeleton.html
client/src/entrypoints/admin/core.js
await jest.runAllTimersAsync();
is your friend, seeclient/src/controllers/CloneController.test.js
for some examples of tests that use this.RevealController
- this is actually not required and better served with this generic approach when it comes time.About timing & usage
Stimulus will connect controllers progressively based on the order of the
data-controller
and all controllers connect async, but as a microtask. This is slightly before a setTimeout would fire (it's a bit nuanced).This gives us the ability to order our controllers in a way that the
w-init
will be last and hence will do its classes changes last.In the above code,
w-other
will connect first,w-init
second.Rough implementation
Here's a proposed implementation, it has ready and remove classes and the ability to configure the delay, default will be no delay except for the microtask / Promise resolving.
Describe alternatives you've considered
Additional context
core.js
being a grab-bag of ad-hoc jQuerypanels
to a Stimulus controllerw-panel
#10168x-init
&x-cloak
for inspiration on the usage https://alpinejs.dev/directives/init & https://alpinejs.dev/directives/cloakThe text was updated successfully, but these errors were encountered: