@patternfly/react-core 4.205.1 → 4.206.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (27) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/dist/esm/components/HelperText/HelperText.d.ts +9 -0
  3. package/dist/esm/components/HelperText/HelperText.d.ts.map +1 -1
  4. package/dist/esm/components/HelperText/HelperText.js +2 -2
  5. package/dist/esm/components/HelperText/HelperText.js.map +1 -1
  6. package/dist/esm/components/HelperText/HelperTextItem.d.ts +9 -1
  7. package/dist/esm/components/HelperText/HelperTextItem.d.ts.map +1 -1
  8. package/dist/esm/components/HelperText/HelperTextItem.js +2 -2
  9. package/dist/esm/components/HelperText/HelperTextItem.js.map +1 -1
  10. package/dist/js/components/HelperText/HelperText.d.ts +9 -0
  11. package/dist/js/components/HelperText/HelperText.d.ts.map +1 -1
  12. package/dist/js/components/HelperText/HelperText.js +2 -2
  13. package/dist/js/components/HelperText/HelperText.js.map +1 -1
  14. package/dist/js/components/HelperText/HelperTextItem.d.ts +9 -1
  15. package/dist/js/components/HelperText/HelperTextItem.d.ts.map +1 -1
  16. package/dist/js/components/HelperText/HelperTextItem.js +2 -2
  17. package/dist/js/components/HelperText/HelperTextItem.js.map +1 -1
  18. package/dist/umd/react-core.js +4 -4
  19. package/dist/umd/react-core.min.css +35 -35
  20. package/dist/umd/react-core.min.js +1 -1
  21. package/package.json +5 -5
  22. package/src/components/HelperText/HelperText.tsx +17 -1
  23. package/src/components/HelperText/HelperTextItem.tsx +11 -1
  24. package/src/demos/HelperText.md +48 -0
  25. package/src/demos/examples/HelperText/HelperTextDynamicVariantStaticText.tsx +71 -0
  26. package/src/demos/examples/HelperText/HelperTextStaticVariantDynamicText.tsx +47 -0
  27. package/src/demos/examples/HelperText/HelperTextStaticVariantStaticText.tsx +30 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@patternfly/react-core",
3
- "version": "4.205.1",
3
+ "version": "4.206.0",
4
4
  "description": "This library provides a set of common React components for use with the PatternFly reference implementation.",
5
5
  "main": "dist/js/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -34,9 +34,9 @@
34
34
  "generate": "node scripts/copyStyles.js"
35
35
  },
36
36
  "dependencies": {
37
- "@patternfly/react-icons": "^4.56.1",
38
- "@patternfly/react-styles": "^4.55.1",
39
- "@patternfly/react-tokens": "^4.57.1",
37
+ "@patternfly/react-icons": "^4.57.0",
38
+ "@patternfly/react-styles": "^4.56.0",
39
+ "@patternfly/react-tokens": "^4.58.0",
40
40
  "focus-trap": "6.2.2",
41
41
  "react-dropzone": "9.0.0",
42
42
  "tippy.js": "5.1.2",
@@ -60,5 +60,5 @@
60
60
  "react": "^16.8.0 || ^17.0.0",
61
61
  "react-dom": "^16.8.0 || ^17.0.0"
62
62
  },
63
- "gitHead": "4d73b9030cf92b075c46a0eeab561d47070bec50"
63
+ "gitHead": "b29e37a88fa7fee5dde681b95a45957e348711fd"
64
64
  }
@@ -9,17 +9,33 @@ export interface HelperTextProps extends React.HTMLProps<HTMLDivElement | HTMLUL
9
9
  className?: string;
10
10
  /** Component type of the helper text container */
11
11
  component?: 'div' | 'ul';
12
+ /** ID for the helper text container. The value of this prop can be passed into a form component's
13
+ * aria-describedby prop when you intend for all helper text items to be announced to
14
+ * assistive technologies.
15
+ */
16
+ id?: string;
17
+ /** Flag for indicating whether the helper text container is a live region. Use this prop when you
18
+ * expect or intend for any helper text items within the container to be dynamically updated.
19
+ */
20
+ isLiveRegion?: boolean;
12
21
  }
