Skip to content

Commit 7e80233

Browse files
authored
Merge pull request #144 from arrowtype/enable-muted-sliders
Re-enable muted sliders when interacted with
2 parents 3743231 + 06bb557 commit 7e80233

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

src/form.ts

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,19 @@ async function getFont(id: string): Promise<Font | null> {
313313
return font;
314314
}
315315

316+
function reenableMutedSliders(font: Font, container: Element) {
317+
(container as HTMLElement).addEventListener(
318+
"mousedown",
319+
async () => {
320+
if (!font.inherit) return;
321+
container.classList.remove("mute");
322+
font.inherit = false;
323+
await updateFont(font);
324+
},
325+
{ once: true }
326+
);
327+
}
328+
316329
async function applyNamedInstance(e: Event) {
317330
const sel = e.target as HTMLSelectElement;
318331
const parent = sel.closest(".font") as HTMLFieldSetElement;
@@ -326,13 +339,9 @@ async function applyNamedInstance(e: Event) {
326339

327340
font.inherit = sel.value == "--inherit--";
328341

329-
sliders.querySelectorAll(".variable-slider").forEach(slider => {
330-
let input = slider.querySelector("input");
331-
input.disabled = font.inherit;
332-
});
333-
334342
if (font.inherit) {
335343
sliders.classList.add("mute");
344+
reenableMutedSliders(font, sliders);
336345
await updateFont(font);
337346
return;
338347
}
@@ -367,6 +376,9 @@ async function addVariableSliders(font: Font, el: HTMLElement) {
367376
// If we start with inherit, we start muted
368377
if (font.inherit) {
369378
container.classList.add("mute");
379+
// If a user clicks muted sliders, assume they want to
380+
// go into custom axes mode
381+
reenableMutedSliders(font, container);
370382
}
371383
}
372384

@@ -380,8 +392,6 @@ function addSlider(font: Font, axis: Axis, parent: HTMLElement) {
380392
const label: HTMLLabelElement = el.querySelector("label");
381393
const value: HTMLSpanElement = el.querySelector(".slider-value");
382394

383-
input.disabled = font.inherit;
384-
385395
label.innerText = axis.name;
386396

387397
input.name = `var-${axis.id}`;

src/popup.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,11 @@ textarea:focus {
329329
opacity: 0.5;
330330
}
331331

332+
.variable-sliders-container.mute input {
333+
accent-color: var(--gray-2);
334+
opacity: 0.5;
335+
}
336+
332337
.variable-slider {
333338
display: flex;
334339
margin-top: 0.125rem;

0 commit comments

Comments
 (0)