Skip to content

Commit dad0923

Browse files
committed
feat: add ouia support to dropdown next
1 parent 22fc7d8 commit dad0923

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed

packages/react-core/src/next/components/Dropdown/Dropdown.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ import React from 'react';
22
import { css } from '@patternfly/react-styles';
33
import { Menu, MenuContent, MenuProps } from '../../../components/Menu';
44
import { Popper } from '../../../helpers/Popper/Popper';
5+
import { useOUIAProps, OUIAProps } from '../../../helpers';
56

6-
export interface DropdownProps extends MenuProps {
7+
export interface DropdownProps extends MenuProps, OUIAProps {
78
/** Anything which can be rendered in a dropdown. */
89
children?: React.ReactNode;
910
/** Classes applied to root element of dropdown. */
@@ -23,6 +24,10 @@ export interface DropdownProps extends MenuProps {
2324
isScrollable?: boolean;
2425
/** Min width of the menu. */
2526
minWidth?: string;
27+
/** Value to overwrite the randomly generated data-ouia-component-id.*/
28+
ouiaId?: number | string;
29+
/** 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. */
30+
ouiaSafe?: boolean;
2631
}
2732

2833
export const Dropdown: React.FunctionComponent<DropdownProps> = ({
@@ -35,11 +40,14 @@ export const Dropdown: React.FunctionComponent<DropdownProps> = ({
3540
isPlain,
3641
isScrollable,
3742
minWidth,
43+
ouiaId,
44+
ouiaSafe = true,
3845
...props
3946
}: DropdownProps) => {
4047
const localMenuRef = React.useRef<HTMLDivElement>();
4148
const toggleRef = React.useRef<HTMLButtonElement>();
4249
const containerRef = React.useRef<HTMLDivElement>();
50+
const ouiaProps = useOUIAProps(Dropdown.displayName, ouiaId, ouiaSafe);
4351

4452
const menuRef = (props.innerRef as React.RefObject<HTMLDivElement>) || localMenuRef;
4553
React.useEffect(() => {
@@ -101,7 +109,7 @@ export const Dropdown: React.FunctionComponent<DropdownProps> = ({
101109
</Menu>
102110
);
103111
return (
104-
<div ref={containerRef}>
112+
<div ref={containerRef} {...ouiaProps}>
105113
<Popper
106114
trigger={toggle(toggleRef)}
107115
removeFindDomNode
Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,34 @@
11
import React from 'react';
22
import { css } from '@patternfly/react-styles';
33
import { MenuItemProps, MenuItem } from '../../../components/Menu';
4+
import { useOUIAProps, OUIAProps } from '../../../helpers';
45

5-
export interface DropdownItemProps extends Omit<MenuItemProps, 'ref'> {
6+
export interface DropdownItemProps extends Omit<MenuItemProps, 'ref'>, OUIAProps {
67
/** Anything which can be rendered in a dropdown item */
78
children?: React.ReactNode;
89
/** Classes applied to root element of dropdown item */
910
className?: string;
1011
/** Description of the dropdown item */
1112
description?: React.ReactNode;
13+
/** Value to overwrite the randomly generated data-ouia-component-id.*/
14+
ouiaId?: number | string;
15+
/** 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. */
16+
ouiaSafe?: boolean;
1217
}
1318

1419
export const DropdownItem: React.FunctionComponent<MenuItemProps> = ({
1520
children,
1621
className,
1722
description,
23+
ouiaId,
24+
ouiaSafe,
1825
...props
19-
}: DropdownItemProps) => (
20-
<MenuItem className={css(className)} description={description} {...props}>
21-
{children}
22-
</MenuItem>
23-
);
26+
}: DropdownItemProps) => {
27+
const ouiaProps = useOUIAProps(DropdownItem.displayName, ouiaId, ouiaSafe);
28+
return (
29+
<MenuItem className={css(className)} description={description} {...ouiaProps} {...props}>
30+
{children}
31+
</MenuItem>
32+
);
33+
};
2434
DropdownItem.displayName = 'DropdownItem';

0 commit comments

Comments
 (0)