Skip to content

Commit

Permalink
fix: use hue normalized color in handle and allow focus
Browse files Browse the repository at this point in the history
  • Loading branch information
Westbrook committed Apr 7, 2021
1 parent 8e0fd9c commit f9e1fa2
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
11 changes: 6 additions & 5 deletions packages/color-area/stories/color-area.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,23 @@ export const joint = (): TemplateResult => {
<sp-color-area
color="#7f3e3e"
@input=${({ target }: Event & { target: ColorArea }) => {
const display = (target.nextElementSibling as HTMLElement)
.nextElementSibling as HTMLElement;
const next = target.nextElementSibling as ColorSlider;
const display = next.nextElementSibling as HTMLElement;
display.textContent = target.color as string;
display.style.color = target.color as string;
next.color = target.color;
}}
></sp-color-area>
<sp-color-slider
color="#7f3e3e"
@input=${({
target: { value, previousElementSibling },
target: { color, previousElementSibling },
}: Event & {
target: ColorSlider & {
value: number;
previousElementSibling: ColorArea;
};
}): void => {
previousElementSibling.hue = value;
previousElementSibling.color = color;
}}
></sp-color-slider>
<div style="color: #7f3e3e">#7f3e3e</div>
Expand Down
8 changes: 7 additions & 1 deletion packages/color-slider/src/ColorSlider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,9 @@ export class ColorSlider extends Focusable {
this._previousColor = this._color.clone();
this.boundingClientRect = this.getBoundingClientRect();
(event.target as HTMLElement).setPointerCapture(event.pointerId);
if (event.pointerType === 'mouse') {
this.handleFocus();
}
}

private handlePointermove(event: PointerEvent): void {
Expand Down Expand Up @@ -284,6 +287,9 @@ export class ColorSlider extends Focusable {
if (!applyDefault) {
this._color = this._previousColor;
}
if (event.pointerType === 'mouse') {
this.handleBlur();
}
}

/**
Expand Down Expand Up @@ -336,7 +342,7 @@ export class ColorSlider extends Focusable {
</div>
<sp-color-handle
class="handle"
color=${this._color.toHslString()}
color="hsl(${this._color.toHsl().h}, 100%, 50%)"
?disabled=${this.disabled}
style="${this.vertical ? 'top' : 'left'}: ${this
.sliderHandlePosition}%"
Expand Down
8 changes: 7 additions & 1 deletion packages/color-wheel/src/ColorWheel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,9 @@ export class ColorWheel extends Focusable {
this._previousColor = this._color.clone();
this.boundingClientRect = this.getBoundingClientRect();
(event.target as HTMLElement).setPointerCapture(event.pointerId);
if (event.pointerType === 'mouse') {
this.handleFocus();
}
}

private handlePointermove(event: PointerEvent): void {
Expand Down Expand Up @@ -261,6 +264,9 @@ export class ColorWheel extends Focusable {
if (!applyDefault) {
this._color = this._previousColor;
}
if (event.pointerType === 'mouse') {
this.handleBlur();
}
}

/**
Expand Down Expand Up @@ -314,7 +320,7 @@ export class ColorWheel extends Focusable {
<sp-color-handle
class="handle"
color=${this._color.toHslString()}
color="hsl(${this._color.toHsl().h}, 100%, 50%)"
?disabled=${this.disabled}
style=${handleLocationStyles}
@manage=${streamingListener(
Expand Down

0 comments on commit f9e1fa2

Please sign in to comment.