From d9750a7b9951e5fe145505db075a705fc8ef87ed Mon Sep 17 00:00:00 2001 From: mshriver Date: Mon, 20 Jul 2026 09:40:08 -0400 Subject: [PATCH] chore(Slider): Include OUIAProps for Slider Add OUIA attribute support to Slider for better test automation. Co-authored-by: Cursor --- .../src/components/Slider/Slider.tsx | 11 +++++- .../Slider/__tests__/Slider.test.tsx | 22 ++++++++++- .../__snapshots__/Slider.test.tsx.snap | 39 ++++++++++++++++--- packages/react-core/src/helpers/OUIA/OUIA.md | 1 + 4 files changed, 65 insertions(+), 8 deletions(-) diff --git a/packages/react-core/src/components/Slider/Slider.tsx b/packages/react-core/src/components/Slider/Slider.tsx index 08b8dadf339..6845518e5da 100644 --- a/packages/react-core/src/components/Slider/Slider.tsx +++ b/packages/react-core/src/components/Slider/Slider.tsx @@ -8,6 +8,7 @@ import { Tooltip, TooltipProps } from '../Tooltip'; import cssSliderValue from '@patternfly/react-tokens/dist/esm/c_slider_value'; import cssFormControlWidthChars from '@patternfly/react-tokens/dist/esm/c_slider__value_c_form_control_width_chars'; import { getLanguageDirection } from '../../helpers/util'; +import { useOUIAProps, OUIAProps } from '../../helpers'; /** Properties for creating custom steps in a slider. These properties should be passed in as * an object within an array to the slider component's customSteps property. @@ -29,7 +30,7 @@ export type SliderOnChangeEvent = | React.FocusEvent; /** The main slider component. */ -export interface SliderProps extends Omit, 'onChange'> { +export interface SliderProps extends Omit, 'onChange'>, OUIAProps { /** Flag indicating if the slider is discrete for custom steps. This will cause the slider * to snap to the closest value. */ @@ -93,6 +94,10 @@ export interface SliderProps extends Omit, 'onCh thumbAriaValueText?: string; /** Current value of the slider. */ value?: number; + /** Value to overwrite the randomly generated data-ouia-component-id.*/ + ouiaId?: number | string; + /** Set the value of data-ouia-safe. Only set to true when the component is in a static state, i.e. no animations are occurring. At all other times, this value must be false. */ + ouiaSafe?: boolean; } const getPercentage = (current: number, max: number) => (100 * current) / max; @@ -126,8 +131,11 @@ export const Slider: React.FunctionComponent = ({ showBoundaries = true, 'aria-describedby': ariaDescribedby, 'aria-labelledby': ariaLabelledby, + ouiaId, + ouiaSafe = true, ...props }: SliderProps) => { + const ouiaProps = useOUIAProps(Slider.displayName, ouiaId, ouiaSafe); const sliderRailRef = useRef(undefined); const thumbRef = useRef(undefined); @@ -457,6 +465,7 @@ export const Slider: React.FunctionComponent = ({ className={css(styles.slider, className, isDisabled && styles.modifiers.disabled)} style={{ ...style, ...inputStyle }} {...props} + {...ouiaProps} > {(leftActions || startActions) &&
{leftActions || startActions}
}
diff --git a/packages/react-core/src/components/Slider/__tests__/Slider.test.tsx b/packages/react-core/src/components/Slider/__tests__/Slider.test.tsx index 8bb83203c76..11d4ad245fc 100644 --- a/packages/react-core/src/components/Slider/__tests__/Slider.test.tsx +++ b/packages/react-core/src/components/Slider/__tests__/Slider.test.tsx @@ -5,7 +5,7 @@ import { Button } from '../../Button'; describe('slider', () => { test('renders continuous slider', () => { - const { asFragment } = render(); + const { asFragment } = render(); expect(asFragment()).toMatchSnapshot(); }); @@ -91,6 +91,26 @@ describe('slider', () => { }); }); +test('Renders with custom ouiaId', () => { + const { container } = render(); + expect(container.firstChild).toHaveAttribute('data-ouia-component-id', 'test-id'); +}); + +test('Renders with expected ouia component type', () => { + const { container } = render(); + expect(container.firstChild).toHaveAttribute('data-ouia-component-type', 'PF6/Slider'); +}); + +test('Renders with ouiaSafe defaulting to true', () => { + const { container } = render(); + expect(container.firstChild).toHaveAttribute('data-ouia-safe', 'true'); +}); + +test('Renders with ouiaSafe=false when specified', () => { + const { container } = render(); + expect(container.firstChild).toHaveAttribute('data-ouia-safe', 'false'); +}); + test('renders slider with aria-labelledby', () => { render( <> diff --git a/packages/react-core/src/components/Slider/__tests__/__snapshots__/Slider.test.tsx.snap b/packages/react-core/src/components/Slider/__tests__/__snapshots__/Slider.test.tsx.snap index 3cb539b1129..dea3a20938c 100644 --- a/packages/react-core/src/components/Slider/__tests__/__snapshots__/Slider.test.tsx.snap +++ b/packages/react-core/src/components/Slider/__tests__/__snapshots__/Slider.test.tsx.snap @@ -4,6 +4,9 @@ exports[`slider renders continuous slider 1`] = `