diff --git a/packages/react-components/react-color-picker-preview/library/src/components/ColorSlider/ColorSlider.test.tsx b/packages/react-components/react-color-picker-preview/library/src/components/ColorSlider/ColorSlider.test.tsx
index faa827fef4cc7d..5e34689a56f1c3 100644
--- a/packages/react-components/react-color-picker-preview/library/src/components/ColorSlider/ColorSlider.test.tsx
+++ b/packages/react-components/react-color-picker-preview/library/src/components/ColorSlider/ColorSlider.test.tsx
@@ -1,5 +1,5 @@
import * as React from 'react';
-import { render } from '@testing-library/react';
+import { render, screen } from '@testing-library/react';
import { isConformant } from '../../testing/isConformant';
import { ColorSlider } from './ColorSlider';
@@ -34,4 +34,51 @@ describe('ColorSlider', () => {
`);
});
+
+ it('handles id prop', () => {
+ const testId = 'test-id';
+ render();
+ expect(screen.getByRole('slider').getAttribute('id')).toEqual(testId);
+ });
+
+ it('applies the defaultValue prop', () => {
+ render();
+ expect(screen.getByRole('slider').getAttribute('value')).toEqual('10');
+ });
+
+ it('applies the value prop', () => {
+ render();
+ expect(screen.getByRole('slider').getAttribute('value')).toEqual('10');
+ });
+
+ it('applies the correct value prop when min is set', () => {
+ render();
+ expect(screen.getByRole('slider').getAttribute('value')).toEqual('20');
+ });
+
+ it('applies the correct value prop when max is set', () => {
+ render();
+ expect(screen.getByRole('slider').getAttribute('value')).toEqual('20');
+ });
+
+ it('clamps an initial defaultValue that is out of bounds', () => {
+ render();
+ expect(screen.getByRole('slider').getAttribute('value')).toEqual('0');
+ });
+
+ it('applies focus to the hidden input', () => {
+ render();
+ const input = screen.getByRole('slider');
+
+ input.focus();
+ expect(document.activeElement).toEqual(input);
+ });
+
+ it('applies aria-valuetext', () => {
+ const testValue = 'test-value';
+
+ render();
+
+ expect(screen.getByRole('slider').getAttribute('aria-label')).toEqual(testValue);
+ });
});
diff --git a/packages/react-components/react-color-picker-preview/library/src/components/ColorSlider/useColorSliderState.ts b/packages/react-components/react-color-picker-preview/library/src/components/ColorSlider/useColorSliderState.ts
index 6bbc204cae75dc..03baa8d3105430 100644
--- a/packages/react-components/react-color-picker-preview/library/src/components/ColorSlider/useColorSliderState.ts
+++ b/packages/react-components/react-color-picker-preview/library/src/components/ColorSlider/useColorSliderState.ts
@@ -16,10 +16,11 @@ export const useColorSliderState_unstable = (state: ColorSliderState, props: Col
'use no memo';
const { dir } = useFluent();
- const { min = 0, max = MAX_COLOR_HUE, onChange, value } = props;
+ const { defaultValue, min = 0, max = MAX_COLOR_HUE, onChange, value } = props;
const [currentValue, setCurrentValue] = useControllableState({
state: value,
+ defaultState: defaultValue,
initialState: 0,
});
const clampedValue = clamp(currentValue, min, max);