Skip to content

fix(colorarea): remove layout thrashing and cache selectors #5550

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/rotten-parents-do.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@spectrum-web-components/color-area': patch
---

Remove layout invalidation and cache selectors
44 changes: 19 additions & 25 deletions packages/color-area/src/ColorArea.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export class ColorArea extends SpectrumElement {
@property({ type: String, attribute: 'label-y' })
public labelY = 'luminosity';

@query('.handle')
@query('.handle', true)
private handle!: ColorHandle;

private languageResolver = new LanguageResolutionController(this);
Expand Down Expand Up @@ -126,57 +126,51 @@ export class ColorArea extends SpectrumElement {
@property({ attribute: false })
private activeAxis = 'x';

private _x = 1;

@property({ type: Number })
public get x(): number {
return this.colorController.color.hsv.s / 100;
}

public set x(x: number) {
if (x === this.x) {
const oldValue = this._x;
// Restrict x to the nearest step
const newValue = Math.round(x / this.step) * this.step;
if (newValue === oldValue) {
return;
}
const oldValue = this.x;
if (this.inputX) {
// Use the native `input[type='range']` control to validate this value after `firstUpdate`
this.inputX.value = x.toString();
this.colorController.color.set(
's',
this.inputX.valueAsNumber * 100
);
} else {
this.colorController.color.set('s', x * 100);
}
this._x = newValue;
this.colorController.color.set('s', newValue * 100);
this.requestUpdate('x', oldValue);
}

private _y = 1;

@property({ type: Number })
public get y(): number {
return this.colorController.color.hsv.v / 100;
}

public set y(y: number) {
if (y === this.y) {
const oldValue = this._y;
// Restrict y to the nearest step
const newValue = Math.round(y / this.step) * this.step;
if (newValue === oldValue) {
return;
}
const oldValue = this.y;
if (this.inputY) {
// Use the native `input[type='range']` control to validate this value after `firstUpdate`
this.inputY.value = y.toString();
this.colorController.color.set(
'v',
this.inputY.valueAsNumber * 100
);
}
this._y = newValue;
this.colorController.color.set('v', newValue * 100);
this.requestUpdate('y', oldValue);
}

@property({ type: Number })
public step = 0.01;

@query('[name="x"]')
@query('[name="x"]', true)
public inputX!: HTMLInputElement;

@query('[name="y"]')
@query('[name="y"]', true)
public inputY!: HTMLInputElement;

private altered = 0;
Expand Down
Loading