diff --git a/packages/react-core/src/components/FileUpload/examples/FileUploadTextWithRestrictions.tsx b/packages/react-core/src/components/FileUpload/examples/FileUploadTextWithRestrictions.tsx index c84445b95ca..56f71a4f536 100644 --- a/packages/react-core/src/components/FileUpload/examples/FileUploadTextWithRestrictions.tsx +++ b/packages/react-core/src/components/FileUpload/examples/FileUploadTextWithRestrictions.tsx @@ -1,5 +1,5 @@ import React from 'react'; -import { FileUpload, Form, FormGroup } from '@patternfly/react-core'; +import { FileUpload, Form, FormGroup, FormHelperText, HelperText, HelperTextItem } from '@patternfly/react-core'; export const TextFileUploadWithRestrictions: React.FunctionComponent = () => { const [value, setValue] = React.useState(''); @@ -35,12 +35,7 @@ export const TextFileUploadWithRestrictions: React.FunctionComponent = () => { return (
- + { validated={isRejected ? 'error' : 'default'} browseButtonText="Upload" /> + + + + {isRejected ? 'Must be a CSV file no larger than 1 KB' : 'Upload a CSV file'} + + + ); diff --git a/packages/react-core/src/components/Form/FormGroup.tsx b/packages/react-core/src/components/Form/FormGroup.tsx index 6a63fa728b2..ddd9a3e5723 100644 --- a/packages/react-core/src/components/Form/FormGroup.tsx +++ b/packages/react-core/src/components/Form/FormGroup.tsx @@ -2,7 +2,6 @@ import * as React from 'react'; import styles from '@patternfly/react-styles/css/components/Form/form'; import { ASTERISK } from '../../helpers/htmlConstants'; import { css } from '@patternfly/react-styles'; -import { ValidatedOptions } from '../../helpers/constants'; import { GenerateId } from '../../helpers/GenerateId/GenerateId'; export interface FormGroupProps extends Omit, 'label'> { @@ -18,28 +17,12 @@ export interface FormGroupProps extends Omit, 'l labelIcon?: React.ReactElement; /** Sets the FormGroup required. */ isRequired?: boolean; - /** - * Sets the FormGroup validated. If you set to success, text color of helper text will be modified to indicate valid state. - * If set to error, text color of helper text will be modified to indicate error state. - * If set to warning, text color of helper text will be modified to indicate warning state. - */ - validated?: 'success' | 'warning' | 'error' | 'default'; /** Sets the FormGroup isInline. */ isInline?: boolean; /** Sets the FormGroupControl to be stacked */ isStack?: boolean; /** Removes top spacer from label. */ hasNoPaddingTop?: boolean; - /** Helper text regarding the field. It can be a simple text or an object. */ - helperText?: React.ReactNode; - /** Flag to position the helper text before the field. False by default */ - isHelperTextBeforeField?: boolean; - /** Helper text after the field when the field is invalid. It can be a simple text or an object. */ - helperTextInvalid?: React.ReactNode; - /** Icon displayed to the left of the helper text. */ - helperTextIcon?: React.ReactNode; - /** Icon displayed to the left of the helper text when the field is invalid. */ - helperTextInvalidIcon?: React.ReactNode; /** ID of an individual field or a group of multiple fields. Required when a role of "group" or "radiogroup" is passed in. * If only one field is included, its ID attribute and this prop must be the same. */ @@ -57,53 +40,13 @@ export const FormGroup: React.FunctionComponent = ({ labelInfo, labelIcon, isRequired = false, - validated = 'default', isInline = false, hasNoPaddingTop = false, isStack = false, - helperText, - isHelperTextBeforeField = false, - helperTextInvalid, - helperTextIcon, - helperTextInvalidIcon, fieldId, role, ...props }: FormGroupProps) => { - const validHelperText = - typeof helperText !== 'string' ? ( - helperText - ) : ( -
- {helperTextIcon && {helperTextIcon}} - {helperText} -
- ); - - const inValidHelperText = - typeof helperTextInvalid !== 'string' ? ( - helperTextInvalid - ) : ( -
- {helperTextInvalidIcon && {helperTextInvalidIcon}} - {helperTextInvalid} -
- ); - - const showValidHelperTxt = (validationType: 'success' | 'warning' | 'error' | 'default') => - validationType !== ValidatedOptions.error && helperText ? validHelperText : ''; - - const helperTextToDisplay = - validated === ValidatedOptions.error && helperTextInvalid ? inValidHelperText : showValidHelperTxt(validated); - const isGroupOrRadioGroup = role === 'group' || role === 'radiogroup'; const LabelComponent = isGroupOrRadioGroup ? 'span' : 'label'; @@ -124,7 +67,7 @@ export const FormGroup: React.FunctionComponent = ({ return ( - {randomId => ( + {(randomId) => (
= ({ isStack && styles.modifiers.stack )} > - {isHelperTextBeforeField && helperTextToDisplay} {children} - {!isHelperTextBeforeField && helperTextToDisplay}
)} diff --git a/packages/react-core/src/components/Form/FormHelperText.tsx b/packages/react-core/src/components/Form/FormHelperText.tsx index e61bd26b231..2807886eac9 100644 --- a/packages/react-core/src/components/Form/FormHelperText.tsx +++ b/packages/react-core/src/components/Form/FormHelperText.tsx @@ -3,43 +3,19 @@ import { css } from '@patternfly/react-styles'; import styles from '@patternfly/react-styles/css/components/Form/form'; export interface FormHelperTextProps extends React.HTMLProps { - /** Content rendered inside the Helper Text Item */ + /** Content rendered inside the helper text wrapper */ children?: React.ReactNode; - /** Adds error styling to the Helper Text * */ - isError?: boolean; - /** Hides the helper text * */ - isHidden?: boolean; - /** Additional classes added to the Helper Text Item */ + /** Additional classes added to the helper text wrapper */ className?: string; - /** Icon displayed to the left of the helper text. */ - icon?: React.ReactNode; - /** Component type of the form helper text */ - component?: 'p' | 'div'; } export const FormHelperText: React.FunctionComponent = ({ children = null, - isError = false, - isHidden = true, className = '', - icon = null, - component = 'p', ...props -}: FormHelperTextProps) => { - const Component = component as any; - return ( - - {icon && {icon}} - {children} - - ); -}; +}: FormHelperTextProps) => ( +
+ {children} +
+); FormHelperText.displayName = 'FormHelperText'; diff --git a/packages/react-core/src/components/Form/__tests__/FormGroup.test.tsx b/packages/react-core/src/components/Form/__tests__/FormGroup.test.tsx index a3c66f2c470..0e72a884954 100644 --- a/packages/react-core/src/components/Form/__tests__/FormGroup.test.tsx +++ b/packages/react-core/src/components/Form/__tests__/FormGroup.test.tsx @@ -12,7 +12,7 @@ describe('FormGroup', () => { test('should render default form group variant', () => { const { asFragment } = render( - + ); @@ -21,7 +21,7 @@ describe('FormGroup', () => { test('should render inline form group variant', () => { render( - + ); @@ -30,13 +30,7 @@ describe('FormGroup', () => { test('should render no padding-top form group variant', () => { render( - + ); @@ -80,30 +74,10 @@ describe('FormGroup', () => { expect(screen.getByText('label')).toBeInTheDocument(); }); - test('should render form group variant with node helperText', () => { - render( - Header}> - - - ); - - expect(screen.getByRole('heading', { name: 'Header' })).toBeInTheDocument(); - }); - - test('should render form group variant with function helperText', () => { - render( - - - - ); - - expect(screen.getByText('label')).toBeInTheDocument(); - }); - test('should render horizontal form group variant', () => { const { asFragment } = render(
- + @@ -114,18 +88,7 @@ describe('FormGroup', () => { test('should render stacked horizontal form group variant', () => { const { asFragment } = render(
- - - -
- ); - expect(asFragment()).toMatchSnapshot(); - }); - - test('should render helper text above input', () => { - const { asFragment } = render( -
- + @@ -142,58 +105,6 @@ describe('FormGroup', () => { expect(asFragment()).toMatchSnapshot(); }); - test('should render form group invalid variant', () => { - const { asFragment } = render( - - - - ); - expect(asFragment()).toMatchSnapshot(); - }); - - test('should render form group validated success variant', () => { - const { asFragment } = render( - - - - ); - - expect(screen.getByTestId('form-group-test-id').querySelector('input + div')).toHaveClass('pf-m-success'); - expect(asFragment()).toMatchSnapshot(); - }); - - test('should render form group validated error variant', () => { - const { asFragment } = render( - - - - ); - expect(asFragment()).toMatchSnapshot(); - }); - - test('should render form group validated warning variant', () => { - const { asFragment } = render( - - - - ); - - expect(screen.getByTestId('form-group-test-id').querySelector('input + div')).toHaveClass('pf-m-warning'); - expect(asFragment()).toMatchSnapshot(); - }); - test('should render correctly when label is not a string with Children = Array', () => { const { asFragment } = render( @@ -245,7 +156,7 @@ describe('FormGroup', () => { const inputs = screen.getAllByRole('textbox'); await user.click(labelElement); - inputs.forEach(input => { + inputs.forEach((input) => { expect(input).not.toHaveFocus(); }); }); diff --git a/packages/react-core/src/components/Form/__tests__/FormHelperText.test.tsx b/packages/react-core/src/components/Form/__tests__/FormHelperText.test.tsx index fe3277253f1..4bf14b4d3e4 100644 --- a/packages/react-core/src/components/Form/__tests__/FormHelperText.test.tsx +++ b/packages/react-core/src/components/Form/__tests__/FormHelperText.test.tsx @@ -7,20 +7,7 @@ import { FormHelperText } from '../FormHelperText'; describe('FormHelperText', () => { test('renders with PatternFly Core styles', () => { - const { asFragment } = render( - - test - - ); - expect(asFragment()).toMatchSnapshot(); - }); - - test('renders with icon', () => { - const { asFragment } = render( - }> - test - - ); + const { asFragment } = render(test); expect(asFragment()).toMatchSnapshot(); }); diff --git a/packages/react-core/src/components/Form/__tests__/__snapshots__/FormGroup.test.tsx.snap b/packages/react-core/src/components/Form/__tests__/__snapshots__/FormGroup.test.tsx.snap index a1cf9815318..3add5f8e9eb 100644 --- a/packages/react-core/src/components/Form/__tests__/__snapshots__/FormGroup.test.tsx.snap +++ b/packages/react-core/src/components/Form/__tests__/__snapshots__/FormGroup.test.tsx.snap @@ -63,160 +63,6 @@ exports[`FormGroup should render default form group variant 1`] = ` -
- this is helper text -
- - - -`; - -exports[`FormGroup should render form group invalid variant 1`] = ` - -
-
- - -
-
- -
- Invalid FormGroup -
-
-
-
-`; - -exports[`FormGroup should render form group validated error variant 1`] = ` - -
-
- - -
-
- -
-
-
-`; - -exports[`FormGroup should render form group validated success variant 1`] = ` - -
-
- - -
-
- -
- Validated FormGroup -
-
-
-
-`; - -exports[`FormGroup should render form group validated warning variant 1`] = ` - -
-
- - -
-
- -
- Validated FormGroup -
@@ -350,49 +196,6 @@ exports[`FormGroup should render form group with additonal label info 1`] = ` `; -exports[`FormGroup should render helper text above input 1`] = ` - -
-
-
- - -
-
-
- this is helperText -
- -
-
-
-
-`; - exports[`FormGroup should render horizontal form group variant 1`] = `
-
- this is helperText -
@@ -466,13 +262,6 @@ exports[`FormGroup should render stacked horizontal form group variant 1`] = ` -
- this is helperText -
diff --git a/packages/react-core/src/components/Form/__tests__/__snapshots__/FormHelperText.test.tsx.snap b/packages/react-core/src/components/Form/__tests__/__snapshots__/FormHelperText.test.tsx.snap index d2b7e7d9b5e..f56fec72ef1 100644 --- a/packages/react-core/src/components/Form/__tests__/__snapshots__/FormHelperText.test.tsx.snap +++ b/packages/react-core/src/components/Form/__tests__/__snapshots__/FormHelperText.test.tsx.snap @@ -2,59 +2,32 @@ exports[`FormHelperText LoginFooterItem with custom node 1`] = ` -

-

- My custom node +
+
+ My custom node +
-

`; exports[`FormHelperText className is added to the root element 1`] = ` -

test -

+
`; exports[`FormHelperText renders with PatternFly Core styles 1`] = ` -

test -

-
-`; - -exports[`FormHelperText renders with icon 1`] = ` - -

- - - - test -

+
`; diff --git a/packages/react-core/src/components/Form/examples/Form.md b/packages/react-core/src/components/Form/examples/Form.md index 5a2edfe76d9..0cd0163fa19 100644 --- a/packages/react-core/src/components/Form/examples/Form.md +++ b/packages/react-core/src/components/Form/examples/Form.md @@ -14,7 +14,7 @@ propComponents: 'FormFieldGroupHeader', 'FormFieldGroupHeaderTitleTextObject', 'Button', - 'Popover', + 'Popover' ] --- @@ -40,62 +40,76 @@ import TrashIcon from '@patternfly/react-icons/dist/esm/icons/trash-icon'; ## Examples +When using helper text inside a `FormGroup`, the `HelperText` component should be wrapped with the `FormHelperText` component to provide additional spacing. + ### Basic ```ts file="./FormBasic.tsx" + ``` ### Horizontal ```ts file="./FormHorizontal.tsx" + ``` ### Limit width ```ts file="./FormLimitWidth.tsx" + ``` ### Invalid ```ts file="./FormInvalid.tsx" + ``` ### Invalid with form alert ```ts file="./FormInvalidWithFormAlert.tsx" + ``` ### Validated ```ts file="./FormValidated.tsx" + ``` ### Horizontal stacked no padding top ```ts file="./FormHorizontalStacked.tsx" + ``` ### Horizontal stacked helper text on top ```ts file="./FormHorizontalHelper.tsx" + ``` ### Form group with additional label info ```ts file="./FormGroupLabelInfo.tsx" + ``` ### Form Sections ```ts file="./FormSections.tsx" + ``` ### Grid form ```ts file="./FormGrid.tsx" + ``` ### Field Groups ```ts file="./FormFieldGroups.tsx" + ``` diff --git a/packages/react-core/src/components/Form/examples/FormBasic.tsx b/packages/react-core/src/components/Form/examples/FormBasic.tsx index 4fb293b2f40..807bfb00e10 100644 --- a/packages/react-core/src/components/Form/examples/FormBasic.tsx +++ b/packages/react-core/src/components/Form/examples/FormBasic.tsx @@ -1,5 +1,17 @@ import React from 'react'; -import { Form, FormGroup, TextInput, Checkbox, Popover, ActionGroup, Button, Radio } from '@patternfly/react-core'; +import { + Form, + FormGroup, + TextInput, + Checkbox, + Popover, + ActionGroup, + Button, + Radio, + HelperText, + HelperTextItem, + FormHelperText +} from '@patternfly/react-core'; import HelpIcon from '@patternfly/react-icons/dist/esm/icons/help-icon'; export const FormBasic: React.FunctionComponent = () => { @@ -54,7 +66,7 @@ export const FormBasic: React.FunctionComponent = () => {