@patternfly/react-core 6.2.0-prerelease.10 → 6.2.0-prerelease.12
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 +13 -0
- package/components/package.json +1 -1
- package/deprecated/package.json +1 -1
- package/dist/dynamic/components/AboutModal/package.json +1 -1
- package/dist/dynamic/components/Accordion/package.json +1 -1
- package/dist/dynamic/components/ActionList/package.json +1 -1
- package/dist/dynamic/components/Alert/package.json +1 -1
- package/dist/dynamic/components/Avatar/package.json +1 -1
- package/dist/dynamic/components/BackToTop/package.json +1 -1
- package/dist/dynamic/components/Backdrop/package.json +1 -1
- package/dist/dynamic/components/BackgroundImage/package.json +1 -1
- package/dist/dynamic/components/Badge/package.json +1 -1
- package/dist/dynamic/components/Banner/package.json +1 -1
- package/dist/dynamic/components/Brand/package.json +1 -1
- package/dist/dynamic/components/Breadcrumb/package.json +1 -1
- package/dist/dynamic/components/Button/package.json +1 -1
- package/dist/dynamic/components/CalendarMonth/package.json +1 -1
- package/dist/dynamic/components/Card/package.json +1 -1
- package/dist/dynamic/components/Checkbox/package.json +1 -1
- package/dist/dynamic/components/ClipboardCopy/package.json +1 -1
- package/dist/dynamic/components/CodeBlock/package.json +1 -1
- package/dist/dynamic/components/Content/package.json +1 -1
- package/dist/dynamic/components/DataList/package.json +1 -1
- package/dist/dynamic/components/DatePicker/package.json +1 -1
- package/dist/dynamic/components/DescriptionList/package.json +1 -1
- package/dist/dynamic/components/Divider/package.json +1 -1
- package/dist/dynamic/components/Drawer/package.json +1 -1
- package/dist/dynamic/components/Dropdown/package.json +1 -1
- package/dist/dynamic/components/DualListSelector/package.json +1 -1
- package/dist/dynamic/components/EmptyState/package.json +1 -1
- package/dist/dynamic/components/ExpandableSection/package.json +1 -1
- package/dist/dynamic/components/FileUpload/package.json +1 -1
- package/dist/dynamic/components/Form/package.json +1 -1
- package/dist/dynamic/components/FormSelect/package.json +1 -1
- package/dist/dynamic/components/HelperText/package.json +1 -1
- package/dist/dynamic/components/Hint/package.json +1 -1
- package/dist/dynamic/components/Icon/package.json +1 -1
- package/dist/dynamic/components/InputGroup/package.json +1 -1
- package/dist/dynamic/components/JumpLinks/package.json +1 -1
- package/dist/dynamic/components/Label/package.json +1 -1
- package/dist/dynamic/components/List/package.json +1 -1
- package/dist/dynamic/components/LoginPage/package.json +1 -1
- package/dist/dynamic/components/Masthead/package.json +1 -1
- package/dist/dynamic/components/Menu/package.json +1 -1
- package/dist/dynamic/components/MenuToggle/package.json +1 -1
- package/dist/dynamic/components/Modal/package.json +1 -1
- package/dist/dynamic/components/MultipleFileUpload/package.json +1 -1
- package/dist/dynamic/components/Nav/package.json +1 -1
- package/dist/dynamic/components/NotificationBadge/package.json +1 -1
- package/dist/dynamic/components/NotificationDrawer/package.json +1 -1
- package/dist/dynamic/components/NumberInput/package.json +1 -1
- package/dist/dynamic/components/OverflowMenu/package.json +1 -1
- package/dist/dynamic/components/Page/package.json +1 -1
- package/dist/dynamic/components/Pagination/package.json +1 -1
- package/dist/dynamic/components/Panel/package.json +1 -1
- package/dist/dynamic/components/Popover/package.json +1 -1
- package/dist/dynamic/components/Progress/package.json +1 -1
- package/dist/dynamic/components/ProgressStepper/package.json +1 -1
- package/dist/dynamic/components/Radio/package.json +1 -1
- package/dist/dynamic/components/SearchInput/package.json +1 -1
- package/dist/dynamic/components/Select/package.json +1 -1
- package/dist/dynamic/components/Sidebar/package.json +1 -1
- package/dist/dynamic/components/SimpleList/package.json +1 -1
- package/dist/dynamic/components/Skeleton/package.json +1 -1
- package/dist/dynamic/components/SkipToContent/package.json +1 -1
- package/dist/dynamic/components/Slider/package.json +1 -1
- package/dist/dynamic/components/Spinner/package.json +1 -1
- package/dist/dynamic/components/Switch/package.json +1 -1
- package/dist/dynamic/components/Tabs/package.json +1 -1
- package/dist/dynamic/components/TextArea/package.json +1 -1
- package/dist/dynamic/components/TextInput/package.json +1 -1
- package/dist/dynamic/components/TextInputGroup/package.json +1 -1
- package/dist/dynamic/components/TimePicker/package.json +1 -1
- package/dist/dynamic/components/Timestamp/package.json +1 -1
- package/dist/dynamic/components/Title/package.json +1 -1
- package/dist/dynamic/components/ToggleGroup/package.json +1 -1
- package/dist/dynamic/components/Toolbar/package.json +1 -1
- package/dist/dynamic/components/Tooltip/package.json +1 -1
- package/dist/dynamic/components/TreeView/package.json +1 -1
- package/dist/dynamic/components/Truncate/package.json +1 -1
- package/dist/dynamic/components/Wizard/hooks/package.json +1 -1
- package/dist/dynamic/components/Wizard/package.json +1 -1
- package/dist/dynamic/deprecated/components/Chip/package.json +1 -1
- package/dist/dynamic/deprecated/components/DragDrop/package.json +1 -1
- package/dist/dynamic/deprecated/components/DualListSelector/package.json +1 -1
- package/dist/dynamic/deprecated/components/Modal/package.json +1 -1
- package/dist/dynamic/deprecated/components/Tile/package.json +1 -1
- package/dist/dynamic/deprecated/components/Wizard/package.json +1 -1
- package/dist/dynamic/deprecated/components/package.json +1 -1
- package/dist/dynamic/helpers/FocusTrap/FocusTrap/package.json +1 -1
- package/dist/dynamic/helpers/GenerateId/GenerateId/package.json +1 -1
- package/dist/dynamic/helpers/KeyboardHandler/package.json +1 -1
- package/dist/dynamic/helpers/OUIA/ouia/package.json +1 -1
- package/dist/dynamic/helpers/Popper/Popper/package.json +1 -1
- package/dist/dynamic/helpers/constants/package.json +1 -1
- package/dist/dynamic/helpers/datetimeUtils/package.json +1 -1
- package/dist/dynamic/helpers/fileUtils/package.json +1 -1
- package/dist/dynamic/helpers/htmlConstants/package.json +1 -1
- package/dist/dynamic/helpers/package.json +1 -1
- package/dist/dynamic/helpers/resizeObserver/package.json +1 -1
- package/dist/dynamic/helpers/typeUtils/package.json +1 -1
- package/dist/dynamic/helpers/useInterval/package.json +1 -1
- package/dist/dynamic/helpers/useIsomorphicLayout/package.json +1 -1
- package/dist/dynamic/helpers/useUnmountEffect/package.json +1 -1
- package/dist/dynamic/helpers/util/package.json +1 -1
- package/dist/dynamic/layouts/Bullseye/package.json +1 -1
- package/dist/dynamic/layouts/Flex/package.json +1 -1
- package/dist/dynamic/layouts/Gallery/package.json +1 -1
- package/dist/dynamic/layouts/Grid/package.json +1 -1
- package/dist/dynamic/layouts/Level/package.json +1 -1
- package/dist/dynamic/layouts/Split/package.json +1 -1
- package/dist/dynamic/layouts/Stack/package.json +1 -1
- package/dist/dynamic/styles/package.json +1 -1
- package/dist/esm/components/FileUpload/FileUploadField.d.ts +2 -0
- package/dist/esm/components/FileUpload/FileUploadField.d.ts.map +1 -1
- package/dist/esm/components/FileUpload/FileUploadField.js +2 -2
- package/dist/esm/components/FileUpload/FileUploadField.js.map +1 -1
- package/dist/esm/components/JumpLinks/JumpLinks.d.ts +2 -0
- package/dist/esm/components/JumpLinks/JumpLinks.d.ts.map +1 -1
- package/dist/esm/components/JumpLinks/JumpLinks.js +11 -7
- package/dist/esm/components/JumpLinks/JumpLinks.js.map +1 -1
- package/dist/esm/components/Truncate/Truncate.d.ts.map +1 -1
- package/dist/esm/components/Truncate/Truncate.js +5 -7
- package/dist/esm/components/Truncate/Truncate.js.map +1 -1
- package/dist/js/components/FileUpload/FileUploadField.d.ts +2 -0
- package/dist/js/components/FileUpload/FileUploadField.d.ts.map +1 -1
- package/dist/js/components/FileUpload/FileUploadField.js +2 -2
- package/dist/js/components/FileUpload/FileUploadField.js.map +1 -1
- package/dist/js/components/JumpLinks/JumpLinks.d.ts +2 -0
- package/dist/js/components/JumpLinks/JumpLinks.d.ts.map +1 -1
- package/dist/js/components/JumpLinks/JumpLinks.js +12 -8
- package/dist/js/components/JumpLinks/JumpLinks.js.map +1 -1
- package/dist/js/components/Truncate/Truncate.d.ts.map +1 -1
- package/dist/js/components/Truncate/Truncate.js +5 -7
- package/dist/js/components/Truncate/Truncate.js.map +1 -1
- package/dist/umd/assets/{output-BTedH57W.css → output-u1iwt0Hj.css} +18825 -18825
- package/dist/umd/react-core.min.js +1 -1
- package/helpers/package.json +1 -1
- package/layouts/package.json +1 -1
- package/next/package.json +1 -1
- package/package.json +2 -2
- package/src/components/FileUpload/FileUploadField.tsx +4 -1
- package/src/components/FileUpload/__tests__/FileUploadField.test.tsx +15 -1
- package/src/components/FileUpload/examples/FileUploadCustomUpload.tsx +8 -0
- package/src/components/JumpLinks/JumpLinks.tsx +12 -6
- package/src/components/Truncate/Truncate.tsx +17 -14
- package/src/components/Truncate/__tests__/Truncate.test.tsx +17 -1
package/helpers/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@patternfly/react-core-helpers","main":"../dist/js/helpers/index.js","module":"../dist/esm/helpers/index.js","typings":"../dist/esm/helpers/index.d.ts","version":"6.2.0-prerelease.
|
|
1
|
+
{"name":"@patternfly/react-core-helpers","main":"../dist/js/helpers/index.js","module":"../dist/esm/helpers/index.js","typings":"../dist/esm/helpers/index.d.ts","version":"6.2.0-prerelease.11","private":true}
|
package/layouts/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@patternfly/react-core-layouts","main":"../dist/js/layouts/index.js","module":"../dist/esm/layouts/index.js","typings":"../dist/esm/layouts/index.d.ts","version":"6.2.0-prerelease.
|
|
1
|
+
{"name":"@patternfly/react-core-layouts","main":"../dist/js/layouts/index.js","module":"../dist/esm/layouts/index.js","typings":"../dist/esm/layouts/index.d.ts","version":"6.2.0-prerelease.11","private":true}
|
package/next/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@patternfly/react-core-next","main":"../dist/js/next/index.js","module":"../dist/esm/next/index.js","typings":"../dist/esm/next/index.d.ts","version":"6.2.0-prerelease.
|
|
1
|
+
{"name":"@patternfly/react-core-next","main":"../dist/js/next/index.js","module":"../dist/esm/next/index.js","typings":"../dist/esm/next/index.d.ts","version":"6.2.0-prerelease.11","private":true}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@patternfly/react-core",
|
|
3
|
-
"version": "6.2.0-prerelease.
|
|
3
|
+
"version": "6.2.0-prerelease.12",
|
|
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",
|
|
@@ -63,5 +63,5 @@
|
|
|
63
63
|
"react": "^17 || ^18",
|
|
64
64
|
"react-dom": "^17 || ^18"
|
|
65
65
|
},
|
|
66
|
-
"gitHead": "
|
|
66
|
+
"gitHead": "2cadfb9dc39636e1429ac38d738b7526ddb3adef"
|
|
67
67
|
}
|
|
@@ -43,6 +43,8 @@ export interface FileUploadFieldProps extends Omit<React.HTMLProps<HTMLDivElemen
|
|
|
43
43
|
id: string;
|
|
44
44
|
/** Name property for the text input. */
|
|
45
45
|
name?: string;
|
|
46
|
+
/** Flag to disable the browse button. */
|
|
47
|
+
isBrowseButtonDisabled?: boolean;
|
|
46
48
|
/** Flag to disable the clear button. */
|
|
47
49
|
isClearButtonDisabled?: boolean;
|
|
48
50
|
/** Flag to show if the field is disabled. */
|
|
@@ -114,6 +116,7 @@ export const FileUploadField: React.FunctionComponent<FileUploadFieldProps> = ({
|
|
|
114
116
|
browseButtonText = 'Browse...',
|
|
115
117
|
browseButtonAriaDescribedby,
|
|
116
118
|
clearButtonText = 'Clear',
|
|
119
|
+
isBrowseButtonDisabled = false,
|
|
117
120
|
isClearButtonDisabled = !filename && !value,
|
|
118
121
|
containerRef = null as React.Ref<HTMLDivElement>,
|
|
119
122
|
allowEditingUploadedText = false,
|
|
@@ -153,7 +156,7 @@ export const FileUploadField: React.FunctionComponent<FileUploadFieldProps> = ({
|
|
|
153
156
|
<Button
|
|
154
157
|
variant={ButtonVariant.control}
|
|
155
158
|
onClick={onBrowseButtonClick}
|
|
156
|
-
isDisabled={isDisabled}
|
|
159
|
+
isDisabled={isDisabled || isBrowseButtonDisabled}
|
|
157
160
|
aria-describedby={browseButtonAriaDescribedby}
|
|
158
161
|
>
|
|
159
162
|
{browseButtonText}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { FileUploadField } from '../FileUploadField';
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
import { render, screen } from '@testing-library/react';
|
|
4
|
+
import '@testing-library/jest-dom';
|
|
4
5
|
|
|
5
6
|
test('simple fileuploadfield', () => {
|
|
6
7
|
const browserBtnClickHandler = jest.fn();
|
|
@@ -15,6 +16,7 @@ test('simple fileuploadfield', () => {
|
|
|
15
16
|
filenamePlaceholder="Do something custom with this!"
|
|
16
17
|
onBrowseButtonClick={browserBtnClickHandler}
|
|
17
18
|
onClearButtonClick={clearBtnClickHandler}
|
|
19
|
+
isBrowseButtonDisabled={false}
|
|
18
20
|
isClearButtonDisabled={false}
|
|
19
21
|
isLoading={false}
|
|
20
22
|
isDragActive={false}
|
|
@@ -32,7 +34,7 @@ test('Renders without aria-describedby on browse button by default', () => {
|
|
|
32
34
|
expect(screen.getByRole('button', { name: 'Upload' })).not.toHaveAccessibleDescription();
|
|
33
35
|
});
|
|
34
36
|
|
|
35
|
-
test('Renders
|
|
37
|
+
test('Renders with aria-describedby on browse button', () => {
|
|
36
38
|
render(
|
|
37
39
|
<FileUploadField id="file-upload-field" browseButtonText="Upload" browseButtonAriaDescribedby="helper-text">
|
|
38
40
|
<div id="helper-text">Helper text</div>
|
|
@@ -41,3 +43,15 @@ test('Renders without aria-describedby on browse button by default', () => {
|
|
|
41
43
|
|
|
42
44
|
expect(screen.getByRole('button', { name: 'Upload' })).toHaveAccessibleDescription('Helper text');
|
|
43
45
|
});
|
|
46
|
+
|
|
47
|
+
test('Browse button is enabled by default', () => {
|
|
48
|
+
render(<FileUploadField id="file-upload-field" browseButtonText="Upload" />);
|
|
49
|
+
|
|
50
|
+
expect(screen.getByRole('button', { name: 'Upload' })).not.toHaveAttribute('disabled');
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
test('Browse button is disabled with isBrowseButtonDisabled prop', () => {
|
|
54
|
+
render(<FileUploadField id="file-upload-field" browseButtonText="Upload" isBrowseButtonDisabled={true} />);
|
|
55
|
+
|
|
56
|
+
expect(screen.getByRole('button', { name: 'Upload' })).toHaveAttribute('disabled');
|
|
57
|
+
});
|
|
@@ -4,6 +4,7 @@ import { FileUploadField, FileUploadHelperText, HelperText, HelperTextItem, Chec
|
|
|
4
4
|
export const CustomPreviewFileUpload: React.FunctionComponent = () => {
|
|
5
5
|
const properties = [
|
|
6
6
|
'filename',
|
|
7
|
+
'isBrowseButtonDisabled',
|
|
7
8
|
'isClearButtonDisabled',
|
|
8
9
|
'isDragActive',
|
|
9
10
|
'isLoading',
|
|
@@ -15,6 +16,7 @@ export const CustomPreviewFileUpload: React.FunctionComponent = () => {
|
|
|
15
16
|
|
|
16
17
|
const [value, setValue] = React.useState('');
|
|
17
18
|
const [filename, setFilename] = React.useState(false);
|
|
19
|
+
const [isBrowseButtonDisabled, setIsBrowseButtonDisabled] = React.useState(true);
|
|
18
20
|
const [isClearButtonDisabled, setIsClearButtonDisabled] = React.useState(true);
|
|
19
21
|
const [isLoading, setIsLoading] = React.useState(false);
|
|
20
22
|
const [isDragActive, setIsDragActive] = React.useState(false);
|
|
@@ -24,6 +26,7 @@ export const CustomPreviewFileUpload: React.FunctionComponent = () => {
|
|
|
24
26
|
const [hasPlaceholderText, setHasPlaceholderText] = React.useState(false);
|
|
25
27
|
const [checkedState, setCheckedState] = React.useState([
|
|
26
28
|
filename,
|
|
29
|
+
isBrowseButtonDisabled,
|
|
27
30
|
isClearButtonDisabled,
|
|
28
31
|
isLoading,
|
|
29
32
|
isDragActive,
|
|
@@ -44,6 +47,10 @@ export const CustomPreviewFileUpload: React.FunctionComponent = () => {
|
|
|
44
47
|
checked ? setFilename(true) : setFilename(false);
|
|
45
48
|
break;
|
|
46
49
|
|
|
50
|
+
case 'isBrowseButtonDisabled':
|
|
51
|
+
checked ? setIsBrowseButtonDisabled(true) : setIsBrowseButtonDisabled(false);
|
|
52
|
+
break;
|
|
53
|
+
|
|
47
54
|
case 'isClearButtonDisabled':
|
|
48
55
|
checked ? setIsClearButtonDisabled(true) : setIsClearButtonDisabled(false);
|
|
49
56
|
break;
|
|
@@ -109,6 +116,7 @@ export const CustomPreviewFileUpload: React.FunctionComponent = () => {
|
|
|
109
116
|
filenamePlaceholder="Do something custom with this!"
|
|
110
117
|
onBrowseButtonClick={() => alert('Browse button clicked!')}
|
|
111
118
|
onClearButtonClick={() => alert('Clear button clicked!')}
|
|
119
|
+
isBrowseButtonDisabled={isBrowseButtonDisabled}
|
|
112
120
|
isClearButtonDisabled={isClearButtonDisabled}
|
|
113
121
|
isLoading={isLoading}
|
|
114
122
|
isDragActive={isDragActive}
|
|
@@ -2,13 +2,12 @@ import * as React from 'react';
|
|
|
2
2
|
import { css } from '@patternfly/react-styles';
|
|
3
3
|
import styles from '@patternfly/react-styles/css/components/JumpLinks/jump-links';
|
|
4
4
|
import sidebarStyles from '@patternfly/react-styles/css/components/Sidebar/sidebar';
|
|
5
|
-
import { JumpLinksItem, JumpLinksItemProps } from './JumpLinksItem';
|
|
6
|
-
import { JumpLinksList } from './JumpLinksList';
|
|
7
|
-
import { formatBreakpointMods } from '../../helpers/util';
|
|
8
|
-
import { Button } from '../Button';
|
|
9
5
|
import AngleRightIcon from '@patternfly/react-icons/dist/esm/icons/angle-right-icon';
|
|
10
6
|
import cssToggleDisplayVar from '@patternfly/react-tokens/dist/esm/c_jump_links__toggle_Display';
|
|
11
|
-
import {
|
|
7
|
+
import { Button } from '../Button';
|
|
8
|
+
import { JumpLinksItem, JumpLinksItemProps } from './JumpLinksItem';
|
|
9
|
+
import { JumpLinksList } from './JumpLinksList';
|
|
10
|
+
import { canUseDOM, formatBreakpointMods } from '../../helpers/util';
|
|
12
11
|
|
|
13
12
|
export interface JumpLinksProps extends Omit<React.HTMLProps<HTMLElement>, 'label'> {
|
|
14
13
|
/** Whether to center children. */
|
|
@@ -46,6 +45,8 @@ export interface JumpLinksProps extends Omit<React.HTMLProps<HTMLElement>, 'labe
|
|
|
46
45
|
toggleAriaLabel?: string;
|
|
47
46
|
/** Class for nav */
|
|
48
47
|
className?: string;
|
|
48
|
+
/** Whether the current entry in the navigation history should be replaced when a JumpLinksItem is clicked. By default a new entry will be pushed to the navigation history. */
|
|
49
|
+
shouldReplaceNavHistory?: boolean;
|
|
49
50
|
}
|
|
50
51
|
|
|
51
52
|
// Recursively find JumpLinkItems and return an array of all their scrollNodes
|
|
@@ -92,6 +93,7 @@ export const JumpLinks: React.FunctionComponent<JumpLinksProps> = ({
|
|
|
92
93
|
alwaysShowLabel = true,
|
|
93
94
|
toggleAriaLabel = 'Toggle jump links',
|
|
94
95
|
className,
|
|
96
|
+
shouldReplaceNavHistory = false,
|
|
95
97
|
...props
|
|
96
98
|
}: JumpLinksProps) => {
|
|
97
99
|
const hasScrollSpy = Boolean(scrollableRef || scrollableSelector);
|
|
@@ -207,7 +209,11 @@ export const JumpLinks: React.FunctionComponent<JumpLinksProps> = ({
|
|
|
207
209
|
scrollableElement.scrollTo(0, newScrollItem.offsetTop - offset);
|
|
208
210
|
}
|
|
209
211
|
newScrollItem.focus();
|
|
210
|
-
|
|
212
|
+
if (shouldReplaceNavHistory) {
|
|
213
|
+
window.history.replaceState('', '', (ev.currentTarget as HTMLAnchorElement).href);
|
|
214
|
+
} else {
|
|
215
|
+
window.history.pushState('', '', (ev.currentTarget as HTMLAnchorElement).href);
|
|
216
|
+
}
|
|
211
217
|
ev.preventDefault();
|
|
212
218
|
setActiveIndex(itemIndex);
|
|
213
219
|
}
|
|
@@ -88,7 +88,7 @@ export const Truncate: React.FunctionComponent<TruncateProps> = ({
|
|
|
88
88
|
if (subParentRef && subParentRef.current.parentElement.parentElement && !parentElement) {
|
|
89
89
|
setParentElement(subParentRef.current.parentElement.parentElement);
|
|
90
90
|
}
|
|
91
|
-
}, [textRef, subParentRef]);
|
|
91
|
+
}, [textRef, subParentRef, textElement, parentElement]);
|
|
92
92
|
|
|
93
93
|
React.useEffect(() => {
|
|
94
94
|
if (textElement && parentElement && !observer.current) {
|
|
@@ -106,7 +106,7 @@ export const Truncate: React.FunctionComponent<TruncateProps> = ({
|
|
|
106
106
|
observer();
|
|
107
107
|
};
|
|
108
108
|
}
|
|
109
|
-
}, [textElement, parentElement]);
|
|
109
|
+
}, [textElement, parentElement, trailingNumChars, content, position]);
|
|
110
110
|
|
|
111
111
|
const truncateBody = (
|
|
112
112
|
<span ref={subParentRef} className={css(styles.truncate, className)} {...props}>
|
|
@@ -116,18 +116,21 @@ export const Truncate: React.FunctionComponent<TruncateProps> = ({
|
|
|
116
116
|
{position === TruncatePosition.start && <React.Fragment>‎</React.Fragment>}
|
|
117
117
|
</span>
|
|
118
118
|
)}
|
|
119
|
-
{position === TruncatePosition.middle &&
|
|
120
|
-
|
|
121
|
-
<
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
119
|
+
{position === TruncatePosition.middle && content.length - trailingNumChars > minWidthCharacters && (
|
|
120
|
+
<React.Fragment>
|
|
121
|
+
<span ref={textRef} className={styles.truncateStart}>
|
|
122
|
+
{sliceContent(content, trailingNumChars)[0]}
|
|
123
|
+
</span>
|
|
124
|
+
<span className={styles.truncateEnd}>{sliceContent(content, trailingNumChars)[1]}</span>
|
|
125
|
+
</React.Fragment>
|
|
126
|
+
)}
|
|
127
|
+
{position === TruncatePosition.middle && content.length - trailingNumChars <= minWidthCharacters && (
|
|
128
|
+
<React.Fragment>
|
|
129
|
+
<span ref={textRef} className={styles.truncateStart}>
|
|
130
|
+
{content}
|
|
131
|
+
</span>
|
|
132
|
+
</React.Fragment>
|
|
133
|
+
)}
|
|
131
134
|
</span>
|
|
132
135
|
);
|
|
133
136
|
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import React from 'react';
|
|
1
|
+
import * as React from 'react';
|
|
2
2
|
import { render, screen } from '@testing-library/react';
|
|
3
3
|
import { Truncate } from '../Truncate';
|
|
4
4
|
import styles from '@patternfly/react-styles/css/components/Truncate/truncate';
|
|
5
|
+
import '@testing-library/jest-dom';
|
|
5
6
|
|
|
6
7
|
jest.mock('../../Tooltip', () => ({
|
|
7
8
|
Tooltip: ({ content, position, children, ...props }) => (
|
|
@@ -112,6 +113,21 @@ test('renders different content when trailingNumChars is passed with middle trun
|
|
|
112
113
|
expect(end).toHaveClass(styles.truncateEnd);
|
|
113
114
|
});
|
|
114
115
|
|
|
116
|
+
test('renders full content when trailingNumChars exceeds the length of the original string using middle truncate', () => {
|
|
117
|
+
render(
|
|
118
|
+
<Truncate
|
|
119
|
+
content={'Vestibulum interdum risus et enim faucibus, sit amet molestie est accumsan.'} // 75 chars
|
|
120
|
+
trailingNumChars={80}
|
|
121
|
+
position="middle"
|
|
122
|
+
/>
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
const start = screen.getByText('Vestibulum interdum risus et enim faucibus, sit amet molestie est accumsan.');
|
|
126
|
+
|
|
127
|
+
expect(start).toHaveClass(styles.truncateStart);
|
|
128
|
+
expect(start).not.toHaveClass(styles.truncateEnd);
|
|
129
|
+
});
|
|
130
|
+
|
|
115
131
|
test('renders tooltip position', () => {
|
|
116
132
|
render(<Truncate content={''} tooltipPosition="top" />);
|
|
117
133
|
|