Skip to content
Snippets Groups Projects
Commit 7867d10e authored by Justin Toupin's avatar Justin Toupin
Browse files

Correctly manage visibility of UI elements

parent 8ed4f1b4
No related branches found
No related tags found
No related merge requests found
Pipeline #430167 failed
...@@ -59,6 +59,19 @@ ...@@ -59,6 +59,19 @@
}); });
} }
/**
* Sets the visibility of UI elements based on the data-active attribute.
*/
function setUiElementVisibility() {
selectAll('.js-lpb-component .js-lpb-ui').forEach((element) => {
if (element.closest('.js-lpb-component')?.getAttribute('data-active')) {
element.classList.remove('visually-hidden');
} else {
element.classList.add('visually-hidden');
}
});
}
/** /**
* Removes focus data attributes from all components. * Removes focus data attributes from all components.
*/ */
...@@ -72,9 +85,7 @@ ...@@ -72,9 +85,7 @@
selectAll('.is-navigating').forEach((element) => selectAll('.is-navigating').forEach((element) =>
element.classList.remove('is-navigating'), element.classList.remove('is-navigating'),
); );
selectAll('.js-lpb-ui:not(.visually-hidden)').forEach((element) => setUiElementVisibility();
element.classList.add('visually-hidden'),
);
} }
/** /**
...@@ -87,9 +98,7 @@ ...@@ -87,9 +98,7 @@
// Add the data-active attribute to the element. // Add the data-active attribute to the element.
element.setAttribute('data-active', 'true'); element.setAttribute('data-active', 'true');
element.setAttribute('data-active-within', 'true'); element.setAttribute('data-active-within', 'true');
selectAll('.js-lpb-ui', element) setUiElementVisibility();
.filter((uiElement) => uiElement.closest('.js-lpb-component') === element)
.forEach((uiElement) => uiElement.classList.remove('visually-hidden'));
// Add the data-active-within attribute to all parent elements. // Add the data-active-within attribute to all parent elements.
let parent = element.parentNode.closest('.js-lpb-component'); let parent = element.parentNode.closest('.js-lpb-component');
while (parent) { while (parent) {
...@@ -160,10 +169,9 @@ ...@@ -160,10 +169,9 @@
const containerUiElements = uiElements[id] || []; const containerUiElements = uiElements[id] || [];
Object.values(containerUiElements).forEach((uiElement) => { Object.values(containerUiElements).forEach((uiElement) => {
const { element, method } = uiElement; const { element, method } = uiElement;
$container[method]( $container[method]($(element).addClass('js-lpb-ui'));
$(element).addClass('js-lpb-ui').addClass('visually-hidden'),
);
}); });
setUiElementVisibility();
} }
/** /**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment