@patternfly/react-core 4.242.8 → 4.243.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.
- package/CHANGELOG.md +11 -0
- package/dist/esm/components/DatePicker/DatePicker.d.ts.map +1 -1
- package/dist/esm/components/DatePicker/DatePicker.js +4 -2
- package/dist/esm/components/DatePicker/DatePicker.js.map +1 -1
- package/dist/esm/components/TextArea/TextArea.d.ts +17 -11
- package/dist/esm/components/TextArea/TextArea.d.ts.map +1 -1
- package/dist/esm/components/TextArea/TextArea.js +8 -3
- package/dist/esm/components/TextArea/TextArea.js.map +1 -1
- package/dist/esm/components/TextInput/TextInput.d.ts +21 -16
- package/dist/esm/components/TextInput/TextInput.d.ts.map +1 -1
- package/dist/esm/components/TextInput/TextInput.js +7 -4
- package/dist/esm/components/TextInput/TextInput.js.map +1 -1
- package/dist/js/components/DatePicker/DatePicker.d.ts.map +1 -1
- package/dist/js/components/DatePicker/DatePicker.js +4 -2
- package/dist/js/components/DatePicker/DatePicker.js.map +1 -1
- package/dist/js/components/TextArea/TextArea.d.ts +17 -11
- package/dist/js/components/TextArea/TextArea.d.ts.map +1 -1
- package/dist/js/components/TextArea/TextArea.js +9 -4
- package/dist/js/components/TextArea/TextArea.js.map +1 -1
- package/dist/js/components/TextInput/TextInput.d.ts +21 -16
- package/dist/js/components/TextInput/TextInput.d.ts.map +1 -1
- package/dist/js/components/TextInput/TextInput.js +8 -5
- package/dist/js/components/TextInput/TextInput.js.map +1 -1
- package/dist/umd/react-core.min.css +938 -916
- package/dist/umd/react-core.min.js +3 -3
- package/package.json +6 -6
- package/src/components/DatePicker/DatePicker.tsx +4 -2
- package/src/components/DatePicker/__tests__/DatePicker.test.tsx +22 -1
- package/src/components/TextArea/TextArea.tsx +21 -13
- package/src/components/TextArea/__tests__/TextArea.test.tsx +20 -6
- package/src/components/TextArea/__tests__/__snapshots__/TextArea.test.tsx.snap +31 -5
- package/src/components/TextArea/examples/TextArea.md +30 -0
- package/src/components/TextInput/TextInput.tsx +26 -18
- package/src/components/TextInput/__tests__/TextInput.test.tsx +16 -2
- package/src/components/TextInput/__tests__/__snapshots__/TextInput.test.tsx.snap +36 -4
- package/src/components/TextInput/examples/TextInput.md +23 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@patternfly/react-core",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.243.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",
|
|
@@ -44,16 +44,16 @@
|
|
|
44
44
|
"generate": "node scripts/copyStyles.js"
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@patternfly/react-icons": "^4.92.
|
|
48
|
-
"@patternfly/react-styles": "^4.91.
|
|
49
|
-
"@patternfly/react-tokens": "^4.93.
|
|
47
|
+
"@patternfly/react-icons": "^4.92.5",
|
|
48
|
+
"@patternfly/react-styles": "^4.91.5",
|
|
49
|
+
"@patternfly/react-tokens": "^4.93.5",
|
|
50
50
|
"focus-trap": "6.9.2",
|
|
51
51
|
"react-dropzone": "9.0.0",
|
|
52
52
|
"tippy.js": "5.1.2",
|
|
53
53
|
"tslib": "^2.0.0"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
|
-
"@patternfly/patternfly": "4.
|
|
56
|
+
"@patternfly/patternfly": "4.217.0",
|
|
57
57
|
"@rollup/plugin-commonjs": "^21.0.0",
|
|
58
58
|
"@rollup/plugin-node-resolve": "^13.0.0",
|
|
59
59
|
"@rollup/plugin-replace": "^3.0.0",
|
|
@@ -70,5 +70,5 @@
|
|
|
70
70
|
"react": "^16.8 || ^17 || ^18",
|
|
71
71
|
"react-dom": "^16.8 || ^17 || ^18"
|
|
72
72
|
},
|
|
73
|
-
"gitHead": "
|
|
73
|
+
"gitHead": "51b287699eb4b522491b3ade19a8d16b68b5b4da"
|
|
74
74
|
}
|
|
@@ -120,7 +120,9 @@ const DatePickerBase = (
|
|
|
120
120
|
setPristine(!value);
|
|
121
121
|
}, [value]);
|
|
122
122
|
|
|
123
|
-
const setError = (date: Date) =>
|
|
123
|
+
const setError = (date: Date) => {
|
|
124
|
+
setErrorText(validators.map(validator => validator(date)).join('\n') || '');
|
|
125
|
+
};
|
|
124
126
|
|
|
125
127
|
const onTextInput = (value: string) => {
|
|
126
128
|
setValue(value);
|
|
@@ -236,7 +238,7 @@ const DatePickerBase = (
|
|
|
236
238
|
isDisabled={isDisabled}
|
|
237
239
|
aria-label={ariaLabel}
|
|
238
240
|
placeholder={placeholder}
|
|
239
|
-
validated={errorText ? 'error' : 'default'}
|
|
241
|
+
validated={errorText.trim() ? 'error' : 'default'}
|
|
240
242
|
value={value}
|
|
241
243
|
onChange={onTextInput}
|
|
242
244
|
onBlur={onInputBlur}
|
|
@@ -1,8 +1,29 @@
|
|
|
1
|
-
import { render } from '@testing-library/react';
|
|
1
|
+
import { screen, render } from '@testing-library/react';
|
|
2
2
|
import { DatePicker } from '../DatePicker';
|
|
3
3
|
import React from 'react';
|
|
4
|
+
import userEvent from '@testing-library/user-event';
|
|
4
5
|
|
|
5
6
|
test('disabled date picker', () => {
|
|
6
7
|
const { asFragment } = render(<DatePicker value="2020-11-20" isDisabled aria-label="disabled date picker" />);
|
|
7
8
|
expect(asFragment()).toMatchSnapshot();
|
|
8
9
|
});
|
|
10
|
+
|
|
11
|
+
test('Date picker with multiple validators does not show invalid icon on valid input', async () => {
|
|
12
|
+
const user = userEvent.setup();
|
|
13
|
+
|
|
14
|
+
const rangeValidator = (date: Date) => {
|
|
15
|
+
return '';
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const rangeValidatorB = (date: Date) => {
|
|
19
|
+
return '';
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
render(<DatePicker value="2020-03-17" validators={[rangeValidator, rangeValidatorB]} />);
|
|
23
|
+
|
|
24
|
+
await user.click(screen.getByRole('textbox'));
|
|
25
|
+
|
|
26
|
+
await user.click(document.body);
|
|
27
|
+
|
|
28
|
+
expect(screen.getByRole('textbox')).not.toBeInvalid();
|
|
29
|
+
});
|
|
@@ -11,33 +11,40 @@ export enum TextAreResizeOrientation {
|
|
|
11
11
|
both = 'both'
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
+
export enum TextAreaReadOnlyVariant {
|
|
15
|
+
default = 'default',
|
|
16
|
+
plain = 'plain'
|
|
17
|
+
}
|
|
18
|
+
|
|
14
19
|
export interface TextAreaProps extends Omit<HTMLProps<HTMLTextAreaElement>, 'onChange' | 'ref'> {
|
|
15
|
-
/** Additional classes added to the
|
|
20
|
+
/** Additional classes added to the text area. */
|
|
16
21
|
className?: string;
|
|
17
|
-
/** Flag to show if the
|
|
22
|
+
/** Flag to show if the text area is required. */
|
|
18
23
|
isRequired?: boolean;
|
|
19
|
-
/** Flag to show if the
|
|
24
|
+
/** Flag to show if the text area is disabled. */
|
|
20
25
|
isDisabled?: boolean;
|
|
21
|
-
/** Flag to show if the
|
|
26
|
+
/** @deprecated Use readOnlyVariant instead. Flag to show if the text area is read only. */
|
|
22
27
|
isReadOnly?: boolean;
|
|
28
|
+
/** Read only variant. */
|
|
29
|
+
readOnlyVariant?: 'default' | 'plain';
|
|
23
30
|
/** Use the external file instead of a data URI */
|
|
24
31
|
isIconSprite?: boolean;
|
|
25
32
|
/** Flag to modify height based on contents. */
|
|
26
33
|
autoResize?: boolean;
|
|
27
|
-
/** Value to indicate if the
|
|
28
|
-
* If set to success,
|
|
29
|
-
* If set to error,
|
|
34
|
+
/** Value to indicate if the text area is modified to show that validation state.
|
|
35
|
+
* If set to success, text area will be modified to indicate valid state.
|
|
36
|
+
* If set to error, text area will be modified to indicate error state.
|
|
30
37
|
*/
|
|
31
38
|
validated?: 'success' | 'warning' | 'error' | 'default';
|
|
32
|
-
/** Value of the
|
|
39
|
+
/** Value of the text area. */
|
|
33
40
|
value?: string | number;
|
|
34
|
-
/** A callback for when the
|
|
41
|
+
/** A callback for when the text area value changes. */
|
|
35
42
|
onChange?: (value: string, event: React.ChangeEvent<HTMLTextAreaElement>) => void;
|
|
36
43
|
/** Sets the orientation to limit the resize to */
|
|
37
44
|
resizeOrientation?: 'horizontal' | 'vertical' | 'both';
|
|
38
|
-
/** Custom flag to show that the
|
|
45
|
+
/** Custom flag to show that the text area requires an associated id or aria-label. */
|
|
39
46
|
'aria-label'?: string;
|
|
40
|
-
/** A reference object to attach to the
|
|
47
|
+
/** A reference object to attach to the text area. */
|
|
41
48
|
innerRef?: React.RefObject<any>;
|
|
42
49
|
}
|
|
43
50
|
|
|
@@ -105,9 +112,9 @@ export class TextAreaBase extends React.Component<TextAreaProps> {
|
|
|
105
112
|
isDisabled,
|
|
106
113
|
isIconSprite,
|
|
107
114
|
isReadOnly,
|
|
115
|
+
readOnlyVariant,
|
|
108
116
|
resizeOrientation,
|
|
109
117
|
innerRef,
|
|
110
|
-
readOnly,
|
|
111
118
|
disabled,
|
|
112
119
|
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
113
120
|
autoResize,
|
|
@@ -121,6 +128,7 @@ export class TextAreaBase extends React.Component<TextAreaProps> {
|
|
|
121
128
|
className={css(
|
|
122
129
|
styles.formControl,
|
|
123
130
|
isIconSprite && styles.modifiers.iconSprite,
|
|
131
|
+
readOnlyVariant === 'plain' && styles.modifiers.plain,
|
|
124
132
|
className,
|
|
125
133
|
resizeOrientation !== TextAreResizeOrientation.both && styles.modifiers[orientation],
|
|
126
134
|
validated === ValidatedOptions.success && styles.modifiers.success,
|
|
@@ -131,7 +139,7 @@ export class TextAreaBase extends React.Component<TextAreaProps> {
|
|
|
131
139
|
aria-invalid={validated === ValidatedOptions.error}
|
|
132
140
|
required={isRequired}
|
|
133
141
|
disabled={isDisabled || disabled}
|
|
134
|
-
readOnly={
|
|
142
|
+
readOnly={!!readOnlyVariant || isReadOnly}
|
|
135
143
|
ref={innerRef || this.inputRef}
|
|
136
144
|
{...props}
|
|
137
145
|
/>
|
|
@@ -12,7 +12,7 @@ const props = {
|
|
|
12
12
|
};
|
|
13
13
|
|
|
14
14
|
describe('TextArea', () => {
|
|
15
|
-
test('textarea
|
|
15
|
+
test('textarea passes value and event to onChange handler', async () => {
|
|
16
16
|
const user = userEvent.setup();
|
|
17
17
|
|
|
18
18
|
render(<TextAreaBase {...props} value="" aria-label="test textarea" />);
|
|
@@ -21,27 +21,41 @@ describe('TextArea', () => {
|
|
|
21
21
|
expect(props.onChange).toHaveBeenCalledWith('a', expect.any(Object));
|
|
22
22
|
});
|
|
23
23
|
|
|
24
|
-
test('simple text
|
|
24
|
+
test('simple text area', () => {
|
|
25
25
|
const { asFragment } = render(<TextArea {...props} aria-label="simple textarea" />);
|
|
26
26
|
expect(asFragment()).toMatchSnapshot();
|
|
27
27
|
});
|
|
28
28
|
|
|
29
|
-
test('disabled text
|
|
29
|
+
test('disabled text area using isDisabled', () => {
|
|
30
30
|
const { asFragment } = render(<TextArea {...props} aria-label="is disabled textarea" isDisabled />);
|
|
31
31
|
expect(asFragment()).toMatchSnapshot();
|
|
32
32
|
});
|
|
33
33
|
|
|
34
|
-
test('disabled text
|
|
34
|
+
test('disabled text area using disabled', () => {
|
|
35
35
|
const { asFragment } = render(<TextArea {...props} aria-label="disabled textarea" disabled />);
|
|
36
36
|
expect(asFragment()).toMatchSnapshot();
|
|
37
37
|
});
|
|
38
38
|
|
|
39
|
-
test('read only text
|
|
39
|
+
test('read only text area using isReadOnly', () => {
|
|
40
40
|
const { asFragment } = render(<TextArea {...props} aria-label="is read only textarea" isReadOnly />);
|
|
41
41
|
expect(asFragment()).toMatchSnapshot();
|
|
42
42
|
});
|
|
43
43
|
|
|
44
|
-
test('read only text
|
|
44
|
+
test('read only text area using default readOnlyVariant', () => {
|
|
45
|
+
const { asFragment } = render(
|
|
46
|
+
<TextArea {...props} aria-label="is default read only textarea" readOnlyVariant="default" />
|
|
47
|
+
);
|
|
48
|
+
expect(asFragment()).toMatchSnapshot();
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
test('read only text area using plain readOnlyVariant', () => {
|
|
52
|
+
const { asFragment } = render(
|
|
53
|
+
<TextArea {...props} aria-label="is plain read only textarea" readOnlyVariant="plain" />
|
|
54
|
+
);
|
|
55
|
+
expect(asFragment()).toMatchSnapshot();
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
test('read only text area using readOnly', () => {
|
|
45
59
|
const { asFragment } = render(<TextArea {...props} aria-label="read only textarea" readOnly />);
|
|
46
60
|
expect(asFragment()).toMatchSnapshot();
|
|
47
61
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
2
|
|
|
3
|
-
exports[`TextArea disabled text
|
|
3
|
+
exports[`TextArea disabled text area using disabled 1`] = `
|
|
4
4
|
<DocumentFragment>
|
|
5
5
|
<textarea
|
|
6
6
|
aria-invalid="false"
|
|
@@ -13,7 +13,7 @@ exports[`TextArea disabled text input using disabled 1`] = `
|
|
|
13
13
|
</DocumentFragment>
|
|
14
14
|
`;
|
|
15
15
|
|
|
16
|
-
exports[`TextArea disabled text
|
|
16
|
+
exports[`TextArea disabled text area using isDisabled 1`] = `
|
|
17
17
|
<DocumentFragment>
|
|
18
18
|
<textarea
|
|
19
19
|
aria-invalid="false"
|
|
@@ -39,7 +39,20 @@ exports[`TextArea horizontally resizable text area 1`] = `
|
|
|
39
39
|
</DocumentFragment>
|
|
40
40
|
`;
|
|
41
41
|
|
|
42
|
-
exports[`TextArea read only text
|
|
42
|
+
exports[`TextArea read only text area using default readOnlyVariant 1`] = `
|
|
43
|
+
<DocumentFragment>
|
|
44
|
+
<textarea
|
|
45
|
+
aria-invalid="false"
|
|
46
|
+
aria-label="is default read only textarea"
|
|
47
|
+
class="pf-c-form-control"
|
|
48
|
+
readonly=""
|
|
49
|
+
>
|
|
50
|
+
test textarea
|
|
51
|
+
</textarea>
|
|
52
|
+
</DocumentFragment>
|
|
53
|
+
`;
|
|
54
|
+
|
|
55
|
+
exports[`TextArea read only text area using isReadOnly 1`] = `
|
|
43
56
|
<DocumentFragment>
|
|
44
57
|
<textarea
|
|
45
58
|
aria-invalid="false"
|
|
@@ -52,7 +65,20 @@ exports[`TextArea read only text input using isReadOnly 1`] = `
|
|
|
52
65
|
</DocumentFragment>
|
|
53
66
|
`;
|
|
54
67
|
|
|
55
|
-
exports[`TextArea read only text
|
|
68
|
+
exports[`TextArea read only text area using plain readOnlyVariant 1`] = `
|
|
69
|
+
<DocumentFragment>
|
|
70
|
+
<textarea
|
|
71
|
+
aria-invalid="false"
|
|
72
|
+
aria-label="is plain read only textarea"
|
|
73
|
+
class="pf-c-form-control pf-m-plain"
|
|
74
|
+
readonly=""
|
|
75
|
+
>
|
|
76
|
+
test textarea
|
|
77
|
+
</textarea>
|
|
78
|
+
</DocumentFragment>
|
|
79
|
+
`;
|
|
80
|
+
|
|
81
|
+
exports[`TextArea read only text area using readOnly 1`] = `
|
|
56
82
|
<DocumentFragment>
|
|
57
83
|
<textarea
|
|
58
84
|
aria-invalid="false"
|
|
@@ -65,7 +91,7 @@ exports[`TextArea read only text input using readOnly 1`] = `
|
|
|
65
91
|
</DocumentFragment>
|
|
66
92
|
`;
|
|
67
93
|
|
|
68
|
-
exports[`TextArea simple text
|
|
94
|
+
exports[`TextArea simple text area 1`] = `
|
|
69
95
|
<DocumentFragment>
|
|
70
96
|
<textarea
|
|
71
97
|
aria-invalid="false"
|
|
@@ -223,6 +223,36 @@ import { TextArea } from '@patternfly/react-core';
|
|
|
223
223
|
<TextArea aria-label="disabled text area example" isDisabled />;
|
|
224
224
|
```
|
|
225
225
|
|
|
226
|
+
### Read only
|
|
227
|
+
|
|
228
|
+
```js
|
|
229
|
+
import React from 'react';
|
|
230
|
+
import { Checkbox, TextArea } from '@patternfly/react-core';
|
|
231
|
+
|
|
232
|
+
const ReadOnlyTextArea = () => {
|
|
233
|
+
const [isPlainChecked, setIsPlainChecked] = React.useState(false);
|
|
234
|
+
|
|
235
|
+
return (
|
|
236
|
+
<React.Fragment>
|
|
237
|
+
<div style={{ marginBottom: '12px' }}>
|
|
238
|
+
<Checkbox
|
|
239
|
+
id="isPlain"
|
|
240
|
+
key="isPlain"
|
|
241
|
+
label="Plain read only variant"
|
|
242
|
+
isChecked={isPlainChecked}
|
|
243
|
+
onChange={checked => setIsPlainChecked(checked)}
|
|
244
|
+
/>
|
|
245
|
+
</div>
|
|
246
|
+
<TextArea
|
|
247
|
+
aria-label="read only text area example"
|
|
248
|
+
value="read only text area example"
|
|
249
|
+
readOnlyVariant={isPlainChecked ? 'plain' : 'default'}
|
|
250
|
+
/>
|
|
251
|
+
</React.Fragment>
|
|
252
|
+
);
|
|
253
|
+
};
|
|
254
|
+
```
|
|
255
|
+
|
|
226
256
|
### Auto resizing
|
|
227
257
|
|
|
228
258
|
```js
|
|
@@ -20,25 +20,31 @@ export enum TextInputTypes {
|
|
|
20
20
|
url = 'url'
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
+
export enum TextInputReadOnlyVariant {
|
|
24
|
+
default = 'default',
|
|
25
|
+
plain = 'plain'
|
|
26
|
+
}
|
|
27
|
+
|
|
23
28
|
export interface TextInputProps
|
|
24
29
|
extends Omit<React.HTMLProps<HTMLInputElement>, 'onChange' | 'onFocus' | 'onBlur' | 'disabled' | 'ref'>,
|
|
25
30
|
OUIAProps {
|
|
26
|
-
/** Additional classes added to the
|
|
31
|
+
/** Additional classes added to the text input. */
|
|
27
32
|
className?: string;
|
|
28
|
-
/** Flag to show if the input is disabled. */
|
|
33
|
+
/** Flag to show if the text input is disabled. */
|
|
29
34
|
isDisabled?: boolean;
|
|
30
|
-
/** Flag to show if the input is read only. */
|
|
35
|
+
/** @deprecated Use readOnlyVariant instead. Flag to show if the text input is read only. */
|
|
31
36
|
isReadOnly?: boolean;
|
|
32
|
-
/**
|
|
37
|
+
/** Read only variant. */
|
|
38
|
+
readOnlyVariant?: 'plain' | 'default';
|
|
33
39
|
isRequired?: boolean;
|
|
34
|
-
/** Value to indicate if the input is modified to show that validation state.
|
|
35
|
-
* If set to success, input will be modified to indicate valid state.
|
|
36
|
-
* If set to error,
|
|
40
|
+
/** Value to indicate if the text input is modified to show that validation state.
|
|
41
|
+
* If set to success, text input will be modified to indicate valid state.
|
|
42
|
+
* If set to error, text input will be modified to indicate error state.
|
|
37
43
|
*/
|
|
38
44
|
validated?: 'success' | 'warning' | 'error' | 'default';
|
|
39
|
-
/** A callback for when the input value changes. */
|
|
45
|
+
/** A callback for when the text input value changes. */
|
|
40
46
|
onChange?: (value: string, event: React.FormEvent<HTMLInputElement>) => void;
|
|
41
|
-
/** Type that the input accepts. */
|
|
47
|
+
/** Type that the text input accepts. */
|
|
42
48
|
type?:
|
|
43
49
|
| 'text'
|
|
44
50
|
| 'date'
|
|
@@ -51,25 +57,25 @@ export interface TextInputProps
|
|
|
51
57
|
| 'tel'
|
|
52
58
|
| 'time'
|
|
53
59
|
| 'url';
|
|
54
|
-
/** Value of the input. */
|
|
60
|
+
/** Value of the text input. */
|
|
55
61
|
value?: string | number;
|
|
56
|
-
/** Aria-label. The input requires an associated id or aria-label. */
|
|
62
|
+
/** Aria-label. The text input requires an associated id or aria-label. */
|
|
57
63
|
'aria-label'?: string;
|
|
58
|
-
/** A reference object to attach to the input box. */
|
|
64
|
+
/** A reference object to attach to the text input box. */
|
|
59
65
|
innerRef?: React.RefObject<any>;
|
|
60
66
|
/** Trim text on left */
|
|
61
67
|
isLeftTruncated?: boolean;
|
|
62
|
-
/** Callback function when input is focused */
|
|
68
|
+
/** Callback function when text input is focused */
|
|
63
69
|
onFocus?: (event?: any) => void;
|
|
64
|
-
/** Callback function when input is blurred (focus leaves) */
|
|
70
|
+
/** Callback function when text input is blurred (focus leaves) */
|
|
65
71
|
onBlur?: (event?: any) => void;
|
|
66
72
|
/** icon variant */
|
|
67
73
|
iconVariant?: 'calendar' | 'clock' | 'search';
|
|
68
74
|
/** Use the external file instead of a data URI */
|
|
69
75
|
isIconSprite?: boolean;
|
|
70
|
-
/** Custom icon url to set as the input's background-image */
|
|
76
|
+
/** Custom icon url to set as the text input's background-image */
|
|
71
77
|
customIconUrl?: string;
|
|
72
|
-
/** Dimensions for the custom icon set as the input's background-size */
|
|
78
|
+
/** Dimensions for the custom icon set as the text input's background-size */
|
|
73
79
|
customIconDimensions?: string;
|
|
74
80
|
}
|
|
75
81
|
|
|
@@ -169,8 +175,9 @@ export class TextInputBase extends React.Component<TextInputProps, TextInputStat
|
|
|
169
175
|
onFocus,
|
|
170
176
|
onBlur,
|
|
171
177
|
isLeftTruncated,
|
|
172
|
-
/* eslint-enable @typescript-eslint/no-unused-vars */
|
|
173
178
|
isReadOnly,
|
|
179
|
+
readOnly,
|
|
180
|
+
readOnlyVariant,
|
|
174
181
|
isRequired,
|
|
175
182
|
isDisabled,
|
|
176
183
|
isIconSprite,
|
|
@@ -198,6 +205,7 @@ export class TextInputBase extends React.Component<TextInputProps, TextInputStat
|
|
|
198
205
|
className={css(
|
|
199
206
|
styles.formControl,
|
|
200
207
|
isIconSprite && styles.modifiers.iconSprite,
|
|
208
|
+
readOnlyVariant === 'plain' && styles.modifiers.plain,
|
|
201
209
|
validated === ValidatedOptions.success && styles.modifiers.success,
|
|
202
210
|
validated === ValidatedOptions.warning && styles.modifiers.warning,
|
|
203
211
|
((iconVariant && iconVariant !== 'search') || customIconUrl) && styles.modifiers.icon,
|
|
@@ -210,7 +218,7 @@ export class TextInputBase extends React.Component<TextInputProps, TextInputStat
|
|
|
210
218
|
aria-invalid={props['aria-invalid'] ? props['aria-invalid'] : validated === ValidatedOptions.error}
|
|
211
219
|
required={isRequired}
|
|
212
220
|
disabled={isDisabled}
|
|
213
|
-
readOnly={isReadOnly}
|
|
221
|
+
readOnly={!!readOnlyVariant || isReadOnly || readOnly}
|
|
214
222
|
ref={innerRef || this.inputRef}
|
|
215
223
|
{...((customIconUrl || customIconDimensions) && { style: customIconStyle })}
|
|
216
224
|
{...getOUIAProps(TextInput.displayName, ouiaId !== undefined ? ouiaId : this.state.ouiaStateId, ouiaSafe)}
|
|
@@ -31,8 +31,22 @@ describe('TextInput', () => {
|
|
|
31
31
|
expect(asFragment()).toMatchSnapshot();
|
|
32
32
|
});
|
|
33
33
|
|
|
34
|
-
test('
|
|
35
|
-
const { asFragment } = render(<TextInput isReadOnly value="read only" aria-label="
|
|
34
|
+
test('read only text input using isReadOnly', () => {
|
|
35
|
+
const { asFragment } = render(<TextInput isReadOnly value="read only" aria-label="read only text input" />);
|
|
36
|
+
expect(asFragment()).toMatchSnapshot();
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test('default read only text input', () => {
|
|
40
|
+
const { asFragment } = render(
|
|
41
|
+
<TextInput readOnlyVariant="default" value="read only default" aria-label="default read only text input" />
|
|
42
|
+
);
|
|
43
|
+
expect(asFragment()).toMatchSnapshot();
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
test('plain read only text input', () => {
|
|
47
|
+
const { asFragment } = render(
|
|
48
|
+
<TextInput readOnlyVariant="plain" value="read only plain" aria-label="plain read only text input" />
|
|
49
|
+
);
|
|
36
50
|
expect(asFragment()).toMatchSnapshot();
|
|
37
51
|
});
|
|
38
52
|
|
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
2
|
|
|
3
|
+
exports[`TextInput default read only text input 1`] = `
|
|
4
|
+
<DocumentFragment>
|
|
5
|
+
<input
|
|
6
|
+
aria-invalid="false"
|
|
7
|
+
aria-label="default read only text input"
|
|
8
|
+
class="pf-c-form-control"
|
|
9
|
+
data-ouia-component-id="OUIA-Generated-TextInputBase-5"
|
|
10
|
+
data-ouia-component-type="PF4/TextInput"
|
|
11
|
+
data-ouia-safe="true"
|
|
12
|
+
readonly=""
|
|
13
|
+
type="text"
|
|
14
|
+
value="read only default"
|
|
15
|
+
/>
|
|
16
|
+
</DocumentFragment>
|
|
17
|
+
`;
|
|
18
|
+
|
|
3
19
|
exports[`TextInput disabled text input 1`] = `
|
|
4
20
|
<DocumentFragment>
|
|
5
21
|
<input
|
|
@@ -22,7 +38,7 @@ exports[`TextInput invalid text input 1`] = `
|
|
|
22
38
|
aria-invalid="true"
|
|
23
39
|
aria-label="invalid text input"
|
|
24
40
|
class="pf-c-form-control"
|
|
25
|
-
data-ouia-component-id="OUIA-Generated-TextInputBase-
|
|
41
|
+
data-ouia-component-id="OUIA-Generated-TextInputBase-7"
|
|
26
42
|
data-ouia-component-type="PF4/TextInput"
|
|
27
43
|
data-ouia-safe="true"
|
|
28
44
|
type="text"
|
|
@@ -31,11 +47,27 @@ exports[`TextInput invalid text input 1`] = `
|
|
|
31
47
|
</DocumentFragment>
|
|
32
48
|
`;
|
|
33
49
|
|
|
34
|
-
exports[`TextInput
|
|
50
|
+
exports[`TextInput plain read only text input 1`] = `
|
|
51
|
+
<DocumentFragment>
|
|
52
|
+
<input
|
|
53
|
+
aria-invalid="false"
|
|
54
|
+
aria-label="plain read only text input"
|
|
55
|
+
class="pf-c-form-control pf-m-plain"
|
|
56
|
+
data-ouia-component-id="OUIA-Generated-TextInputBase-6"
|
|
57
|
+
data-ouia-component-type="PF4/TextInput"
|
|
58
|
+
data-ouia-safe="true"
|
|
59
|
+
readonly=""
|
|
60
|
+
type="text"
|
|
61
|
+
value="read only plain"
|
|
62
|
+
/>
|
|
63
|
+
</DocumentFragment>
|
|
64
|
+
`;
|
|
65
|
+
|
|
66
|
+
exports[`TextInput read only text input using isReadOnly 1`] = `
|
|
35
67
|
<DocumentFragment>
|
|
36
68
|
<input
|
|
37
69
|
aria-invalid="false"
|
|
38
|
-
aria-label="
|
|
70
|
+
aria-label="read only text input"
|
|
39
71
|
class="pf-c-form-control"
|
|
40
72
|
data-ouia-component-id="OUIA-Generated-TextInputBase-4"
|
|
41
73
|
data-ouia-component-type="PF4/TextInput"
|
|
@@ -68,7 +100,7 @@ exports[`TextInput validated text input error 1`] = `
|
|
|
68
100
|
aria-invalid="true"
|
|
69
101
|
aria-label="validated text input"
|
|
70
102
|
class="pf-c-form-control"
|
|
71
|
-
data-ouia-component-id="OUIA-Generated-TextInputBase-
|
|
103
|
+
data-ouia-component-id="OUIA-Generated-TextInputBase-10"
|
|
72
104
|
data-ouia-component-type="PF4/TextInput"
|
|
73
105
|
data-ouia-safe="true"
|
|
74
106
|
type="text"
|
|
@@ -80,9 +80,30 @@ constructor(props) {
|
|
|
80
80
|
|
|
81
81
|
```js
|
|
82
82
|
import React from 'react';
|
|
83
|
-
import { TextInput } from '@patternfly/react-core';
|
|
83
|
+
import { Checkbox, TextInput } from '@patternfly/react-core';
|
|
84
|
+
|
|
85
|
+
const ReadOnlyTextArea = () => {
|
|
86
|
+
const [isPlainChecked, setIsPlainChecked] = React.useState(false);
|
|
84
87
|
|
|
85
|
-
|
|
88
|
+
return (
|
|
89
|
+
<React.Fragment>
|
|
90
|
+
<div style={{ marginBottom: '12px' }}>
|
|
91
|
+
<Checkbox
|
|
92
|
+
id="isPlain"
|
|
93
|
+
key="isPlain"
|
|
94
|
+
label="Plain read only variant"
|
|
95
|
+
isChecked={isPlainChecked}
|
|
96
|
+
onChange={checked => setIsPlainChecked(checked)}
|
|
97
|
+
/>
|
|
98
|
+
</div>
|
|
99
|
+
<TextInput
|
|
100
|
+
aria-label="read only text input example"
|
|
101
|
+
value="read only text input example"
|
|
102
|
+
readOnlyVariant={isPlainChecked ? 'plain' : 'default'}
|
|
103
|
+
/>
|
|
104
|
+
</React.Fragment>
|
|
105
|
+
);
|
|
106
|
+
};
|
|
86
107
|
```
|
|
87
108
|
|
|
88
109
|
### Invalid
|