Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Stimulus controller we created to replace ActiveLink .
// src/controllers/highlight_sidebar_controller.js
import { Controller } from "stimulus"
export default class extends Controller {
onCurrentController() {
let activeLinks = this.data.get("active-on"));
return activeLinks == App.controller;
}
connect() {
if (this.onCurrentController()) {
this.element.classList.add("active");
} else {
this.element.classList.remove("active");
}
}
}
<script>
App.controller = "Users";
</script>
(...)
<a class="nav-link"
data-controller="highlight-sidebar"
data-highlight-sidebar-active-on="Users"
href="/Users">
<span>show Users</span>
</a>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.