File tree Expand file tree Collapse file tree
apps/web/src/components/ui Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import { describe , expect , it } from "vite-plus/test" ;
2+
3+ import { render } from "../../../test/render" ;
4+ import { MiddleTruncate } from "./middle-truncate" ;
5+
6+ import "~/index.css" ;
7+
8+ const narrow = ( value : string ) => (
9+ < div style = { { width : 80 } } >
10+ < MiddleTruncate value = { value } className = "w-full" />
11+ </ div >
12+ ) ;
13+
14+ describe ( "MiddleTruncate" , ( ) => {
15+ it ( "does not clip a short value that replaces a truncated one" , async ( ) => {
16+ await using screen = await render ( narrow ( "t3/investigate-release-build-times" ) ) ;
17+ const label = ( ) => screen . container . querySelector ( "[title] > span" ) ;
18+ await expect . poll ( ( ) => label ( ) ?. hasAttribute ( "data-overflow" ) ) . toBe ( true ) ;
19+
20+ await screen . rerender ( narrow ( "main" ) ) ;
21+
22+ expect ( label ( ) ) . toHaveTextContent ( "main" ) ;
23+ expect ( label ( ) ) . not . toHaveAttribute ( "data-overflow" ) ;
24+ expect ( label ( ) ) . toHaveStyle ( { clipPath : "none" } ) ;
25+ } ) ;
26+ } ) ;
Original file line number Diff line number Diff line change @@ -47,7 +47,10 @@ export function MiddleTruncate({
4747 < span className = "shrink-0 peer-data-overflow:before:content-['…']" > { split . tail } </ span >
4848 </ >
4949 ) : (
50- < span className = "min-w-0 truncate" > { value } </ span >
50+ // Keyed so React does not reuse the head node and its imperative clip.
51+ < span key = "whole" className = "min-w-0 truncate" >
52+ { value }
53+ </ span >
5154 ) }
5255 </ span >
5356 ) ;
You can’t perform that action at this time.
0 commit comments