Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions packages/react-core/src/next/components/Dropdown/Dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand All @@ -25,6 +26,10 @@ export interface DropdownProps extends MenuProps {
minWidth?: string;
/** @hide Forwarded ref */
innerRef?: React.Ref<any>;
/** 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<DropdownProps> = ({
Expand All @@ -38,11 +43,14 @@ const DropdownBase: React.FunctionComponent<DropdownProps> = ({
isScrollable,
minWidth,
innerRef,
ouiaId,
ouiaSafe = true,
...props
}: DropdownProps) => {
const localMenuRef = React.useRef<HTMLDivElement>();
const toggleRef = React.useRef<HTMLButtonElement>();
const containerRef = React.useRef<HTMLDivElement>();
const ouiaProps = useOUIAProps(Dropdown.displayName, ouiaId, ouiaSafe);

const menuRef = (innerRef as React.RefObject<HTMLDivElement>) || localMenuRef;
React.useEffect(() => {
Expand Down Expand Up @@ -104,7 +112,7 @@ const DropdownBase: React.FunctionComponent<DropdownProps> = ({
</Menu>
);
return (
<div ref={containerRef}>
<div ref={containerRef} {...ouiaProps}>
<Popper
trigger={toggle(toggleRef)}
removeFindDomNode
Expand Down
22 changes: 16 additions & 6 deletions packages/react-core/src/next/components/Dropdown/DropdownItem.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,34 @@
import React from 'react';
import { css } from '@patternfly/react-styles';
import { MenuItemProps, MenuItem } from '../../../components/Menu';
import { useOUIAProps, OUIAProps } from '../../../helpers';

export interface DropdownItemProps extends Omit<MenuItemProps, 'ref'> {
export interface DropdownItemProps extends Omit<MenuItemProps, 'ref'>, 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<MenuItemProps> = ({
children,
className,
description,
ouiaId,
ouiaSafe,
...props
}: DropdownItemProps) => (
<MenuItem className={css(className)} description={description} {...props}>
{children}
</MenuItem>
);
}: DropdownItemProps) => {
const ouiaProps = useOUIAProps(DropdownItem.displayName, ouiaId, ouiaSafe);
return (
<MenuItem className={css(className)} description={description} {...ouiaProps} {...props}>
{children}
</MenuItem>
);
};
DropdownItem.displayName = 'DropdownItem';