@patternfly/react-core 4.237.3 → 4.237.6
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.
- package/CHANGELOG.md +30 -0
- package/dist/esm/components/Checkbox/Checkbox.d.ts +7 -5
- package/dist/esm/components/Checkbox/Checkbox.d.ts.map +1 -1
- package/dist/esm/components/Checkbox/Checkbox.js +7 -3
- package/dist/esm/components/Checkbox/Checkbox.js.map +1 -1
- package/dist/esm/components/Dropdown/DropdownItem.d.ts +1 -1
- package/dist/esm/components/Dropdown/DropdownItem.d.ts.map +1 -1
- package/dist/esm/components/Dropdown/DropdownToggleCheckbox.js +2 -1
- package/dist/esm/components/Dropdown/DropdownToggleCheckbox.js.map +1 -1
- package/dist/esm/components/Dropdown/InternalDropdownItem.js +14 -11
- package/dist/esm/components/Dropdown/InternalDropdownItem.js.map +1 -1
- package/dist/esm/components/Dropdown/Toggle.js +9 -7
- package/dist/esm/components/Dropdown/Toggle.js.map +1 -1
- package/dist/esm/components/Modal/Modal.d.ts +2 -2
- package/dist/esm/components/Modal/Modal.d.ts.map +1 -1
- package/dist/esm/components/Modal/Modal.js +2 -1
- package/dist/esm/components/Modal/Modal.js.map +1 -1
- package/dist/esm/components/Modal/ModalBoxTitle.js +1 -1
- package/dist/esm/components/Modal/ModalBoxTitle.js.map +1 -1
- package/dist/esm/components/TextArea/TextArea.d.ts +3 -0
- package/dist/esm/components/TextArea/TextArea.d.ts.map +1 -1
- package/dist/esm/components/TextArea/TextArea.js +21 -10
- package/dist/esm/components/TextArea/TextArea.js.map +1 -1
- package/dist/esm/components/TreeView/TreeView.js +2 -2
- package/dist/esm/components/TreeView/TreeView.js.map +1 -1
- package/dist/esm/components/TreeView/TreeViewListItem.d.ts +1 -1
- package/dist/esm/components/TreeView/TreeViewListItem.d.ts.map +1 -1
- package/dist/esm/components/TreeView/TreeViewRoot.d.ts.map +1 -1
- package/dist/esm/components/TreeView/TreeViewRoot.js +30 -26
- package/dist/esm/components/TreeView/TreeViewRoot.js.map +1 -1
- package/dist/js/components/Checkbox/Checkbox.d.ts +7 -5
- package/dist/js/components/Checkbox/Checkbox.d.ts.map +1 -1
- package/dist/js/components/Checkbox/Checkbox.js +7 -3
- package/dist/js/components/Checkbox/Checkbox.js.map +1 -1
- package/dist/js/components/Dropdown/DropdownItem.d.ts +1 -1
- package/dist/js/components/Dropdown/DropdownItem.d.ts.map +1 -1
- package/dist/js/components/Dropdown/DropdownToggleCheckbox.js +2 -1
- package/dist/js/components/Dropdown/DropdownToggleCheckbox.js.map +1 -1
- package/dist/js/components/Dropdown/InternalDropdownItem.js +14 -11
- package/dist/js/components/Dropdown/InternalDropdownItem.js.map +1 -1
- package/dist/js/components/Dropdown/Toggle.js +9 -7
- package/dist/js/components/Dropdown/Toggle.js.map +1 -1
- package/dist/js/components/Modal/Modal.d.ts +2 -2
- package/dist/js/components/Modal/Modal.d.ts.map +1 -1
- package/dist/js/components/Modal/Modal.js +2 -1
- package/dist/js/components/Modal/Modal.js.map +1 -1
- package/dist/js/components/Modal/ModalBoxTitle.js +1 -1
- package/dist/js/components/Modal/ModalBoxTitle.js.map +1 -1
- package/dist/js/components/TextArea/TextArea.d.ts +3 -0
- package/dist/js/components/TextArea/TextArea.d.ts.map +1 -1
- package/dist/js/components/TextArea/TextArea.js +21 -10
- package/dist/js/components/TextArea/TextArea.js.map +1 -1
- package/dist/js/components/TreeView/TreeView.js +2 -2
- package/dist/js/components/TreeView/TreeView.js.map +1 -1
- package/dist/js/components/TreeView/TreeViewListItem.d.ts +1 -1
- package/dist/js/components/TreeView/TreeViewListItem.d.ts.map +1 -1
- package/dist/js/components/TreeView/TreeViewRoot.d.ts.map +1 -1
- package/dist/js/components/TreeView/TreeViewRoot.js +30 -26
- package/dist/js/components/TreeView/TreeViewRoot.js.map +1 -1
- package/dist/umd/react-core.min.css +200 -200
- package/dist/umd/react-core.min.js +6 -6
- package/package.json +5 -5
- package/src/components/Checkbox/Checkbox.tsx +16 -5
- package/src/components/Checkbox/examples/Checkbox.md +5 -0
- package/src/components/Checkbox/examples/CheckboxRequired.tsx +6 -0
- package/src/components/Dropdown/DropdownItem.tsx +1 -1
- package/src/components/Dropdown/DropdownToggleCheckbox.tsx +1 -1
- package/src/components/Dropdown/InternalDropdownItem.tsx +10 -10
- package/src/components/Dropdown/Toggle.tsx +8 -8
- package/src/components/Modal/Modal.tsx +3 -3
- package/src/components/Modal/ModalBoxTitle.tsx +1 -1
- package/src/components/TextArea/TextArea.tsx +26 -12
- package/src/components/TextArea/examples/TextArea.md +47 -21
- package/src/components/TreeView/TreeView.tsx +1 -1
- package/src/components/TreeView/TreeViewListItem.tsx +1 -1
- package/src/components/TreeView/TreeViewRoot.tsx +29 -25
- package/src/components/TreeView/examples/TreeView.md +37 -19
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@patternfly/react-core",
|
|
3
|
-
"version": "4.237.
|
|
3
|
+
"version": "4.237.6",
|
|
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",
|
|
@@ -44,9 +44,9 @@
|
|
|
44
44
|
"generate": "node scripts/copyStyles.js"
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@patternfly/react-icons": "^4.88.
|
|
48
|
-
"@patternfly/react-styles": "^4.87.
|
|
49
|
-
"@patternfly/react-tokens": "^4.89.
|
|
47
|
+
"@patternfly/react-icons": "^4.88.6",
|
|
48
|
+
"@patternfly/react-styles": "^4.87.6",
|
|
49
|
+
"@patternfly/react-tokens": "^4.89.6",
|
|
50
50
|
"focus-trap": "6.9.2",
|
|
51
51
|
"react-dropzone": "9.0.0",
|
|
52
52
|
"tippy.js": "5.1.2",
|
|
@@ -70,5 +70,5 @@
|
|
|
70
70
|
"react": "^16.8.0 || ^17.0.0",
|
|
71
71
|
"react-dom": "^16.8.0 || ^17.0.0"
|
|
72
72
|
},
|
|
73
|
-
"gitHead": "
|
|
73
|
+
"gitHead": "55fff2303d14e704bf9c55a5d5f2866e16a83a05"
|
|
74
74
|
}
|
|
@@ -3,20 +3,23 @@ import styles from '@patternfly/react-styles/css/components/Check/check';
|
|
|
3
3
|
import { css } from '@patternfly/react-styles';
|
|
4
4
|
import { PickOptional } from '../../helpers/typeUtils';
|
|
5
5
|
import { getDefaultOUIAId, getOUIAProps, OUIAProps } from '../../helpers';
|
|
6
|
+
import { ASTERISK } from '../../helpers/htmlConstants';
|
|
6
7
|
|
|
7
8
|
export interface CheckboxProps
|
|
8
9
|
extends Omit<React.HTMLProps<HTMLInputElement>, 'type' | 'onChange' | 'disabled' | 'label'>,
|
|
9
10
|
OUIAProps {
|
|
10
|
-
/** Additional classes added to the
|
|
11
|
+
/** Additional classes added to the checkbox. */
|
|
11
12
|
className?: string;
|
|
12
|
-
/** Flag to show if the
|
|
13
|
+
/** Flag to show if the checkbox selection is valid or invalid. */
|
|
13
14
|
isValid?: boolean;
|
|
14
|
-
/** Flag to show if the
|
|
15
|
+
/** Flag to show if the checkbox is disabled. */
|
|
15
16
|
isDisabled?: boolean;
|
|
16
|
-
/** Flag to show if the
|
|
17
|
+
/** Flag to show if the checkbox is required. */
|
|
18
|
+
isRequired?: boolean;
|
|
19
|
+
/** Flag to show if the checkbox is checked. If null, the checkbox will be indeterminate (partially checked). */
|
|
17
20
|
isChecked?: boolean | null;
|
|
18
21
|
checked?: boolean;
|
|
19
|
-
/** A callback for when the
|
|
22
|
+
/** A callback for when the checkbox selection changes. */
|
|
20
23
|
onChange?: (checked: boolean, event: React.FormEvent<HTMLInputElement>) => void;
|
|
21
24
|
/** Label text of the checkbox. */
|
|
22
25
|
label?: React.ReactNode;
|
|
@@ -45,6 +48,7 @@ export class Checkbox extends React.Component<CheckboxProps, CheckboxState> {
|
|
|
45
48
|
className: '',
|
|
46
49
|
isValid: true,
|
|
47
50
|
isDisabled: false,
|
|
51
|
+
isRequired: false,
|
|
48
52
|
isChecked: false,
|
|
49
53
|
onChange: defaultOnChange,
|
|
50
54
|
ouiaSafe: true,
|
|
@@ -69,6 +73,7 @@ export class Checkbox extends React.Component<CheckboxProps, CheckboxState> {
|
|
|
69
73
|
onChange,
|
|
70
74
|
isValid,
|
|
71
75
|
isDisabled,
|
|
76
|
+
isRequired,
|
|
72
77
|
isChecked,
|
|
73
78
|
label,
|
|
74
79
|
checked,
|
|
@@ -106,6 +111,7 @@ export class Checkbox extends React.Component<CheckboxProps, CheckboxState> {
|
|
|
106
111
|
aria-invalid={!isValid}
|
|
107
112
|
aria-label={ariaLabel}
|
|
108
113
|
disabled={isDisabled}
|
|
114
|
+
required={isRequired}
|
|
109
115
|
ref={elem => elem && (elem.indeterminate = isChecked === null)}
|
|
110
116
|
{...checkedProps}
|
|
111
117
|
{...getOUIAProps(Checkbox.displayName, ouiaId !== undefined ? ouiaId : this.state.ouiaStateId, ouiaSafe)}
|
|
@@ -113,6 +119,11 @@ export class Checkbox extends React.Component<CheckboxProps, CheckboxState> {
|
|
|
113
119
|
{label && (
|
|
114
120
|
<label className={css(styles.checkLabel, isDisabled && styles.modifiers.disabled)} htmlFor={props.id}>
|
|
115
121
|
{label}
|
|
122
|
+
{isRequired && (
|
|
123
|
+
<span className={css(styles.checkLabelRequired)} aria-hidden="true">
|
|
124
|
+
{ASTERISK}
|
|
125
|
+
</span>
|
|
126
|
+
)}
|
|
116
127
|
</label>
|
|
117
128
|
)}
|
|
118
129
|
{description && <span className={css(styles.checkDescription)}>{description}</span>}
|
|
@@ -3,7 +3,7 @@ import { InternalDropdownItemProps, InternalDropdownItem } from './InternalDropd
|
|
|
3
3
|
import { DropdownArrowContext } from './dropdownConstants';
|
|
4
4
|
import { useOUIAProps, OUIAProps } from '../../helpers';
|
|
5
5
|
|
|
6
|
-
export interface DropdownItemProps extends InternalDropdownItemProps, OUIAProps {
|
|
6
|
+
export interface DropdownItemProps extends Omit<InternalDropdownItemProps, 'tabIndex'>, OUIAProps {
|
|
7
7
|
/** Anything which can be rendered as dropdown item */
|
|
8
8
|
children?: React.ReactNode;
|
|
9
9
|
/** Classes applied to root element of dropdown item */
|
|
@@ -44,7 +44,7 @@ export class DropdownToggleCheckbox extends React.Component<DropdownToggleCheckb
|
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
handleChange = (event: React.FormEvent<HTMLInputElement>) => {
|
|
47
|
-
this.props.onChange((event.target as HTMLInputElement).checked, event);
|
|
47
|
+
this.props.onChange?.((event.target as HTMLInputElement).checked, event);
|
|
48
48
|
};
|
|
49
49
|
|
|
50
50
|
calculateChecked = () => {
|
|
@@ -87,7 +87,7 @@ export class InternalDropdownItem extends React.Component<InternalDropdownItemPr
|
|
|
87
87
|
componentDidMount() {
|
|
88
88
|
const { context, index, isDisabled, role, customChild, autoFocus } = this.props;
|
|
89
89
|
const customRef = customChild ? this.getInnerNode(this.ref.current) : this.ref.current;
|
|
90
|
-
context
|
|
90
|
+
context?.sendRef?.(
|
|
91
91
|
index,
|
|
92
92
|
[customRef, customChild ? customRef : this.additionalRef.current],
|
|
93
93
|
isDisabled,
|
|
@@ -99,7 +99,7 @@ export class InternalDropdownItem extends React.Component<InternalDropdownItemPr
|
|
|
99
99
|
componentDidUpdate() {
|
|
100
100
|
const { context, index, isDisabled, role, customChild } = this.props;
|
|
101
101
|
const customRef = customChild ? this.getInnerNode(this.ref.current) : this.ref.current;
|
|
102
|
-
context
|
|
102
|
+
context?.sendRef?.(
|
|
103
103
|
index,
|
|
104
104
|
[customRef, customChild ? customRef : this.additionalRef.current],
|
|
105
105
|
isDisabled,
|
|
@@ -116,21 +116,21 @@ export class InternalDropdownItem extends React.Component<InternalDropdownItemPr
|
|
|
116
116
|
event.preventDefault();
|
|
117
117
|
}
|
|
118
118
|
if (event.key === 'ArrowUp') {
|
|
119
|
-
this.props.context
|
|
119
|
+
this.props.context?.keyHandler?.(this.props.index, innerIndex, KEYHANDLER_DIRECTION.UP);
|
|
120
120
|
event.stopPropagation();
|
|
121
121
|
} else if (event.key === 'ArrowDown') {
|
|
122
|
-
this.props.context
|
|
122
|
+
this.props.context?.keyHandler?.(this.props.index, innerIndex, KEYHANDLER_DIRECTION.DOWN);
|
|
123
123
|
event.stopPropagation();
|
|
124
124
|
} else if (event.key === 'ArrowRight') {
|
|
125
|
-
this.props.context
|
|
125
|
+
this.props.context?.keyHandler?.(this.props.index, innerIndex, KEYHANDLER_DIRECTION.RIGHT);
|
|
126
126
|
event.stopPropagation();
|
|
127
127
|
} else if (event.key === 'ArrowLeft') {
|
|
128
|
-
this.props.context
|
|
128
|
+
this.props.context?.keyHandler?.(this.props.index, innerIndex, KEYHANDLER_DIRECTION.LEFT);
|
|
129
129
|
event.stopPropagation();
|
|
130
130
|
} else if (event.key === 'Enter' || event.key === ' ') {
|
|
131
131
|
event.target.click();
|
|
132
132
|
this.props.enterTriggersArrowDown &&
|
|
133
|
-
this.props.context
|
|
133
|
+
this.props.context?.keyHandler?.(this.props.index, innerIndex, KEYHANDLER_DIRECTION.DOWN);
|
|
134
134
|
}
|
|
135
135
|
};
|
|
136
136
|
|
|
@@ -264,13 +264,13 @@ export class InternalDropdownItem extends React.Component<InternalDropdownItemPr
|
|
|
264
264
|
|
|
265
265
|
return (
|
|
266
266
|
<li
|
|
267
|
-
|
|
267
|
+
{...(listItemClassName && { className: listItemClassName })}
|
|
268
268
|
role="none"
|
|
269
269
|
onKeyDown={this.onKeyDown}
|
|
270
270
|
onClick={(event: any) => {
|
|
271
271
|
if (!isDisabled && !isAriaDisabled) {
|
|
272
|
-
onClick(event);
|
|
273
|
-
onSelect(event);
|
|
272
|
+
onClick?.(event);
|
|
273
|
+
onSelect?.(event);
|
|
274
274
|
}
|
|
275
275
|
}}
|
|
276
276
|
id={id}
|
|
@@ -89,7 +89,7 @@ export class Toggle extends React.Component<ToggleProps> {
|
|
|
89
89
|
const clickedOnToggle = parentRef && parentRef.current && parentRef.current.contains(event.target as Node);
|
|
90
90
|
const clickedWithinMenu = menuRef && menuRef.contains && menuRef.contains(event.target as Node);
|
|
91
91
|
if (isOpen && !(clickedOnToggle || clickedWithinMenu)) {
|
|
92
|
-
onToggle(false, event);
|
|
92
|
+
onToggle?.(false, event);
|
|
93
93
|
}
|
|
94
94
|
};
|
|
95
95
|
|
|
@@ -103,8 +103,8 @@ export class Toggle extends React.Component<ToggleProps> {
|
|
|
103
103
|
(event.key === KeyTypes.Escape || event.key === 'Tab') &&
|
|
104
104
|
(escFromToggle || escFromWithinMenu)
|
|
105
105
|
) {
|
|
106
|
-
this.props.onToggle(false, event);
|
|
107
|
-
this.buttonRef.current
|
|
106
|
+
this.props.onToggle?.(false, event);
|
|
107
|
+
this.buttonRef.current?.focus();
|
|
108
108
|
}
|
|
109
109
|
};
|
|
110
110
|
|
|
@@ -118,15 +118,15 @@ export class Toggle extends React.Component<ToggleProps> {
|
|
|
118
118
|
}
|
|
119
119
|
event.preventDefault();
|
|
120
120
|
|
|
121
|
-
this.props.onToggle(!this.props.isOpen, event);
|
|
121
|
+
this.props.onToggle?.(!this.props.isOpen, event);
|
|
122
122
|
} else if ((event.key === 'Enter' || event.key === ' ') && !this.props.isOpen) {
|
|
123
123
|
if (!this.props.bubbleEvent) {
|
|
124
124
|
event.stopPropagation();
|
|
125
125
|
}
|
|
126
126
|
event.preventDefault();
|
|
127
127
|
|
|
128
|
-
this.props.onToggle(!this.props.isOpen, event);
|
|
129
|
-
this.props.onEnter();
|
|
128
|
+
this.props.onToggle?.(!this.props.isOpen, event);
|
|
129
|
+
this.props.onEnter?.();
|
|
130
130
|
}
|
|
131
131
|
};
|
|
132
132
|
|
|
@@ -167,11 +167,11 @@ export class Toggle extends React.Component<ToggleProps> {
|
|
|
167
167
|
isPlain && styles.modifiers.plain,
|
|
168
168
|
isText && styles.modifiers.text,
|
|
169
169
|
isPrimary && styles.modifiers.primary,
|
|
170
|
-
buttonVariantStyles[toggleVariant],
|
|
170
|
+
toggleVariant && buttonVariantStyles[toggleVariant],
|
|
171
171
|
className
|
|
172
172
|
)}
|
|
173
173
|
type={type || 'button'}
|
|
174
|
-
onClick={event => onToggle(!isOpen, event)}
|
|
174
|
+
onClick={event => onToggle?.(!isOpen, event)}
|
|
175
175
|
aria-expanded={isOpen}
|
|
176
176
|
aria-haspopup={ariaHasPopup}
|
|
177
177
|
onKeyDown={event => this.onKeyDown(event)}
|
|
@@ -26,7 +26,7 @@ export interface ModalProps extends React.HTMLProps<HTMLDivElement>, OUIAProps {
|
|
|
26
26
|
/** Optional title label text for screen readers */
|
|
27
27
|
titleLabel?: string;
|
|
28
28
|
/** Id to use for Modal Box label */
|
|
29
|
-
'aria-labelledby'?: string
|
|
29
|
+
'aria-labelledby'?: string;
|
|
30
30
|
/** Accessible descriptor of modal */
|
|
31
31
|
'aria-label'?: string;
|
|
32
32
|
/** Id to use for Modal Box descriptor */
|
|
@@ -121,7 +121,7 @@ export class Modal extends React.Component<ModalProps, ModalState> {
|
|
|
121
121
|
handleEscKeyClick = (event: KeyboardEvent): void => {
|
|
122
122
|
const { onEscapePress } = this.props;
|
|
123
123
|
if (event.key === KeyTypes.Escape && this.props.isOpen) {
|
|
124
|
-
onEscapePress ? onEscapePress(event) : this.props.onClose();
|
|
124
|
+
onEscapePress ? onEscapePress(event) : this.props.onClose?.();
|
|
125
125
|
}
|
|
126
126
|
};
|
|
127
127
|
|
|
@@ -143,7 +143,7 @@ export class Modal extends React.Component<ModalProps, ModalState> {
|
|
|
143
143
|
}
|
|
144
144
|
};
|
|
145
145
|
|
|
146
|
-
isEmpty = (value: string | null) => value === null || value === undefined || value === '';
|
|
146
|
+
isEmpty = (value: string | null | undefined) => value === null || value === undefined || value === '';
|
|
147
147
|
|
|
148
148
|
componentDidMount() {
|
|
149
149
|
const {
|
|
@@ -38,7 +38,7 @@ export const ModalBoxTitle: React.FunctionComponent<ModalBoxTitleProps> = ({
|
|
|
38
38
|
...props
|
|
39
39
|
}: ModalBoxTitleProps) => {
|
|
40
40
|
const [hasTooltip, setHasTooltip] = React.useState(false);
|
|
41
|
-
const h1 = React.useRef<HTMLHeadingElement>();
|
|
41
|
+
const h1 = React.useRef<HTMLHeadingElement>(null);
|
|
42
42
|
const label = titleLabel || (isVariantIcon(titleIconVariant) ? `${capitalize(titleIconVariant)} alert:` : titleLabel);
|
|
43
43
|
const variantIcons = {
|
|
44
44
|
success: <CheckCircleIcon />,
|
|
@@ -54,6 +54,21 @@ export class TextAreaBase extends React.Component<TextAreaProps> {
|
|
|
54
54
|
'aria-label': null as string
|
|
55
55
|
};
|
|
56
56
|
|
|
57
|
+
inputRef = React.createRef<HTMLTextAreaElement>();
|
|
58
|
+
|
|
59
|
+
private setAutoHeight = (field: HTMLTextAreaElement) => {
|
|
60
|
+
field.style.setProperty(heightToken.name, 'inherit');
|
|
61
|
+
const computed = window.getComputedStyle(field);
|
|
62
|
+
// Calculate the height
|
|
63
|
+
const height =
|
|
64
|
+
parseInt(computed.getPropertyValue('border-top-width')) +
|
|
65
|
+
parseInt(computed.getPropertyValue('padding-top')) +
|
|
66
|
+
field.scrollHeight +
|
|
67
|
+
parseInt(computed.getPropertyValue('padding-bottom')) +
|
|
68
|
+
parseInt(computed.getPropertyValue('border-bottom-width'));
|
|
69
|
+
field.style.setProperty(heightToken.name, `${height}px`);
|
|
70
|
+
};
|
|
71
|
+
|
|
57
72
|
constructor(props: TextAreaProps) {
|
|
58
73
|
super(props);
|
|
59
74
|
if (!props.id && !props['aria-label']) {
|
|
@@ -62,20 +77,19 @@ export class TextAreaBase extends React.Component<TextAreaProps> {
|
|
|
62
77
|
}
|
|
63
78
|
}
|
|
64
79
|
|
|
80
|
+
componentDidMount(): void {
|
|
81
|
+
const inputRef = this.props.innerRef || this.inputRef;
|
|
82
|
+
if (this.props.autoResize && canUseDOM) {
|
|
83
|
+
const field = inputRef.current;
|
|
84
|
+
this.setAutoHeight(field);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
65
88
|
private handleChange = (event: React.ChangeEvent<HTMLTextAreaElement>) => {
|
|
66
89
|
// https://gomakethings.com/automatically-expand-a-textarea-as-the-user-types-using-vanilla-javascript/
|
|
67
90
|
const field = event.currentTarget;
|
|
68
91
|
if (this.props.autoResize && canUseDOM) {
|
|
69
|
-
|
|
70
|
-
const computed = window.getComputedStyle(field);
|
|
71
|
-
// Calculate the height
|
|
72
|
-
const height =
|
|
73
|
-
parseInt(computed.getPropertyValue('border-top-width')) +
|
|
74
|
-
parseInt(computed.getPropertyValue('padding-top')) +
|
|
75
|
-
field.scrollHeight +
|
|
76
|
-
parseInt(computed.getPropertyValue('padding-bottom')) +
|
|
77
|
-
parseInt(computed.getPropertyValue('border-bottom-width'));
|
|
78
|
-
field.style.setProperty(heightToken.name, `${height}px`);
|
|
92
|
+
this.setAutoHeight(field);
|
|
79
93
|
}
|
|
80
94
|
if (this.props.onChange) {
|
|
81
95
|
this.props.onChange(field.value, event);
|
|
@@ -118,14 +132,14 @@ export class TextAreaBase extends React.Component<TextAreaProps> {
|
|
|
118
132
|
required={isRequired}
|
|
119
133
|
disabled={isDisabled || disabled}
|
|
120
134
|
readOnly={isReadOnly || readOnly}
|
|
121
|
-
ref={innerRef}
|
|
135
|
+
ref={innerRef || this.inputRef}
|
|
122
136
|
{...props}
|
|
123
137
|
/>
|
|
124
138
|
);
|
|
125
139
|
}
|
|
126
140
|
}
|
|
127
141
|
|
|
128
|
-
export const TextArea = React.forwardRef
|
|
142
|
+
export const TextArea = React.forwardRef((props: TextAreaProps, ref: React.Ref<HTMLTextAreaElement>) => (
|
|
129
143
|
<TextAreaBase {...props} innerRef={ref as React.MutableRefObject<any>} />
|
|
130
144
|
));
|
|
131
145
|
TextArea.displayName = 'TextArea';
|
|
@@ -6,7 +6,9 @@ propComponents: ['TextArea']
|
|
|
6
6
|
---
|
|
7
7
|
|
|
8
8
|
## Examples
|
|
9
|
+
|
|
9
10
|
### Basic
|
|
11
|
+
|
|
10
12
|
```js
|
|
11
13
|
import React from 'react';
|
|
12
14
|
import { TextArea } from '@patternfly/react-core';
|
|
@@ -32,6 +34,7 @@ class SimpleTextArea extends React.Component {
|
|
|
32
34
|
```
|
|
33
35
|
|
|
34
36
|
### Invalid
|
|
37
|
+
|
|
35
38
|
```js
|
|
36
39
|
import React from 'react';
|
|
37
40
|
import { TextArea } from '@patternfly/react-core';
|
|
@@ -42,7 +45,7 @@ class InvalidTextArea extends React.Component {
|
|
|
42
45
|
this.state = {
|
|
43
46
|
value: ''
|
|
44
47
|
};
|
|
45
|
-
|
|
48
|
+
|
|
46
49
|
this.handleInvalidTextAreaChange = value => {
|
|
47
50
|
this.setState({ value });
|
|
48
51
|
};
|
|
@@ -65,6 +68,7 @@ class InvalidTextArea extends React.Component {
|
|
|
65
68
|
```
|
|
66
69
|
|
|
67
70
|
### Validated
|
|
71
|
+
|
|
68
72
|
```js
|
|
69
73
|
import React from 'react';
|
|
70
74
|
import { Form, FormGroup, TextArea } from '@patternfly/react-core';
|
|
@@ -78,28 +82,30 @@ class InvalidTextArea extends React.Component {
|
|
|
78
82
|
validated: 'default',
|
|
79
83
|
helperText: 'Share your thoughts.'
|
|
80
84
|
};
|
|
81
|
-
|
|
85
|
+
|
|
82
86
|
this.simulateNetworkCall = callback => {
|
|
83
87
|
setTimeout(callback, 2000);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
this.handleTextAreaChange = value => {
|
|
88
|
+
};
|
|
87
89
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
90
|
+
this.handleTextAreaChange = value => {
|
|
91
|
+
this.setState(
|
|
92
|
+
{
|
|
93
|
+
value,
|
|
94
|
+
validated: 'default',
|
|
95
|
+
helperText: 'Validating...'
|
|
96
|
+
},
|
|
93
97
|
this.simulateNetworkCall(() => {
|
|
94
98
|
if (value && value.length > 0) {
|
|
95
99
|
if (value.length >= 10) {
|
|
96
|
-
this.setState({validated: 'success', helperText: 'Thanks for your comments!'});
|
|
100
|
+
this.setState({ validated: 'success', helperText: 'Thanks for your comments!' });
|
|
97
101
|
} else {
|
|
98
|
-
this.setState({
|
|
102
|
+
this.setState({
|
|
103
|
+
validated: 'error',
|
|
104
|
+
invalidText: 'Your being too brief, please enter at least 10 characters.'
|
|
105
|
+
});
|
|
99
106
|
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
this.setState({validated: 'warning', helperText: 'You must have something to say'});
|
|
107
|
+
} else {
|
|
108
|
+
this.setState({ validated: 'warning', helperText: 'You must have something to say' });
|
|
103
109
|
}
|
|
104
110
|
})
|
|
105
111
|
);
|
|
@@ -134,6 +140,7 @@ class InvalidTextArea extends React.Component {
|
|
|
134
140
|
```
|
|
135
141
|
|
|
136
142
|
### Vertically resizable text area
|
|
143
|
+
|
|
137
144
|
```js
|
|
138
145
|
import React from 'react';
|
|
139
146
|
import { TextArea } from '@patternfly/react-core';
|
|
@@ -153,12 +160,20 @@ class VerticalResizeTextArea extends React.Component {
|
|
|
153
160
|
render() {
|
|
154
161
|
const { value } = this.state;
|
|
155
162
|
|
|
156
|
-
return
|
|
163
|
+
return (
|
|
164
|
+
<TextArea
|
|
165
|
+
value={value}
|
|
166
|
+
onChange={this.handleTextAreaChange}
|
|
167
|
+
resizeOrientation="vertical"
|
|
168
|
+
aria-label="text vertical resize example"
|
|
169
|
+
/>
|
|
170
|
+
);
|
|
157
171
|
}
|
|
158
172
|
}
|
|
159
173
|
```
|
|
160
174
|
|
|
161
175
|
### Horizontally resizable text area
|
|
176
|
+
|
|
162
177
|
```js
|
|
163
178
|
import React from 'react';
|
|
164
179
|
import { TextArea } from '@patternfly/react-core';
|
|
@@ -178,33 +193,43 @@ class HorizontalResizeTextArea extends React.Component {
|
|
|
178
193
|
render() {
|
|
179
194
|
const { value } = this.state;
|
|
180
195
|
|
|
181
|
-
return
|
|
196
|
+
return (
|
|
197
|
+
<TextArea
|
|
198
|
+
value={value}
|
|
199
|
+
onChange={this.handleTextAreaChange}
|
|
200
|
+
resizeOrientation="horizontal"
|
|
201
|
+
aria-label="text horizontal resize example"
|
|
202
|
+
/>
|
|
203
|
+
);
|
|
182
204
|
}
|
|
183
205
|
}
|
|
184
206
|
```
|
|
185
207
|
|
|
186
208
|
### Uncontrolled
|
|
209
|
+
|
|
187
210
|
```js
|
|
188
211
|
import React from 'react';
|
|
189
212
|
import { TextArea } from '@patternfly/react-core';
|
|
190
213
|
|
|
191
|
-
<TextArea defaultValue="default value" aria-label="uncontrolled text area example"
|
|
214
|
+
<TextArea defaultValue="default value" aria-label="uncontrolled text area example" />;
|
|
192
215
|
```
|
|
193
216
|
|
|
194
217
|
### Disabled
|
|
218
|
+
|
|
195
219
|
```js
|
|
196
220
|
import React from 'react';
|
|
197
221
|
import { TextArea } from '@patternfly/react-core';
|
|
198
222
|
|
|
199
|
-
<TextArea aria-label="disabled text area example" isDisabled
|
|
223
|
+
<TextArea aria-label="disabled text area example" isDisabled />;
|
|
200
224
|
```
|
|
201
225
|
|
|
202
226
|
### Auto resizing
|
|
227
|
+
|
|
203
228
|
```js
|
|
204
229
|
import React from 'react';
|
|
205
230
|
import { TextArea } from '@patternfly/react-core';
|
|
206
231
|
|
|
207
|
-
<TextArea aria-label="auto resizing text area example" autoResize
|
|
232
|
+
<TextArea aria-label="auto resizing text area example" autoResize />;
|
|
208
233
|
```
|
|
209
234
|
|
|
210
235
|
### Icon sprite variants
|
|
@@ -249,4 +274,5 @@ IconSpriteTextArea = () => {
|
|
|
249
274
|
/>
|
|
250
275
|
</>
|
|
251
276
|
);
|
|
252
|
-
};
|
|
277
|
+
};
|
|
278
|
+
```
|
|
@@ -101,7 +101,7 @@ export const TreeView: React.FunctionComponent<TreeViewProps> = ({
|
|
|
101
101
|
<TreeViewList isNested={isNested} toolbar={toolbar}>
|
|
102
102
|
{data.map(item => (
|
|
103
103
|
<TreeViewListItem
|
|
104
|
-
key={item.id?.toString() || item.name
|
|
104
|
+
key={item.id?.toString() || item.name?.toString()}
|
|
105
105
|
name={item.name}
|
|
106
106
|
title={item.title}
|
|
107
107
|
id={item.id}
|
|
@@ -6,7 +6,7 @@ import { TreeViewDataItem } from './TreeView';
|
|
|
6
6
|
import { Badge } from '../Badge';
|
|
7
7
|
import { GenerateId } from '../../helpers/GenerateId/GenerateId';
|
|
8
8
|
|
|
9
|
-
export interface TreeViewCheckProps extends Partial<React.InputHTMLAttributes<HTMLInputElement
|
|
9
|
+
export interface TreeViewCheckProps extends Omit<Partial<React.InputHTMLAttributes<HTMLInputElement>>, 'checked'> {
|
|
10
10
|
checked?: boolean | null;
|
|
11
11
|
}
|
|
12
12
|
|
|
@@ -26,16 +26,16 @@ export class TreeViewRoot extends React.Component<TreeViewRootProps> {
|
|
|
26
26
|
window.addEventListener('keydown', this.props.hasChecks ? this.handleKeysCheckbox : this.handleKeys);
|
|
27
27
|
}
|
|
28
28
|
if (this.props.hasChecks) {
|
|
29
|
-
const firstToggle = this.treeRef.current
|
|
29
|
+
const firstToggle = this.treeRef.current?.getElementsByClassName('pf-c-tree-view__node-toggle')[0] as HTMLElement;
|
|
30
30
|
if (firstToggle) {
|
|
31
31
|
firstToggle.tabIndex = 0;
|
|
32
32
|
}
|
|
33
|
-
const firstInput = this.treeRef.current
|
|
33
|
+
const firstInput = this.treeRef.current?.getElementsByTagName('INPUT')[0] as HTMLElement;
|
|
34
34
|
if (firstInput) {
|
|
35
35
|
firstInput.tabIndex = 0;
|
|
36
36
|
}
|
|
37
37
|
} else {
|
|
38
|
-
(this.treeRef.current
|
|
38
|
+
(this.treeRef.current?.getElementsByClassName('pf-c-tree-view__node')[0] as HTMLElement).tabIndex = 0;
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
41
|
|
|
@@ -51,7 +51,7 @@ export class TreeViewRoot extends React.Component<TreeViewRootProps> {
|
|
|
51
51
|
}
|
|
52
52
|
const activeElement = document.activeElement;
|
|
53
53
|
const key = event.key;
|
|
54
|
-
const treeItems = Array.from(this.treeRef.current
|
|
54
|
+
const treeItems = Array.from(this.treeRef.current?.getElementsByClassName('pf-c-tree-view__node')).filter(
|
|
55
55
|
el => !el.classList.contains('pf-m-disabled')
|
|
56
56
|
);
|
|
57
57
|
|
|
@@ -72,20 +72,22 @@ export class TreeViewRoot extends React.Component<TreeViewRootProps> {
|
|
|
72
72
|
);
|
|
73
73
|
|
|
74
74
|
if (['ArrowLeft', 'ArrowRight'].includes(key)) {
|
|
75
|
-
const isExpandable = activeElement
|
|
75
|
+
const isExpandable = activeElement?.firstElementChild?.firstElementChild?.classList.contains(
|
|
76
76
|
'pf-c-tree-view__node-toggle'
|
|
77
77
|
);
|
|
78
|
-
const isExpanded = activeElement
|
|
78
|
+
const isExpanded = activeElement?.closest('li')?.classList.contains('pf-m-expanded');
|
|
79
79
|
if (key === 'ArrowLeft') {
|
|
80
80
|
if (isExpandable && isExpanded) {
|
|
81
81
|
(activeElement as HTMLElement).click();
|
|
82
82
|
} else {
|
|
83
|
-
const parentList = activeElement
|
|
84
|
-
if (parentList
|
|
85
|
-
const parentButton = parentList
|
|
83
|
+
const parentList = activeElement?.closest('ul')?.parentElement;
|
|
84
|
+
if (parentList?.tagName !== 'DIV') {
|
|
85
|
+
const parentButton = parentList?.querySelector('button');
|
|
86
86
|
(activeElement as HTMLElement).tabIndex = -1;
|
|
87
|
-
parentButton
|
|
88
|
-
|
|
87
|
+
if (parentButton) {
|
|
88
|
+
parentButton.tabIndex = 0;
|
|
89
|
+
parentButton.focus();
|
|
90
|
+
}
|
|
89
91
|
}
|
|
90
92
|
}
|
|
91
93
|
} else {
|
|
@@ -93,11 +95,13 @@ export class TreeViewRoot extends React.Component<TreeViewRootProps> {
|
|
|
93
95
|
(activeElement as HTMLElement).tabIndex = -1;
|
|
94
96
|
(activeElement as HTMLElement).click();
|
|
95
97
|
const childElement = activeElement
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
childElement
|
|
100
|
-
|
|
98
|
+
?.closest('li')
|
|
99
|
+
?.querySelector('ul > li')
|
|
100
|
+
?.querySelector('button');
|
|
101
|
+
if (childElement) {
|
|
102
|
+
childElement.tabIndex = 0;
|
|
103
|
+
childElement.focus();
|
|
104
|
+
}
|
|
101
105
|
}
|
|
102
106
|
}
|
|
103
107
|
event.preventDefault();
|
|
@@ -116,7 +120,7 @@ export class TreeViewRoot extends React.Component<TreeViewRootProps> {
|
|
|
116
120
|
event.preventDefault();
|
|
117
121
|
}
|
|
118
122
|
|
|
119
|
-
const treeNodes = Array.from(this.treeRef.current
|
|
123
|
+
const treeNodes = Array.from(this.treeRef.current?.getElementsByClassName('pf-c-tree-view__node'));
|
|
120
124
|
|
|
121
125
|
handleArrows(
|
|
122
126
|
event,
|
|
@@ -131,21 +135,21 @@ export class TreeViewRoot extends React.Component<TreeViewRootProps> {
|
|
|
131
135
|
|
|
132
136
|
if (['ArrowLeft', 'ArrowRight'].includes(key)) {
|
|
133
137
|
if (key === 'ArrowLeft') {
|
|
134
|
-
if (activeElement
|
|
135
|
-
activeElement
|
|
138
|
+
if (activeElement?.tagName === 'INPUT') {
|
|
139
|
+
activeElement?.parentElement?.previousSibling &&
|
|
136
140
|
(activeElement.parentElement.previousSibling as HTMLElement).focus();
|
|
137
|
-
} else if (activeElement
|
|
138
|
-
if (activeElement.previousElementSibling
|
|
141
|
+
} else if (activeElement?.previousSibling) {
|
|
142
|
+
if (activeElement.previousElementSibling?.tagName === 'SPAN') {
|
|
139
143
|
(activeElement.previousSibling.firstChild as HTMLElement).focus();
|
|
140
144
|
} else {
|
|
141
145
|
(activeElement.previousSibling as HTMLElement).focus();
|
|
142
146
|
}
|
|
143
147
|
}
|
|
144
148
|
} else {
|
|
145
|
-
if (activeElement
|
|
146
|
-
activeElement.parentElement
|
|
147
|
-
} else if (activeElement
|
|
148
|
-
if (activeElement.nextElementSibling
|
|
149
|
+
if (activeElement?.tagName === 'INPUT') {
|
|
150
|
+
activeElement.parentElement?.nextSibling && (activeElement.parentElement.nextSibling as HTMLElement).focus();
|
|
151
|
+
} else if (activeElement?.nextSibling) {
|
|
152
|
+
if (activeElement.nextElementSibling?.tagName === 'SPAN') {
|
|
149
153
|
(activeElement.nextSibling.firstChild as HTMLElement).focus();
|
|
150
154
|
} else {
|
|
151
155
|
(activeElement.nextSibling as HTMLElement).focus();
|