@@ -269,94 +269,105 @@ describe(`${Control.metadata.tag}: fit-text input`, () => {
269269removeFixture ( fixture ) ;
270270} ) ;
271271
272- it ( 'should set control width to input text character width' , async ( ) => {
272+ it ( 'should set input width to text content width' , async ( ) => {
273+ await new Promise ( resolve => requestAnimationFrame ( resolve ) ) ;
274+ const fitTextWidth = input . getBoundingClientRect ( ) . width ;
275+
276+ element . fitText = false ;
273277await elementIsStable ( element ) ;
274- expect ( element . style . getPropertyValue ( '--control-width' ) ) . toBe ( `4ch` ) ;
278+ await new Promise ( resolve => requestAnimationFrame ( resolve ) ) ;
279+
280+ expect ( fitTextWidth ) . toBeLessThan ( input . getBoundingClientRect ( ) . width ) ;
275281} ) ;
276282
277- it ( 'should update control width to input text character width' , async ( ) => {
278- await elementIsStable ( element ) ;
283+ it ( 'should update input width to text content width' , async ( ) => {
284+ await new Promise ( resolve => requestAnimationFrame ( resolve ) ) ;
285+ const initialWidth = input . getBoundingClientRect ( ) . width ;
286+
279287input . value = '123456789012345678901234567890' ;
280288input . dispatchEvent ( new Event ( 'input' ) ) ;
281289await elementIsStable ( element ) ;
282- expect ( element . style . getPropertyValue ( '--control-width' ) ) . toBe ( `30ch` ) ;
290+ await new Promise ( resolve => requestAnimationFrame ( resolve ) ) ;
291+
292+ expect ( input . getBoundingClientRect ( ) . width ) . toBeGreaterThan ( initialWidth ) ;
283293} ) ;
284294
285- it ( 'should update control width to input text character width with icon offset' , async ( ) => {
286- await elementIsStable ( element ) ;
295+ it ( 'should update input width to native date content width' , async ( ) => {
296+ await new Promise ( resolve => requestAnimationFrame ( resolve ) ) ;
297+ const textWidth = input . getBoundingClientRect ( ) . width ;
298+
287299input . type = 'date' ;
288300input . value = '' ;
289301input . dispatchEvent ( new Event ( 'input' ) ) ;
290302await elementIsStable ( element ) ;
291- expect ( element . style . getPropertyValue ( '--control-width' ) ) . toBe ( `4ch` ) ;
292- expect ( input . style . maxWidth ) . toBe ( `2ch` ) ;
303+ await new Promise ( resolve => requestAnimationFrame ( resolve ) ) ;
304+
305+ expect ( input . getBoundingClientRect ( ) . width ) . toBeGreaterThan ( textWidth ) ;
293306} ) ;
294307} ) ;
295308
296- describe ( `${ Control . metadata . tag } : fit-content input ` , ( ) => {
309+ describe ( `${ Control . metadata . tag } : fit-text select ` , ( ) => {
297310let fixture : HTMLElement ;
298311let element : Control ;
299- let input : HTMLInputElement ;
312+ let select : HTMLSelectElement ;
300313
301314beforeEach ( async ( ) => {
302315fixture = await createFixture ( html `
303- < nve-control fit-content >
316+ < nve-control fit-text >
304317< label > label</ label >
305- < input type ="text " />
318+ < select >
319+ < option value ="short "> Short</ option >
320+ < option value ="long "> A much longer option</ option >
321+ </ select >
306322</ nve-control >
307323 ` ) ;
308324element = fixture . querySelector ( Control . metadata . tag ) ;
309- input = fixture . querySelector ( 'input ' ) ;
325+ select = fixture . querySelector ( 'select ' ) ;
310326await elementIsStable ( element ) ;
311327} ) ;
312328
313329afterEach ( ( ) => {
314330removeFixture ( fixture ) ;
315331} ) ;
316332
317- it ( 'should update control width to input browser default content' , async ( ) => {
333+ it ( 'should update select width to selected content width' , async ( ) => {
334+ await new Promise ( resolve => requestAnimationFrame ( resolve ) ) ;
335+ const initialWidth = select . getBoundingClientRect ( ) . width ;
336+
337+ select . value = 'long' ;
338+ select . dispatchEvent ( new Event ( 'change' ) ) ;
318339await elementIsStable ( element ) ;
319- await new Promise ( r => requestAnimationFrame ( r ) ) ;
320- expect ( Math . floor ( input . getBoundingClientRect ( ) . width ) > 100 ) . toBe ( true ) ;
321- expect ( Math . floor ( input . getBoundingClientRect ( ) . width ) < 250 ) . toBe ( true ) ;
340+ await new Promise ( resolve => requestAnimationFrame ( resolve ) ) ;
341+
342+ expect ( select . getBoundingClientRect ( ) . width ) . toBeGreaterThan ( initialWidth ) ;
322343} ) ;
323344} ) ;
324345
325- describe ( `${ Control . metadata . tag } : fit-text select ` , ( ) => {
346+ describe ( `${ Control . metadata . tag } : fit-content input ` , ( ) => {
326347let fixture : HTMLElement ;
327348let element : Control ;
328- let input : HTMLSelectElement ;
349+ let input : HTMLInputElement ;
329350
330351beforeEach ( async ( ) => {
331352fixture = await createFixture ( html `
332- < nve-control fit-text >
353+ < nve-control fit-content >
333354< label > label</ label >
334- < select >
335- < option value ="1 "> Option 1</ option >
336- < option value ="2 "> Option 12345678</ option >
337- </ select >
338- < nve-control-message > message</ nve-control-message >
355+ < input type ="text " />
339356</ nve-control >
340357 ` ) ;
341358element = fixture . querySelector ( Control . metadata . tag ) ;
342- input = fixture . querySelector ( 'select ' ) ;
359+ input = fixture . querySelector ( 'input ' ) ;
343360await elementIsStable ( element ) ;
344361} ) ;
345362
346363afterEach ( ( ) => {
347364removeFixture ( fixture ) ;
348365} ) ;
349366
350- it ( 'should set control width to input text character width' , async ( ) => {
351- await elementIsStable ( element ) ;
352- expect ( element . style . getPropertyValue ( '--control-width' ) ) . toBe ( `12ch` ) ;
353- } ) ;
354-
355- it ( 'should update control width to input text character width' , async ( ) => {
356- await elementIsStable ( element ) ;
357- input . value = '2' ;
358- input . dispatchEvent ( new Event ( 'change' ) ) ;
367+ it ( 'should update control width to input browser default content' , async ( ) => {
359368await elementIsStable ( element ) ;
360- expect ( element . style . getPropertyValue ( '--control-width' ) ) . toBe ( `19ch` ) ;
369+ await new Promise ( r => requestAnimationFrame ( r ) ) ;
370+ expect ( Math . floor ( input . getBoundingClientRect ( ) . width ) > 100 ) . toBe ( true ) ;
371+ expect ( Math . floor ( input . getBoundingClientRect ( ) . width ) < 250 ) . toBe ( true ) ;
361372} ) ;
362373} ) ;
0 commit comments