13
22
 
14
23
  export const HelperText: React.FunctionComponent<HelperTextProps> = ({
15
24
  children,
16
25
  className,
17
26
  component = 'div',
27
+ id,
28
+ isLiveRegion = false,
18
29
  ...props
19
30
  }: HelperTextProps) => {
20
31
  const Component = component as any;
21
32
  return (
22
- <Component className={css(styles.helperText, className)} {...props}>
33
+ <Component
34
+ id={id}
35
+ className={css(styles.helperText, className)}
36
+ {...(isLiveRegion && { 'aria-live': 'polite' })}
37
+ {...props}
38
+ >
23
39
  {children}
24
40
  </Component>
25
41
  );
@@ -17,10 +17,18 @@ export interface HelperTextItemProps extends React.HTMLProps<HTMLDivElement | HT
17
17
  variant?: 'default' | 'indeterminate' | 'warning' | 'success' | 'error';
18
18
  /** Custom icon prefixing the helper text. This property will override the default icon paired with each helper text variant. */
19
19
  icon?: React.ReactNode;
20
- /** Flag indicating the helper text item is dynamic. */
20
+ /** Flag indicating the helper text item is dynamic. This prop should be used when the
21
+ * text content of the helper text item will never change, but the icon and styling will
22
+ * be dynamically updated via the `variant` prop.
23
+ */
21
24
  isDynamic?: boolean;
22
25
  /** Flag indicating the helper text should have an icon. Dynamic helper texts include icons by default while static helper texts do not. */
23
26
  hasIcon?: boolean;
27
+ /** ID for the helper text item. The value of this prop can be passed into a form component's
28
+ * aria-describedby prop when you intend for only specific helper text items to be announced to
29
+ * assistive technologies.
30
+ */
31
+ id?: string;
24
32
  }
25
33
 
