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

Add ability to set UJS handlers on a different HTML element. #64

Open
jho406 opened this issue Jun 7, 2024 · 0 comments
Open

Add ability to set UJS handlers on a different HTML element. #64

jho406 opened this issue Jun 7, 2024 · 0 comments

Comments

@jho406
Copy link
Collaborator

jho406 commented Jun 7, 2024

Superglue brings back UJS handers to Rails. In superglue they often look like this

<a href={"/posts"} data-sg-remote>

They're very convenient and adds SPA functionality without the complexity of javascript. Its behavior is overridable in your application_visit.js that gets generated when you start a new superglue project so you can handle all your edge cases.

In superglue, its installed on the same appEl in application.js, also generated into your project.

The appEl also gets passed internally to superglue's ApplicationBase (your application.js overrides this) here:

const { appEl } = this.props

where the event listeners are added to appEl immediately after that.

    appEl.addEventListener('click', onClick)

In other words, the UJS handers only listen on the appEl, which when considering some component libraries uses react portals to build modals or dropdowns, means that UJS doesn't work on those components because they exist outside the appEl. I'd like to see superglue optionally support passing a custom element to put the listeners on. It can be as simple as allowing a subclass of of ApplicationBase to more easily override. For example:

class Application extends ApplicationBase {
   ujsElement () {
  }

In that scenario `ApplicationBase` would need to define its ujsElement as defaulting to the `appEl` that gets passed to it.




Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Ready for contributors
Development

No branches or pull requests

1 participant