From 08dc8652af860ab374b981c8a33cc158a0bdf57e Mon Sep 17 00:00:00 2001 From: Gustavo Santos Date: Sun, 2 Oct 2022 20:33:54 -0300 Subject: [PATCH] feat: add ouia support to dropdown next --- .../src/next/components/Dropdown/Dropdown.tsx | 12 ++++++++-- .../next/components/Dropdown/DropdownItem.tsx | 22 ++++++++++++++----- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/packages/react-core/src/next/components/Dropdown/Dropdown.tsx b/packages/react-core/src/next/components/Dropdown/Dropdown.tsx index 7b26cfb63fb..83a9996ee1a 100644 --- a/packages/react-core/src/next/components/Dropdown/Dropdown.tsx +++ b/packages/react-core/src/next/components/Dropdown/Dropdown.tsx @@ -2,8 +2,9 @@ import React from 'react'; import { css } from '@patternfly/react-styles'; import { Menu, MenuContent, MenuProps } from '../../../components/Menu'; import { Popper } from '../../../helpers/Popper/Popper'; +import { useOUIAProps, OUIAProps } from '../../../helpers'; -export interface DropdownProps extends MenuProps { +export interface DropdownProps extends MenuProps, OUIAProps { /** Anything which can be rendered in a dropdown. */ children?: React.ReactNode; /** Classes applied to root element of dropdown. */ @@ -25,6 +26,10 @@ export interface DropdownProps extends MenuProps { minWidth?: string; /** @hide Forwarded ref */ innerRef?: React.Ref; + /** 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 DropdownBase: React.FunctionComponent = ({ @@ -38,11 +43,14 @@ const DropdownBase: React.FunctionComponent = ({ isScrollable, minWidth, innerRef, + ouiaId, + ouiaSafe = true, ...props }: DropdownProps) => { const localMenuRef = React.useRef(); const toggleRef = React.useRef(); const containerRef = React.useRef(); + const ouiaProps = useOUIAProps(Dropdown.displayName, ouiaId, ouiaSafe); const menuRef = (innerRef as React.RefObject) || localMenuRef; React.useEffect(() => { @@ -104,7 +112,7 @@ const DropdownBase: React.FunctionComponent = ({ ); return ( -
+
{ +export interface DropdownItemProps extends Omit, OUIAProps { /** Anything which can be rendered in a dropdown item */ children?: React.ReactNode; /** Classes applied to root element of dropdown item */ className?: string; /** Description of the dropdown item */ description?: React.ReactNode; + /** 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; } export const DropdownItem: React.FunctionComponent = ({ children, className, description, + ouiaId, + ouiaSafe, ...props -}: DropdownItemProps) => ( - - {children} - -); +}: DropdownItemProps) => { + const ouiaProps = useOUIAProps(DropdownItem.displayName, ouiaId, ouiaSafe); + return ( + + {children} + + ); +}; DropdownItem.displayName = 'DropdownItem';