Skip to content

Commit cc6b9cd

Browse files
committed
Hide filtering and copy button if JS is disabled
1 parent a2813cd commit cc6b9cd

File tree

4 files changed

+89
-90
lines changed

4 files changed

+89
-90
lines changed

src/_includes/linter-rule-cards.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141

4242
<div class="trailing">
4343
<a href="/tools/linter-rules/{{lint.name}}" title="Learn more about this lint and when to enable it.">Learn more</a>
44-
<button class="copy-button configuring" title="Copy {{lint.name}} to your clipboard.">Copy</button>
44+
<button class="copy-button hidden" title="Copy {{lint.name}} to your clipboard.">Copy</button>
4545
</div>
4646

4747
</div>

src/_sass/components/_linter-rules.scss

+74-72
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ body.linter-rules {
1111
justify-content: center;
1212
gap: 0.75rem;
1313
margin-bottom: 1.25rem;
14+
15+
&.hidden {
16+
display: none;
17+
}
1418
}
1519

1620
.filter-group {
@@ -127,17 +131,15 @@ body.linter-rules {
127131
outline-offset: 1px;
128132
}
129133
}
134+
135+
button.hidden {
136+
display: none;
137+
}
130138
}
131139
}
132140
}
133141
}
134142

135-
.copy-button, #filter-and-search {
136-
&.configuring {
137-
display: none;
138-
}
139-
}
140-
141143
.chip-set {
142144
display: flex;
143145
flex-direction: row;
@@ -276,90 +278,90 @@ section.content-search-results {
276278
margin: 0.5rem 0 1rem;
277279
}
278280

279-
.select-menu {
280-
display: none;
281-
position: absolute;
282-
overflow: auto;
283-
z-index: 5;
284-
background-color: white;
285-
border-radius: 0.5rem;
286-
border: 1px solid rgb(63, 72, 80);
287-
min-width: 100%;
288-
max-height: 15rem;
289-
overflow-y: scroll;
290-
scrollbar-width: thin;
291-
overscroll-behavior: contain;
292-
margin-top: 0.25rem;
293-
294-
ul {
295-
list-style-type: none;
296-
padding: 0;
297-
margin: 0;
298-
width: 100%;
281+
.button-menu-wrapper {
282+
position: relative;
299283

300-
li {
301-
&:first-child {
302-
padding-top: 0.5rem;
303-
}
284+
.select-menu {
285+
display: none;
286+
position: absolute;
287+
overflow: auto;
288+
z-index: 5;
289+
background-color: white;
290+
border-radius: 0.5rem;
291+
border: 1px solid rgb(63, 72, 80);
292+
min-width: 100%;
293+
max-height: 15rem;
294+
overflow-y: scroll;
295+
scrollbar-width: thin;
296+
overscroll-behavior: contain;
297+
margin-top: 0.25rem;
298+
299+
ul {
300+
list-style-type: none;
301+
padding: 0;
302+
margin: 0;
303+
width: 100%;
304+
305+
li {
306+
&:first-child {
307+
padding-top: 0.5rem;
308+
}
304309

305-
&:last-child {
306-
padding-bottom: 0.5rem;
310+
&:last-child {
311+
padding-bottom: 0.5rem;
312+
}
307313
}
308-
}
309314

310-
button {
311-
padding: 0.2rem 0.75rem 0.2rem 0.5rem;
312-
width: 100%;
313-
border: none;
314-
background: none;
315-
color: rgb(63, 72, 80);
316-
font-weight: 500;
317-
text-align: left;
318-
user-select: none;
315+
button {
316+
padding: 0.2rem 0.75rem 0.2rem 0.5rem;
317+
width: 100%;
318+
border: none;
319+
background: none;
320+
color: rgb(63, 72, 80);
321+
font-weight: 500;
322+
text-align: left;
323+
user-select: none;
319324

320-
&:hover {
321-
@include interaction-style(4%);
322-
}
325+
&:hover {
326+
@include interaction-style(4%);
327+
}
323328

324-
&:focus {
325-
@include interaction-style(6%);
326-
}
329+
&:focus {
330+
@include interaction-style(6%);
331+
}
327332

328-
&:active {
329-
@include interaction-style(8%);
330-
}
333+
&:active {
334+
@include interaction-style(8%);
335+
}
331336

332-
display: flex;
333-
flex-direction: row;
337+
display: flex;
338+
flex-direction: row;
334339

335-
.material-symbols {
336-
align-self: center;
337-
vertical-align: center;
338-
fill: currentcolor;
339-
position: relative;
340-
font-size: 20px;
341-
margin-right: 0.4rem;
340+
.material-symbols {
341+
align-self: center;
342+
vertical-align: center;
343+
fill: currentcolor;
344+
position: relative;
345+
font-size: 20px;
346+
margin-right: 0.4rem;
342347

343-
font-variation-settings: 'FILL' 1;
344-
user-select: none;
345-
}
348+
font-variation-settings: 'FILL' 1;
349+
user-select: none;
350+
}
346351

347-
&.selected {
348-
background-color: #cae4ff;
352+
&.selected {
353+
background-color: #cae4ff;
354+
}
349355
}
350356
}
351-
}
352357

353-
&.show-menu {
354-
display: flex;
358+
&.show-menu {
359+
display: flex;
360+
}
355361
}
356362
}
357363

358364
.search-wrapper:has(:focus-visible), .chip:focus-visible, .empty-button:focus-visible, .trailing a:focus-visible, .trailing button:focus-visible {
359365
outline: 2px solid #1967D2;
360366
border-color: transparent;
361367
}
362-
363-
.button-menu-wrapper {
364-
position: relative;
365-
}

src/content/assets/js/linter-rules.js

+12-15
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,12 @@ function _setupFiltering() {
2626
// TODO(parlough): Show toast saying copied to clipboard.
2727
});
2828

29-
copyButton.classList.remove('configuring');
29+
copyButton.classList.remove('hidden');
3030
});
3131

3232
const filterAndSearch = document.getElementById('filter-and-search');
3333
if (!filterAndSearch) return;
34-
35-
function displayLints(lints) {
36-
lintCards.forEach(card => {
37-
const lintName = card.id;
38-
39-
if (lints.has(lintName)) {
40-
card.classList.remove('hidden');
41-
} else {
42-
card.classList.add('hidden');
43-
}
44-
});
45-
}
34+
filterAndSearch.classList.remove('hidden');
4635

4736
const filterChips = filterAndSearch.querySelectorAll('button.filter-chip');
4837
const chips = filterAndSearch.querySelectorAll('button.chip');
@@ -107,7 +96,15 @@ function _setupFiltering() {
10796
lintsToShow.add(lintName);
10897
}
10998

110-
displayLints(lintsToShow);
99+
lintCards.forEach(card => {
100+
const lintName = card.id;
101+
102+
if (lintsToShow.has(lintName)) {
103+
card.classList.remove('hidden');
104+
} else {
105+
card.classList.add('hidden');
106+
}
107+
});
111108
}
112109

113110
searchInput.addEventListener('input', filterRules);
@@ -126,7 +123,7 @@ function _setupFiltering() {
126123
});
127124

128125
document.addEventListener('keydown', (event) => {
129-
// If pressing esc in a menu, close any open menus.
126+
// If pressing the `esc` key in the filter area, close any open menus.
130127
if (event.key === 'Escape' && event.target.closest('#filter-and-search')) {
131128
_closeMenusAndToggle();
132129
}

src/content/tools/linter-rules/index.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,11 @@ check out [All linter rules](/tools/linter-rules/all).
120120

121121
---
122122

123-
{%- comment %}
123+
{% comment -%}
124124
TODO(parlough): Generate this HTML with some sort of component mechanism.
125125
{% endcomment -%}
126126

127-
<section id="filter-and-search">
127+
<section id="filter-and-search" class="hidden">
128128
<div class="search-row">
129129
<div class="search-wrapper">
130130
<span class="material-symbols leading-icon" aria-hidden="true">search</span>

0 commit comments

Comments
 (0)