forked from ontoportal/ontoportal_web_ui
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement tabs container stimulus controller tu update URL on tab change
- Loading branch information
1 parent
8197053
commit 78aa0b8
Showing
5 changed files
with
67 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
app/components/tabs_container_component/tabs_container_component.html.haml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
app/components/tabs_container_component/tabs_container_component_controller.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { Controller } from "@hotwired/stimulus"; | ||
import {HistoryService} from "../../javascript/mixins/useHistory"; | ||
|
||
export default class extends Controller { | ||
|
||
connect() { | ||
this.event = null | ||
} | ||
|
||
|
||
selectTab(event) { | ||
this.event = event | ||
if(this.#parameter()){ | ||
this.#updateURL() | ||
} | ||
} | ||
|
||
#pageId(){ | ||
return this.event.currentTarget.getAttribute("data-tab-id") | ||
} | ||
|
||
#title(){ | ||
return this.event.currentTarget.getAttribute("data-tab-title") | ||
} | ||
|
||
#parameter(){ | ||
return this.event.currentTarget.getAttribute("data-url-parameter") | ||
} | ||
|
||
|
||
#url(){ | ||
return `?${this.#parameter()}=${this.#pageId()}` | ||
} | ||
|
||
#updateURL(){ | ||
(new HistoryService()).pushState({[this.#parameter()]: this.#pageId()}, this.#title(), this.#url()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters