@@ -97,9 +97,13 @@ export default class SdInput extends SolidElement implements SolidFormControl {
9797 * @internal
9898 */
9999 @state ( ) showValidStyle = false ;
100+
100101 /** @internal */
101102 @state ( ) showInvalidStyle = false ;
102103
104+ /** @internal */
105+ @state ( ) isClickableIconFocused = false ;
106+
103107 /**
104108 * The type of input. Works the same as a native `<input>` element, but only a subset of types are supported. Defaults
105109 * to `text`.
@@ -361,6 +365,14 @@ export default class SdInput extends SolidElement implements SolidFormControl {
361365 this . passwordVisible = ! this . passwordVisible ;
362366 }
363367
368+ private handleClickableIconFocusIn ( ) {
369+ this . isClickableIconFocused = true ;
370+ }
371+
372+ private handleClickableIconFocusOut ( ) {
373+ this . isClickableIconFocused = false ;
374+ }
375+
364376 private isDecrementDisabled ( ) {
365377 if ( this . disabled || this . readonly ) {
366378 return true ;
@@ -422,6 +434,11 @@ export default class SdInput extends SolidElement implements SolidFormControl {
422434 this . formControlController . updateValidity ( ) ;
423435 }
424436
437+ @watch ( [ 'size' , 'floatingLabel' ] )
438+ handleSizeChange ( ) {
439+ this . size = this . floatingLabel && this . size === 'sm' ? 'md' : this . size ;
440+ }
441+
425442 /** Sets focus on the input. */
426443 focus ( options ?: FocusOptions ) {
427444 this . input . focus ( options ) ;
@@ -520,7 +537,8 @@ export default class SdInput extends SolidElement implements SolidFormControl {
520537 const hasTooltip = ! ! slots [ 'tooltip' ] ;
521538 const hasIconLeft = slots [ 'left' ] ;
522539 const hasValue = this . value !== null && String ( this . value ) . length > 0 ;
523- const isFloatingLabelActive = this . floatingLabel && hasLabel && ( this . hasFocus || hasValue ) ;
540+ const isFloatingLabelActive =
541+ this . floatingLabel && hasLabel && ( this . hasFocus || hasValue || this . isClickableIconFocused ) ;
524542
525543 // Hierarchy of input states:
526544 const inputState = this . disabled
@@ -615,6 +633,7 @@ export default class SdInput extends SolidElement implements SolidFormControl {
615633 part= "base"
616634 class = ${ cx (
617635 'px-4 flex flex-row items-center rounded-default transition-colors ease-in-out duration-medium hover:duration-fast' ,
636+ this . floatingLabel && 'has-floating-label' ,
618637 // States
619638 ! this . disabled && ! this . readonly && ! this . visuallyDisabled ? 'hover:bg-neutral-200' : '' ,
620639 this . readonly ? 'bg-neutral-100' : 'bg-white' ,
@@ -699,7 +718,7 @@ export default class SdInput extends SolidElement implements SolidFormControl {
699718 'pointer-events-none leading-none' ,
700719 ! this . readonly && 'transition-all duration-medium ease-out' ,
701720 ! isFloatingLabelActive || ( ! hasValue && ( this . readonly || this . visuallyDisabled ) )
702- ? 'text-base'
721+ ? textSize
703722 : 'text-xs' ,
704723 ( this . visuallyDisabled || this . disabled ) && 'text-neutral-500' ,
705724 isFloatingLabelActive &&
@@ -741,9 +760,16 @@ export default class SdInput extends SolidElement implements SolidFormControl {
741760 <butto n
742761 aria- label= ${ this . localize . term ( this . passwordVisible ? 'hidePassword' : 'showPassword' ) }
743762 part= "password-toggle-button"
744- class = ${ cx ( 'flex items-center sd-interactive' , iconMarginLeft ) }
763+ class = ${ cx (
764+ 'flex items-center sd-interactive' ,
765+ iconMarginLeft ,
766+ this . floatingLabel && ! isFloatingLabelActive && 'hide-password-toggle'
767+ ) }
745768 type= "butto n"
746769 @click = ${ this . handlePasswordToggle }
770+ @mousedown = ${ this . handleClickableIconFocusIn }
771+ @focus = ${ ( ) => this . handleClickableIconFocusIn ( ) }
772+ @blur = ${ this . handleClickableIconFocusOut }
747773 >
748774 ${ this . passwordVisible
749775 ? html `
@@ -831,6 +857,9 @@ export default class SdInput extends SolidElement implements SolidFormControl {
831857 aria- hidden= "true"
832858 ${ longPress ( { start : ( ) => this . handleStepDown ( ) , end : ( ) => this . handleChange ( ) } ) }
833859 tabindex= "-1"
860+ @mousedown = ${ this . handleClickableIconFocusIn }
861+ @focus = ${ ( ) => this . handleClickableIconFocusIn ( ) }
862+ @blur = ${ this . handleClickableIconFocusOut }
834863 >
835864 <slot name= "decrement-number-stepper" >
836865 <sd- icon
@@ -922,6 +951,8 @@ export default class SdInput extends SolidElement implements SolidFormControl {
922951 /* Hides clock icon for time type. */
923952 input [type = 'time' ]::-webkit-calendar-picker-indicator {
924953 background : none;
954+ display : none;
955+ -webkit-appearance : none;
925956 }
926957
927958 details summary ::-webkit-details-marker ,
@@ -940,6 +971,21 @@ export default class SdInput extends SolidElement implements SolidFormControl {
940971 .stepper-button [disabled ] sd-icon {
941972 @apply text-neutral-500;
942973 }
974+
975+ .hide-password-toggle {
976+ display : none;
977+ }
978+
979+ .has-floating-label input [type = 'date' ]: not (.has-value ),
980+ .has-floating-label input [type = 'time' ]: not (.has-value ),
981+ .has-floating-label input [type = 'datetime-local' ]: not (.has-value ) {
982+ color : transparent;
983+ }
984+ .has-floating-label input [type = 'date' ]: focus,
985+ .has-floating-label input [type = 'time' ]: focus,
986+ .has-floating-label input [type = 'datetime-local' ]: focus {
987+ color : inherit;
988+ }
943989 `
944990 ] ;
945991}
0 commit comments