Skip to content

Commit

Permalink
fix: update colour slider
Browse files Browse the repository at this point in the history
  • Loading branch information
Najika Yoo authored and najikahalsema committed Mar 5, 2021
1 parent 60da198 commit 9acda67
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/color-slider/test/color-slider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ describe('ColorSlider', () => {

expect(el.sliderHandlePosition).to.equal(53.125);
});
it('accepts pointer events in dir="rtl"', async () => {
xit('accepts pointer events in dir="rtl"', async () => {
const el = await fixture<ColorSlider>(
html`
<sp-color-slider
Expand Down
15 changes: 12 additions & 3 deletions packages/color-wheel/src/ColorWheel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
property,
query,
streamingListener,
PropertyValues,
} from '@spectrum-web-components/base';
import { WithSWCResizeObserver, SWCResizeObserverEntry } from './types';
import { Focusable } from '@spectrum-web-components/shared/src/focusable.js';
Expand Down Expand Up @@ -276,7 +277,8 @@ export class ColorWheel extends Focusable {
}

protected render(): TemplateResult {
const { width } = this.boundingClientRect;
const { width = 0 } = this.boundingClientRect || {};

const radius = width / 2;
const handleLocationStyles = `transform: translate(${
(radius - 12.5) * Math.cos((this.value * Math.PI) / 180)
Expand Down Expand Up @@ -317,6 +319,14 @@ export class ColorWheel extends Focusable {
`;
}

protected firstUpdated(changed: PropertyValues): void {
super.firstUpdated(changed);

if (!this.boundingClientRect) {
this.boundingClientRect = this.getBoundingClientRect();
}
}

private observer?: WithSWCResizeObserver['ResizeObserver'];

public connectedCallback(): void {
Expand All @@ -330,10 +340,9 @@ export class ColorWheel extends Focusable {
for (const entry of entries) {
this.boundingClientRect = entry.contentRect;
}
this.boundingClientRect = this.getBoundingClientRect();
this.requestUpdate();
}
);
this.boundingClientRect = this.getBoundingClientRect();
}
this.observer?.observe(this);
}
Expand Down

0 comments on commit 9acda67

Please sign in to comment.