Skip to content

Commit

Permalink
Merge pull request #822 from googlefonts/issue821
Browse files Browse the repository at this point in the history
Keep sliders as properties of an object instead of using element ids
  • Loading branch information
justvanrossum authored Sep 19, 2023
2 parents 9a7b2c1 + 00423f3 commit 6ff3380
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions src/fontra/client/web-components/designspace-location.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export class DesignspaceLocation extends UnlitElement {
// Event was triggered by us -- ignore
return;
}
const slider = this.shadowRoot.querySelector(`#slider-${event.key}`);
const slider = this._sliders?.[event.key];
if (slider) {
slider.value = event.newValue;
}
Expand All @@ -85,15 +85,15 @@ export class DesignspaceLocation extends UnlitElement {
this._values = { ...values };

for (const [axisName, value] of Object.entries(values)) {
const slider = this.shadowRoot.querySelector(`#slider-${axisName}`);
const slider = this._sliders?.[axisName];
if (slider) {
slider.value = value;
}
}

for (const axis of this.axes || []) {
if (!(axis.name in values)) {
const slider = this.shadowRoot.querySelector(`#slider-${axis.name}`);
const slider = this._sliders?.[axis.name];
if (slider) {
slider.value = axis.defaultValue;
}
Expand All @@ -105,6 +105,7 @@ export class DesignspaceLocation extends UnlitElement {
if (!this.axes) {
return;
}
this._sliders = [];
const elements = [];
for (const axis of this.axes) {
if (axis.isDivider) {
Expand All @@ -129,17 +130,16 @@ export class DesignspaceLocation extends UnlitElement {
[axis.name]
)
);
elements.push(
html.createDomElement("range-slider", {
id: `slider-${axis.name}`,
minValue: axis.minValue,
maxValue: axis.maxValue,
defaultValue: axis.defaultValue,
value: modelValue !== undefined ? modelValue : axis.defaultValue,
onChangeCallback: (event) =>
this._dispatchLocationChangedEvent(axis.name, event.value),
})
);
const slider = html.createDomElement("range-slider", {
minValue: axis.minValue,
maxValue: axis.maxValue,
defaultValue: axis.defaultValue,
value: modelValue !== undefined ? modelValue : axis.defaultValue,
onChangeCallback: (event) =>
this._dispatchLocationChangedEvent(axis.name, event.value),
});
this._sliders[axis.name] = slider;
elements.push(slider);
elements.push(infoBox);
}
return elements;
Expand Down

0 comments on commit 6ff3380

Please sign in to comment.