diff --git a/packages/react-core/src/components/Form/FormFieldGroup.tsx b/packages/react-core/src/components/Form/FormFieldGroup.tsx index 8bfb8f4f87e..3c43a7f6d17 100644 --- a/packages/react-core/src/components/Form/FormFieldGroup.tsx +++ b/packages/react-core/src/components/Form/FormFieldGroup.tsx @@ -1,3 +1,4 @@ +import type { FormFieldGroupHeaderProps } from './FormFieldGroupHeader'; import { InternalFormFieldGroup } from './InternalFormFieldGroup'; export interface FormFieldGroupProps extends Omit, 'label' | 'onToggle'> { @@ -5,8 +6,8 @@ export interface FormFieldGroupProps extends Omit; } export const FormFieldGroup: React.FunctionComponent = ({ diff --git a/packages/react-core/src/components/Form/FormFieldGroupExpandable.tsx b/packages/react-core/src/components/Form/FormFieldGroupExpandable.tsx index b5285b5e758..54f76b45fb0 100644 --- a/packages/react-core/src/components/Form/FormFieldGroupExpandable.tsx +++ b/packages/react-core/src/components/Form/FormFieldGroupExpandable.tsx @@ -1,4 +1,5 @@ import { useState } from 'react'; +import type { FormFieldGroupHeaderProps } from './FormFieldGroupHeader'; import { InternalFormFieldGroup } from './InternalFormFieldGroup'; import { useHasAnimations } from '../../helpers'; @@ -7,8 +8,8 @@ export interface FormFieldGroupExpandableProps extends Omit; /** Flag indicating if the form field group is initially expanded */ isExpanded?: boolean; /** Aria-label to use on the form field group toggle button */ diff --git a/packages/react-core/src/components/Form/FormFieldGroupHeader.tsx b/packages/react-core/src/components/Form/FormFieldGroupHeader.tsx index 594371056ca..ed1267bb126 100644 --- a/packages/react-core/src/components/Form/FormFieldGroupHeader.tsx +++ b/packages/react-core/src/components/Form/FormFieldGroupHeader.tsx @@ -11,9 +11,9 @@ export interface FormFieldGroupHeaderTitleTextObject { export interface FormFieldGroupHeaderProps extends React.HTMLProps { /** Additional classes added to the section */ className?: string; - /** Field group header title text */ - titleText?: FormFieldGroupHeaderTitleTextObject; - /** Field group header title description */ + /** Field group header title text. */ + titleText: FormFieldGroupHeaderTitleTextObject; + /** Field group header title description. Optional; displayed below the title text. */ titleDescription?: React.ReactNode; /** Field group header actions */ actions?: React.ReactNode; diff --git a/packages/react-core/src/components/Form/__tests__/FormFieldGroup.test.tsx b/packages/react-core/src/components/Form/__tests__/FormFieldGroup.test.tsx index b7b09c64141..53871abd512 100644 --- a/packages/react-core/src/components/Form/__tests__/FormFieldGroup.test.tsx +++ b/packages/react-core/src/components/Form/__tests__/FormFieldGroup.test.tsx @@ -47,7 +47,10 @@ test('Verify console error logged when there is no aria-label or title', () => { const FieldGroup = ( } />} + header={ + // @ts-expect-error titleText is intentionally omitted to verify the runtime error is still logged + } /> + } /> ); render(FieldGroup); @@ -69,9 +72,3 @@ test('Verify field group has accessible name when header is passed in', () => { expect(screen.getByRole('group')).toHaveAccessibleName('Field group 4 (non-expandable)'); }); - -test('Verify field group does not have accessible name when header is not passed in', () => { - render(); - - expect(screen.getByRole('group')).not.toHaveAccessibleName(); -}); diff --git a/packages/react-core/src/components/Form/__tests__/FormFieldGroupExpandable.test.tsx b/packages/react-core/src/components/Form/__tests__/FormFieldGroupExpandable.test.tsx index b5d96014ff0..0090ab73c6e 100644 --- a/packages/react-core/src/components/Form/__tests__/FormFieldGroupExpandable.test.tsx +++ b/packages/react-core/src/components/Form/__tests__/FormFieldGroupExpandable.test.tsx @@ -1,17 +1,24 @@ import { render, screen } from '@testing-library/react'; import { FormFieldGroupExpandable } from '../FormFieldGroupExpandable'; +import { FormFieldGroupHeader } from '../FormFieldGroupHeader'; import { AnimationsProvider } from '../../../helpers/AnimationsProvider'; import styles from '@patternfly/react-styles/css/components/Form/form'; +const fieldGroupHeader = ; + test('Does not render children by default', () => { - render(Child content); + render( + + Child content + + ); expect(screen.queryByText('Child content')).not.toBeInTheDocument(); }); test('Renders children when isExpanded is true', () => { render( - + Child content ); @@ -21,7 +28,7 @@ test('Renders children when isExpanded is true', () => { test('Renders children with inert attribute by default when hasAnimations is true', () => { render( - + Child content ); @@ -31,7 +38,7 @@ test('Renders children with inert attribute by default when hasAnimations is tru test('Does not render children with inert attribute when hasAnimations and isExpanded are true', () => { render( - + Child content ); @@ -40,14 +47,18 @@ test('Does not render children with inert attribute when hasAnimations and isExp }); test(`Does not render with class ${styles.modifiers.expandable} by default`, () => { - render(Child content); + render( + + Child content + + ); expect(screen.getByRole('group')).not.toHaveClass(styles.modifiers.expandable); }); test(`Renders with class ${styles.modifiers.expandable} when hasAnimations is true`, () => { render( - + Child content ); @@ -59,7 +70,9 @@ test(`Renders with class ${styles.modifiers.expandable} when hasAnimations is tr test('respects AnimationsProvider context when no local hasAnimations prop', () => { render( - Child content + + Child content + ); @@ -69,7 +82,7 @@ test('respects AnimationsProvider context when no local hasAnimations prop', () test('local hasAnimations prop takes precedence over context', () => { render( - + Child content @@ -79,7 +92,11 @@ test('local hasAnimations prop takes precedence over context', () => { }); test('works without AnimationsProvider (backward compatibility)', () => { - render(Child content); + render( + + Child content + + ); expect(screen.getByRole('group')).not.toHaveClass(styles.modifiers.expandable); }); diff --git a/packages/react-core/src/components/Form/examples/Form.md b/packages/react-core/src/components/Form/examples/Form.md index 5b38dd1e4ef..7bddd72bfec 100644 --- a/packages/react-core/src/components/Form/examples/Form.md +++ b/packages/react-core/src/components/Form/examples/Form.md @@ -103,6 +103,8 @@ When using helper text inside a `FormGroup`, the `HelperText` component should b ### Field Groups +Field groups require a title per the [design guidelines](https://www.patternfly.org/components/forms/form/design-guidelines/#field-groups). For key-value pairs, we recommend the [field builder](https://www.patternfly.org/extensions/component-groups/field-builder) component group. + ```ts file="./FormFieldGroups.tsx" ```