UX/UI: Problème de rechargement des sliding-tabs apres reload htmx#5023
Merged
hellodeloo merged 1 commit intomasterfrom Nov 12, 2024
Merged
UX/UI: Problème de rechargement des sliding-tabs apres reload htmx#5023hellodeloo merged 1 commit intomasterfrom
hellodeloo merged 1 commit intomasterfrom
Conversation
tonial
approved these changes
Nov 4, 2024
Member
francoisfreitag
left a comment
There was a problem hiding this comment.
Un patch avec suggestions d’amélioration :
- Ne chercher des sliding tabs que dans
targetet non document, pour ne pas initialiser deux fois les onglets sur un document lors du chargement d’une réponse HTMX - Utilisation du sélecteur CSS précis au lieu du commentaire pas clair
- Simplification du calcul de
startIndex, et utilisation d’entiers et non d’une string (slidingTabs.getAttribute("data-it-sliding-tabs-startindex") === "2") - Préférer
constàlet, pour indiquer qu’il n’y aura pas de changements
diff --git a/itou/static/js/sliding_tabs.js b/itou/static/js/sliding_tabs.js
index 2825c1e15..04ce4cb9e 100644
--- a/itou/static/js/sliding_tabs.js
+++ b/itou/static/js/sliding_tabs.js
@@ -1,15 +1,10 @@
"use strict";
-htmx.onLoad(function (target) {
- // Only for <ul.s-tabs-01__nav.nav.nav-tabs> how has data-it-sliding-tabs="true" attribute
- let slidingTabs = document.querySelector("[data-it-sliding-tabs=true]");
+htmx.onLoad(function(target) {
+ const slidingTabs = target.querySelector("ul.s-tabs-01__nav.nav.nav-tabs[data-it-sliding-tabs=true]");
if (slidingTabs) {
- let slidingTabsStartIndex = 0;
-
- if (slidingTabs.hasAttribute("data-it-sliding-tabs-startindex")) {
- slidingTabsStartIndex = slidingTabs.getAttribute("data-it-sliding-tabs-startindex")
- }
+ const slidingTabsStartIndex = Number.parseInt(slidingTabs.getAttribute("data-it-sliding-tabs-startindex")) || 0;
tns({
container: slidingTabs,bab9e7e to
c87f078
Compare
Contributor
Author
|
@francoisfreitag Merci, je prends tout sauf le "sélecteur CSS précis" car trop précis. |
francoisfreitag
approved these changes
Nov 4, 2024
Member
|
On pourrait aller un poil plus loin avec un |
Member
"use strict";
htmx.onLoad(function(target) {
target.querySelectorAll("[data-it-sliding-tabs=true]").forEach(function(slidingTabs) {
const slidingTabsStartIndex = Number.parseInt(slidingTabs.getAttribute("data-it-sliding-tabs-startindex")) || 0;
tns({
container: slidingTabs,
slideBy: "page",
autoWidth: true,
arrowKeys: true,
loop: false,
mouseDrag: true,
swipeAngle: false,
speed: 300,
nav: false,
controls: true,
startIndex: slidingTabsStartIndex,
});
})
}); |
Member
|
Cette nouvelle version supporte plusieurs éléments sliding tabs dans une page (ou un fragment) et n’a pas besoin du |
c87f078 to
94fbf9b
Compare
Contributor
Author
Quelle concision ✂️ |
94fbf9b to
803a1d1
Compare
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤔 Pourquoi ?
Les onglets
data-it-sliding-tabs="true"n’est pas réinterprété en "sliding-tabs" après un rechargement partiel htmxx