Skip to content

Commit 1b72e14

Browse files
committed
feat: hide catalog filter without JS, suppress Apply button with JS
Filter form is hidden by default and shown only when JS is active via a synchronous inline script that adds `class="js"` to <html> before paint, preventing any flash. Apply button is hidden by the custom element once JS is available since change-event filtering makes it redundant.
1 parent ad00a7f commit 1b72e14

3 files changed

Lines changed: 8 additions & 0 deletions

File tree

src/design/common/layout.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export function Layout({
2525
<link rel="icon" href={url('/assets/favicon-192x192.png', config.basePath)} sizes="192x192" type="image/png" />
2626
<link rel="apple-touch-icon" href={url('/assets/apple-touch-icon.png', config.basePath)} />
2727
<meta name="msapplication-TileImage" content={url('/assets/mstile-270x270.png', config.basePath)} />
28+
<script>{`document.documentElement.classList.add('js')`}</script>
2829
<script type="module" src={url('/enhancements/register.js', config.basePath)} defer></script>
2930
</head>
3031
<body>

src/design/components/catalog-filter/client.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
class CatalogFilter extends HTMLElement {
22
connectedCallback() {
3+
this.querySelector<HTMLElement>('[type="submit"]')?.setAttribute('hidden', '')
34
this.addEventListener('change', this.apply)
45
this.addEventListener('submit', this.preventAndApply)
56
}

src/design/components/catalog-filter/styles.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
catalog-filter { display: block; }
22

3+
/* Hidden until JS confirms it can do something useful */
34
.catalog-filter {
5+
display: none;
46
margin-block-end: var(--space-5);
57
}
68

9+
.js .catalog-filter {
10+
display: block;
11+
}
12+
713
.catalog-filter fieldset {
814
border: 1px solid var(--color-surface-alt);
915
border-radius: var(--radius-md);

0 commit comments

Comments
 (0)