Skip to content

Commit 7ea5565

Browse files
mshriverclaude
andcommitted
Include OUIAProps for Form and FormGroup
Co-authored-by: Claude <noreply@anthropic.com>
1 parent 2753c22 commit 7ea5565

5 files changed

Lines changed: 45 additions & 321 deletions

File tree

packages/react-core/src/components/Form/Form.tsx

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ import { forwardRef } from 'react';
22
import styles from '@patternfly/react-styles/css/components/Form/form';
33
import { css } from '@patternfly/react-styles';
44
import cssMaxWidth from '@patternfly/react-tokens/dist/esm/c_form_m_limit_width_MaxWidth';
5+
import { useOUIAProps, OUIAProps } from '../../helpers';
56

6-
export interface FormProps extends Omit<React.HTMLProps<HTMLFormElement>, 'ref'> {
7+
export interface FormProps extends Omit<React.HTMLProps<HTMLFormElement>, 'ref'>, OUIAProps {
78
/** Anything that can be rendered as Form content. */
89
children?: React.ReactNode;
910
/** Additional classes added to the Form. */
@@ -16,6 +17,10 @@ export interface FormProps extends Omit<React.HTMLProps<HTMLFormElement>, 'ref'>
1617
maxWidth?: string;
1718
/** @hide Forwarded ref */
1819
innerRef?: React.Ref<any>;
20+
/** Value to overwrite the randomly generated data-ouia-component-id.*/
21+
ouiaId?: number | string;
22+
/** 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. */
23+
ouiaSafe?: boolean;
1924
}
2025

2126
const FormBase: React.FunctionComponent<FormProps> = ({
@@ -25,28 +30,34 @@ const FormBase: React.FunctionComponent<FormProps> = ({
2530
isWidthLimited = false,
2631
maxWidth = '',
2732
innerRef,
33+
ouiaId,
34+
ouiaSafe = true,
2835
...props
29-
}: FormProps) => (
30-
<form
31-
noValidate
32-
{...(maxWidth && {
33-
style: {
34-
[cssMaxWidth.name]: maxWidth,
35-
...props.style
36-
} as React.CSSProperties
37-
})}
38-
{...props}
39-
className={css(
40-
styles.form,
41-
isHorizontal && styles.modifiers.horizontal,
42-
(isWidthLimited || maxWidth) && styles.modifiers.limitWidth,
43-
className
44-
)}
45-
ref={innerRef}
46-
>
47-
{children}
48-
</form>
49-
);
36+
}: FormProps) => {
37+
const ouiaProps = useOUIAProps(Form.displayName, ouiaId, ouiaSafe);
38+
return (
39+
<form
40+
noValidate
41+
{...(maxWidth && {
42+
style: {
43+
[cssMaxWidth.name]: maxWidth,
44+
...props.style
45+
} as React.CSSProperties
46+
})}
47+
{...props}
48+
{...ouiaProps}
49+
className={css(
50+
styles.form,
51+
isHorizontal && styles.modifiers.horizontal,
52+
(isWidthLimited || maxWidth) && styles.modifiers.limitWidth,
53+
className
54+
)}
55+
ref={innerRef}
56+
>
57+
{children}
58+
</form>
59+
);
60+
};
5061

5162
export const Form = forwardRef((props: FormProps, ref: React.Ref<any>) => <FormBase innerRef={ref} {...props} />);
5263

packages/react-core/src/components/Form/FormGroup.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import { Fragment, isValidElement } from 'react';
22
import styles from '@patternfly/react-styles/css/components/Form/form';
33
import { ASTERISK } from '../../helpers/htmlConstants';
44
import { css } from '@patternfly/react-styles';
5-
import { useSSRSafeId } from '../../helpers';
5+
import { useSSRSafeId, useOUIAProps, OUIAProps } from '../../helpers';
66

7-
export interface FormGroupProps extends Omit<React.HTMLProps<HTMLDivElement>, 'label'> {
7+
export interface FormGroupProps extends Omit<React.HTMLProps<HTMLDivElement>, 'label'>, OUIAProps {
88
/** Anything that can be rendered as FormGroup content. */
99
children?: React.ReactNode;
1010
/** Additional classes added to the FormGroup. */
@@ -31,6 +31,10 @@ export interface FormGroupProps extends Omit<React.HTMLProps<HTMLDivElement>, 'l
3131
* radio inputs, or pass in "group" when the form group contains multiple of any other input type.
3232
*/
3333
role?: string;
34+
/** Value to overwrite the randomly generated data-ouia-component-id.*/
35+
ouiaId?: number | string;
36+
/** 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. */
37+
ouiaSafe?: boolean;
3438
}
3539

3640
export const FormGroup: React.FunctionComponent<FormGroupProps> = ({
@@ -45,8 +49,11 @@ export const FormGroup: React.FunctionComponent<FormGroupProps> = ({
4549
isStack = false,
4650
fieldId,
4751
role,
52+
ouiaId,
53+
ouiaSafe = true,
4854
...props
4955
}: FormGroupProps) => {
56+
const ouiaProps = useOUIAProps(FormGroup.displayName, ouiaId, ouiaSafe);
5057
const randomId = useSSRSafeId();
5158
const isGroupOrRadioGroup = role === 'group' || role === 'radiogroup';
5259
const LabelComponent = isGroupOrRadioGroup ? 'span' : 'label';
@@ -72,6 +79,7 @@ export const FormGroup: React.FunctionComponent<FormGroupProps> = ({
7279
{...(role && { role })}
7380
{...(isGroupOrRadioGroup && { 'aria-labelledby': `${fieldId || randomId}-legend` })}
7481
{...props}
82+
{...ouiaProps}
7583
>
7684
{label && (
7785
<div

packages/react-core/src/components/Form/__tests__/__snapshots__/Form.test.tsx.snap

Lines changed: 0 additions & 28 deletions
This file was deleted.

0 commit comments

Comments
 (0)