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

Detect parent LiveView name #77

Closed
HugoDF opened this issue Nov 26, 2020 · 3 comments · Fixed by #87
Closed

Detect parent LiveView name #77

HugoDF opened this issue Nov 26, 2020 · 3 comments · Fixed by #87
Labels
enhancement New feature or request
Milestone

Comments

@HugoDF
Copy link
Collaborator

HugoDF commented Nov 26, 2020

When an Alpine.js component is detected inside of a LiveView view, use view.name as the name of the component.

@HugoDF HugoDF added the enhancement New feature or request label Nov 26, 2020
@KevinBatdorf
Copy link
Contributor

This could probably be added to #79 if you want to take over that PR

@HugoDF
Copy link
Collaborator Author

HugoDF commented Nov 27, 2020

@KevinBatdorf was having a conversation with some LiveView peeps over on Twitter, I'll add the details I've gleaned here later

That PR is fine to go in without the changes for this issue 👍

@HugoDF
Copy link
Collaborator Author

HugoDF commented Nov 28, 2020

Sample LiveView apps:

Per this tweet we can do something like:

const alpineElement = document.querySelector('[x-data]'); // some Alpine.js component root;
const phxEl = alpineElement.closest('[data-phx-view]');
if (phxEl) {
  const view = window.liveSocket.getViewByEl(phxEl);
  return view.name;
}

From a quick look, I think we could even use: phxEl.dataset.phxView

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants