Skip to content

Commit

Permalink
fix: Hide sl-option elements by default
Browse files Browse the repository at this point in the history
  • Loading branch information
romshark committed Nov 12, 2024
1 parent 034dd00 commit ba5f0b4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 26 deletions.
19 changes: 10 additions & 9 deletions server/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,18 @@ document.addEventListener("htmx:afterRequest", function (event) {
}
});

function slOptionsReveal() {
document
.querySelectorAll("sl-option.hidden")
.forEach((o) => o.classList.remove("hidden"));
{
// Reveal <sl-option> elements once the page is loaded or
// parts of the page are reloaded to avoid CLS (cumulative layout shift).
function slOptionsReveal() {
document
.querySelectorAll("sl-option")
.forEach((o) => o.classList.add("visible"));
}
window.addEventListener("load", slOptionsReveal);
document.addEventListener("htmx:afterSwap", slOptionsReveal);
}

// Reveal <sl-option> elements once the page is loaded or
// parts of the page are reloaded to avoid CLS (cumulative layout shift).
window.addEventListener("load", slOptionsReveal);
document.addEventListener("htmx:afterSwap", slOptionsReveal);

enum Theme {
Light = "light",
Dark = "dark",
Expand Down
26 changes: 9 additions & 17 deletions server/input.tw.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,15 @@
@tailwind components;
@tailwind utilities;

/* Default global styles */
html button,
html input,
html select,
html textarea {
border: 1px solid grey;
border-radius: 0.2rem;
padding: 0.2rem;
padding-left: 0.3rem;
padding-right: 0.3rem;
height: 2rem;
background-color: transparent;
}

html table td {
border: 1px solid lightgrey;
padding: 0.2rem 0.5rem 0.2rem 0.5rem;
/* to avoid CLS (cumulative layout shift) on page load the "visible"
class will be added on `window.load` and `htmx:afterSwap` events. */

sl-option {
display: none;
}

sl-option.visible {
display: block;
}

/*--- HTMX loading indicator ---*/
Expand Down

0 comments on commit ba5f0b4

Please sign in to comment.