File tree Expand file tree Collapse file tree 3 files changed +33
-12
lines changed 
packages/ods/src/components 
datepicker/src/components/ods-datepicker Expand file tree Collapse file tree 3 files changed +33
-12
lines changed Original file line number Diff line number Diff line change @@ -331,12 +331,7 @@ export class OdsDatepicker implements OdsFormElement {
331331  } 
332332
333333  private  onInput ( event : InputEvent ) : void { 
334-     const  value  =  ( event . target  as  HTMLInputElement ) . value ; 
335-     if  ( ! value )  { 
336-       this . showClearable  =  false ; 
337-     }  else  { 
338-       this . showClearable  =  true ; 
339-     } 
334+     this . showClearable  =  ! ( event . target  as  HTMLInputElement ) . value ; 
340335  } 
341336
342337  render ( ) : FunctionalComponent  { 
Original file line number Diff line number Diff line change @@ -218,6 +218,8 @@ export class OdsInput implements OdsFormElement {
218218    }  else  { 
219219      this . value  =  this . inputEl ?. value  ??  null ; 
220220    } 
221+ 
222+     this . showClearable  =  ! this . inputEl ?. validity . valid  &&  ! this . inputEl ?. validity . valueMissing ; 
221223  } 
222224
223225  private  onListSlotChange ( event : Event ) : void { 
@@ -258,11 +260,12 @@ export class OdsInput implements OdsFormElement {
258260      this . shouldUpdateIsInvalidState  =  false ; 
259261    } 
260262
261-     if  ( ! this . internals . validity ?. valid  &&  ! this . internals . validity ?. valueMissing )  { 
262-       this . showClearable  =  true ; 
263-     }  else  { 
264-       this . showClearable  =  false ; 
265-     } 
263+     // console.log('this.internals.validity', this.internals.validity) 
264+     // if (!this.internals.validity?.valid && !this.internals.validity?.valueMissing) { 
265+     //   this.showClearable = true; 
266+     // } else { 
267+     //   this.showClearable = false; 
268+     // } 
266269
267270    this . odsChange . emit ( { 
268271      name : this . name , 
@@ -273,7 +276,7 @@ export class OdsInput implements OdsFormElement {
273276  } 
274277
275278  render ( ) : FunctionalComponent  { 
276-     const  hasClearableIcon  =  this . isClearable  &&  ! this . isLoading  &&  ( ! ! this . showClearable  ||  ! ! this . value ) ; 
279+     const  hasClearableIcon  =  this . isClearable  &&  ! this . isLoading  &&  ( this . showClearable  ||  ! ! this . value ) ; 
277280    const  hasToggleMaskIcon  =  this . isPassword  &&  ! this . isLoading ; 
278281    const  hasSearchIcon  =  this . type  ===  ODS_INPUT_TYPE . search  &&  ! this . isLoading ; 
279282
Original file line number Diff line number Diff line change @@ -251,6 +251,29 @@ describe('ods-input rendering', () => {
251251
252252      expect ( buttonClearable ) . not . toBeNull ( ) ; 
253253    } ) ; 
254+ 
255+     it ( 'should render a clearable button when type' ,  async ( )  =>  { 
256+       await  setup ( '<ods-input is-clearable type="number"></ods-input>' ) ; 
257+ 
258+       await  el . type ( '12' ) ; 
259+       await  page . waitForChanges ( ) ; 
260+       buttonClearable  =  await  page . find ( 'ods-input >>> ods-button[icon="xmark"]' ) ; 
261+       expect ( buttonClearable ) . not . toBeNull ( ) ; 
262+ 
263+       await  page . keyboard . press ( 'Backspace' ) ; 
264+       await  page . keyboard . press ( 'Backspace' ) ; 
265+       await  page . waitForChanges ( ) ; 
266+ 
267+       buttonClearable  =  await  page . find ( 'ods-input >>> ods-button[icon="xmark"]' ) ; 
268+       expect ( buttonClearable ) . toBeNull ( ) ; 
269+ 
270+       // Test E2E launched with chrome. Chrome don't allow to type on input type number 
271+       // await page.keyboard.press('q'); 
272+       // await page.waitForChanges(); 
273+       // await new Promise(resolve => setTimeout(resolve, 20000)); 
274+       // buttonClearable = await page.find('ods-input >>> ods-button[icon="xmark"]'); 
275+       // expect(buttonClearable).not.toBeNull(); 
276+     } ) ; 
254277  } ) ; 
255278
256279  describe ( 'type search' ,  ( )  =>  { 
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments