File tree Expand file tree Collapse file tree 3 files changed +14
-7
lines changed
packages/react-core/src/components/Truncate Expand file tree Collapse file tree 3 files changed +14
-7
lines changed Original file line number Diff line number Diff line change @@ -142,13 +142,18 @@ export const Truncate: React.FunctionComponent<TruncateProps> = ({
142142 setShouldRenderByMaxChars ( maxCharsDisplayed > 0 ) ;
143143 } , [ maxCharsDisplayed ] ) ;
144144
145+ const lrmEntity = < Fragment > ‎</ Fragment > ;
146+ const isStartPosition = position === TruncatePosition . start ;
147+ const isEndPosition = position === TruncatePosition . end ;
148+
145149 const renderResizeObserverContent = ( ) => {
146- if ( position === TruncatePosition . end || position === TruncatePosition . start ) {
150+ if ( isEndPosition || isStartPosition ) {
147151 return (
148152 < >
149153 < span ref = { textRef } className = { truncateStyles [ position ] } >
154+ { isStartPosition && lrmEntity }
150155 { content }
151- { position === TruncatePosition . start && < Fragment > ‎ </ Fragment > }
156+ { isStartPosition && lrmEntity }
152157 </ span >
153158 </ >
154159 ) ;
@@ -195,7 +200,7 @@ export const Truncate: React.FunctionComponent<TruncateProps> = ({
195200 </ >
196201 ) ;
197202 }
198- if ( position === TruncatePosition . end ) {
203+ if ( isEndPosition ) {
199204 return (
200205 < >
201206 { renderVisibleContent ( content . slice ( 0 , maxCharsDisplayed ) ) }
Original file line number Diff line number Diff line change 11import { render , screen , within } from '@testing-library/react' ;
2- import { Truncate } from '../Truncate' ;
2+ import { Truncate , TruncatePosition } from '../Truncate' ;
33import styles from '@patternfly/react-styles/css/components/Truncate/truncate' ;
44import '@testing-library/jest-dom' ;
55
@@ -67,7 +67,9 @@ test('renders default truncation', () => {
6767 expect ( asFragment ( ) ) . toMatchSnapshot ( ) ;
6868} ) ;
6969
70- test ( 'renders start truncation with ‎ at end' , ( ) => {
70+ // If this snapshot fails and the output text doesn't seem like it's changed, it most likely
71+ // is due to the ‎ HTML entity isn't rendering correctly.
72+ test ( 'renders start truncation with ‎ at start and end' , ( ) => {
7173 const { asFragment } = render (
7274 < Truncate
7375 content = { 'Vestibulum interdum risus et enim faucibus, sit amet molestie est accumsan.' }
Original file line number Diff line number Diff line change @@ -65,7 +65,7 @@ exports[`renders default truncation 1`] = `
6565</DocumentFragment >
6666` ;
6767
68- exports [` renders start truncation with ‎ at end 1` ] = `
68+ exports [` renders start truncation with ‎ at start and end 1` ] = `
6969<DocumentFragment >
7070 <div
7171 data-testid = " Tooltip-mock"
@@ -86,7 +86,7 @@ exports[`renders start truncation with ‎ at end 1`] = `
8686 <span
8787 class = " pf-v6-c-truncate__end"
8888 >
89- Vestibulum interdum risus et enim faucibus, sit amet molestie est accumsan.
89+ Vestibulum interdum risus et enim faucibus, sit amet molestie est accumsan.
9090 </span >
9191 </span >
9292</DocumentFragment >
You can’t perform that action at this time.
0 commit comments