Skip to content

Commit 7beca86

Browse files
author
Michael Jordan
authored
fix(#3273): useColorWheelState getDisplayColor should not include alpha channel (#3274)
* fix(#3273): useColorWheelState getDisplayColor should not include alpha channel
1 parent fad66ba commit 7beca86

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

packages/@react-spectrum/color/test/ColorWheel.test.tsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,4 +331,25 @@ describe('ColorWheel', () => {
331331
expect(onChangeEndSpy).toHaveBeenCalledTimes(1);
332332
});
333333
});
334+
335+
it('thumb background color should not include alpha channel', () => {
336+
let defaultColor = parseColor('hsla(0, 100%, 50%, 0.5)');
337+
let {container: _container} = render(<ColorWheel defaultValue={defaultColor} />);
338+
/*
339+
Current DOM structure for ColorWheel, starting at the container:
340+
341+
div
342+
div.spectrum-ColorWheel
343+
div.spectrum-ColorWheel-gradient
344+
div.spectrum-ColorWheel-handle
345+
div.spectrum-ColorHandle-color
346+
svg.spectrum-ColorLoupe
347+
...
348+
input.spectrum-ColorWheel-slider
349+
*/
350+
let handleColorElement = _container.firstChild.firstChild.nextSibling.firstChild as HTMLElement;
351+
let thumbColor = parseColor(handleColorElement.style.backgroundColor);
352+
expect(defaultColor.getChannelValue('alpha')).toEqual(0.5);
353+
expect(thumbColor.getChannelValue('alpha')).toEqual(1);
354+
});
334355
});

packages/@react-stately/color/src/useColorWheelState.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ export function useColorWheelState(props: ColorWheelProps): ColorWheelState {
168168
},
169169
isDragging,
170170
getDisplayColor() {
171-
return value.toFormat('hsl').withChannelValue('saturation', 100).withChannelValue('lightness', 50);
171+
return value.toFormat('hsl').withChannelValue('saturation', 100).withChannelValue('lightness', 50).withChannelValue('alpha', 1);
172172
}
173173
};
174174
}

0 commit comments

Comments
 (0)