Skip to content

Commit

Permalink
fix(color-area): providing x and y attributes renders color handle co…
Browse files Browse the repository at this point in the history
…rrectly (#4240)

* fix(color-area): providing x and y attributes renders color handle correctly

* fix(color-area): minor fix
  • Loading branch information
blunteshwar authored Apr 4, 2024
1 parent e19af30 commit 9eb5056
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
7 changes: 5 additions & 2 deletions packages/color-area/src/ColorArea.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,9 @@ export class ColorArea extends SpectrumElement {
v: this.y,
}),
applyColorToState: ({ s, v }) => {
this.x = s;
this.y = v;
this._x = s;
this._y = v;
this.requestUpdate();
},
});

Expand Down Expand Up @@ -128,6 +129,7 @@ export class ColorArea extends SpectrumElement {
this._x = x;
}
this.requestUpdate('x', oldValue);
this.colorController.applyColorFromState();
}

private _x = 1;
Expand All @@ -150,6 +152,7 @@ export class ColorArea extends SpectrumElement {
this._y = y;
}
this.requestUpdate('y', oldValue);
this.colorController.applyColorFromState();
}

private _y = 1;
Expand Down
32 changes: 32 additions & 0 deletions packages/color-area/test/color-area.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,38 @@ describe('ColorArea', () => {
'something custom Color Picker'
);
});
it('updates color when x value changes', async () => {
const el = await fixture<ColorArea>(
html`
<sp-color-area></sp-color-area>
`
);

await el.updateComplete;

const handle = el.shadowRoot.querySelector('.handle') as ColorHandle;

expect(handle.color).to.equal('hsl(0, 100%, 50%)');
el.x = 0.3;
await el.updateComplete;
expect(handle.color).to.equal('hsl(0, 100%, 85%)');
});
it('updates color when y value changes', async () => {
const el = await fixture<ColorArea>(
html`
<sp-color-area></sp-color-area>
`
);

await el.updateComplete;

const handle = el.shadowRoot.querySelector('.handle') as ColorHandle;

expect(handle.color).to.equal('hsl(0, 100%, 50%)');
el.y = 0.7;
await el.updateComplete;
expect(handle.color).to.equal('hsl(0, 100%, 35%)');
});
it('accepts `hue` values', async () => {
const el = await fixture<ColorArea>(
html`
Expand Down

0 comments on commit 9eb5056

Please sign in to comment.