26
34
  const variantStyle = {
@@ -39,12 +47,14 @@ export const HelperTextItem: React.FunctionComponent<HelperTextItemProps> = ({
39
47
  icon,
40
48
  isDynamic = false,
41
49
  hasIcon = isDynamic,
50
+ id,
42
51
  ...props
43
52
  }: HelperTextItemProps) => {
44
53
  const Component = component as any;
45
54
  return (
46
55
  <Component
47
56
  className={css(styles.helperTextItem, variantStyle[variant], isDynamic && styles.modifiers.dynamic, className)}
57
+ id={id}
48
58
  {...props}
49
59
  >
50
60
  {icon && (
@@ -0,0 +1,48 @@
1
+ ---
2
+ id: Helper text
3
+ section: components
4
+ ---
5
+
6
+ import MinusIcon from '@patternfly/react-icons/dist/esm/icons/minus-icon';
7
+ import ExclamationTriangleIcon from '@patternfly/react-icons/dist/esm/icons/exclamation-triangle-icon';
8
+ import CheckCircleIcon from '@patternfly/react-icons/dist/esm/icons/check-circle-icon';
9
+ import ExclamationCircleIcon from '@patternfly/react-icons/dist/esm/icons/exclamation-circle-icon';
10
+ import CheckIcon from '@patternfly/react-icons/dist/esm/icons/check-icon';
11
+ import TimesIcon from '@patternfly/react-icons/dist/esm/icons/times-icon';
12
+
13
+ ## Demos
14
+
15
+ ### Static variant with static text
16
+
17
+ In this demo, the static variant of the helper text item component (the default) is used, and the text itself will always be visible to users and will never change.
18
+
19
+ The `aria-describedby` attribute is passed into the text input component and is linked to the `id` of the helper text component. This allows assistive technologies to notify users of the helper text content when the input receives focus, which can be helpful if a user navigates away from and then back to the input.
20
+
21
+ Note that this demo does not validate the text input component. When it would need to be validated, there are other steps that would need to be taken to make it accessible, such as passing in `aria-invalid` and `aria-live` attributes to the appropriate components.
22
+
23
+ ```ts file='./examples/HelperText/HelperTextStaticVariantStaticText.tsx'
24
+ ```
25
+
26
+ ### Static variant with dynamic text
27
+
28
+ In this demo, the static variant of the helper text item component (the default) is used with the `hasIcon` prop passed in when there is an error, and the text itself dynamically updates based on the input value. When the input has a value of `johndoe`, an error is rendered to simulate a username already being taken, while an empty input renders other helper text. When the input is valid, no helper text is rendered.
29
+
30
+ The `aria-describedby` attribute is passed into the text input component and is linked to the `id` of the helper text component. Similar to the static variant with static text demo, this allows assistive technologies to notify users of the helper text content when the navigating to the input.
31
+
32
+ An `aria-live` region is passed into the helper text component, which allows assistive technologies to announce to users when any dynamic content within it updates, such as when the text content changes or gets rendered. Without this attribute, a user would have to navigate out of and back into the input field multiple times to check the status of their input.
33
+
34
+ The `aria-invalid` attribute is also passed into the text input, which allows assistive technologies to notify users that an input is invalid. When this attribute is true, it's important that users are notified of what is causing the input to be invalid; in this case, `aria-describedby` and `aria-live` help accomplish this.
35
+
36
+ ```ts file='./examples/HelperText/HelperTextStaticVariantDynamicText.tsx'
37
+ ```
38
+
39
+ ### Dynamic variant with static text
40
+
41
+ In this demo, the helper text item components have the `isDynamic` prop passed in. While the text content of the components is static, the icons and styling will change as the validation of the input changes.
42
+
43
+ The `aria-describedby` attribute is passed into the text input component and is linked to the id attribute of a helper text item that results in an invalid input. This will allow assistive technologies to only be notified of any outstanding criteria that has not been met when the input receives focus.
44
+
45
+ Similar to the static variant with dynamic text example, the `aria-invalid` attribute is passed in, allowing assistive technologies to announce to users when at least 1 item is causing the input to be invalid.
46
+
47
+ ```ts file='./examples/HelperText/HelperTextDynamicVariantStaticText.tsx'
48
+ ```
@@ -0,0 +1,71 @@
1
+ import React from 'react';
2
+ import { Form, FormGroup, FormHelperText, TextInput, HelperText, HelperTextItem } from '@patternfly/react-core';
3
+
4
+ export const HelperTextDynamicVariantDynamicText: React.FunctionComponent = () => {
5
+ const [value, setValue] = React.useState('');
6
+ const [inputValidation, setInputValidation] = React.useState({
7
+ ruleLength: 'indeterminate',
8
+ ruleCharacterTypes: 'indeterminate'
9
+ });
10
+ const { ruleLength, ruleCharacterTypes } = inputValidation;
11
+
12
+ React.useEffect(() => {
13
+ let lengthStatus = ruleLength;
14
+ let typeStatus = ruleCharacterTypes;
15
+
16
+ if (value === '') {
17
+ setInputValidation({
18
+ ruleLength: 'indeterminate',
19
+ ruleCharacterTypes: 'indeterminate'
20
+ });
21
+ return;
22
+ }
23
+
24
+ if (!/\d/g.test(value)) {
25
+ typeStatus = 'error';
26
+ } else {
27
+ typeStatus = 'success';
28
+ }
29
+
30
+ if (value.length < 5) {
31
+ lengthStatus = 'error';
32
+ } else {
33
+ lengthStatus = 'success';
34
+ }
35
+
36
+ setInputValidation({ ruleLength: lengthStatus, ruleCharacterTypes: typeStatus });
37
+ }, [value, ruleLength, ruleCharacterTypes]);
38
+
39
+ const handleInputChange = (inputValue: string) => {
40
+ setValue(inputValue);
41
+ };
42
+
43
+ const filterValidations = () => Object.keys(inputValidation).filter(item => inputValidation[item] !== 'success');
44
+
45
+ return (
46
+ <Form>
47
+ <FormGroup label="Username" isRequired fieldId="login-input-helper-text3">
48
+ <TextInput
49
+ isRequired
50
+ type="text"
51
+ id="login-input-helper-text3"
52
+ name="login-input-helper-text3"
53
+ onChange={handleInputChange}
54
+ aria-describedby={filterValidations().join(' ')}
55
+ aria-invalid={ruleCharacterTypes === 'error' || ruleLength === 'error'}
56
+ value={value}
57
+ />
58
+ <FormHelperText isHidden={false} component="div">
59
+ <HelperText component="ul">
60
+ <HelperTextItem component="li" id="ruleLength" isDynamic variant={ruleLength as any}>
61
+ Must be at least 5 characters in length
62
+ </HelperTextItem>
63
+ <HelperTextItem component="li" id="ruleCharacterTypes" isDynamic variant={ruleCharacterTypes as any}>
64
+ Must include at least 1 number
65
+ </HelperTextItem>
66
+ </HelperText>
67
+ </FormHelperText>
68
+ </FormGroup>
69
+ </Form>
70
+ );
71
+ };
@@ -0,0 +1,47 @@
1
+ import React from 'react';
2
+ import { Form, FormGroup, FormHelperText, TextInput, HelperText, HelperTextItem } from '@patternfly/react-core';
3
+
4
+ export const HelperTextStaticVariantDynamicText: React.FunctionComponent = () => {
5
+ const [value, setValue] = React.useState('');
6
+ const [inputValidation, setInputValidation] = React.useState('default');
7
+
8
+ const handleInputChange = (inputValue: string) => {
9
+ setValue(inputValue);
10
+ };
11
+
12
+ React.useEffect(() => {
13
+ if (value === '') {
14
+ setInputValidation('default');
15
+ } else if (value === 'johndoe') {
16
+ setInputValidation('error');
17
+ } else {
18
+ setInputValidation('success');
19
+ }
20
+ }, [value]);
21
+
22
+ return (
23
+ <Form>
24
+ <FormGroup label="Username" isRequired fieldId="login-input-helper-text2">
25
+ <TextInput
26
+ isRequired
27
+ type="text"
28
+ id="login-input-helper-text2"
29
+ name="login-input-helper-text2"
30
+ onChange={handleInputChange}
31
+ aria-describedby="helper-text2"
32
+ aria-invalid={inputValidation === 'error'}
33
+ value={value}
34
+ />
35
+ <FormHelperText isHidden={false} component="div">
36
+ <HelperText id="helper-text2" aria-live="polite">
37
+ {inputValidation !== 'success' && (
38
+ <HelperTextItem variant={inputValidation as any} hasIcon={inputValidation === 'error'}>
39
+ {inputValidation === 'default' ? 'Please enter a username' : 'Username already exists'}
40
+ </HelperTextItem>
41
+ )}
42
+ </HelperText>
43
+ </FormHelperText>
44
+ </FormGroup>
45
+ </Form>
46
+ );
47
+ };
@@ -0,0 +1,30 @@
1
+ import React from 'react';
2
+ import { Form, FormGroup, FormHelperText, TextInput, HelperText, HelperTextItem } from '@patternfly/react-core';
3
+
4
+ export const HelperTextStaticVariantStaticText: React.FunctionComponent = () => {
5
+ const [value, setValue] = React.useState('');
6
+
7
+ const handleInputChange = (inputValue: string) => {
8
+ setValue(inputValue);
9
+ };
10
+
11
+ return (
12
+ <Form>
13
+ <FormGroup label="Middle Name" fieldId="login-input-helper-text1">
14
+ <TextInput
15
+ type="text"
16
+ id="login-input-helper-text1"
17
+ name="login-input-helper-text1"
18
+ onChange={handleInputChange}
19
+ aria-describedby="helper-text1"
20
+ value={value}
21
+ />
22
+ <FormHelperText isHidden={false} component="div">
23
+ <HelperText id="helper-text1">
24
+ <HelperTextItem variant={'default'}>Enter your middle name or your middle initial</HelperTextItem>
25
+ </HelperText>
26
+ </FormHelperText>
27
+ </FormGroup>
28
+ </Form>
29
+ );
30
+ };