@@ -28,6 +28,7 @@ import type {
2828 TextInputStyleProps ,
2929 TextInputStyle
3030} from './props'
31+ import { alpha } from '@instructure/ui-color-utils'
3132
3233/**
3334 * ---
@@ -78,29 +79,12 @@ const generateStyle = (
7879 }
7980 : { }
8081
81- const focusedStyle = focused
82- ? {
83- opacity : 1 ,
84- outlineOffset : '0.15rem'
85- }
86- : {
87- opacity : 0 ,
88- outlineOffset : '-0.9rem'
89- }
90-
9182 const invalidStyle = invalid
9283 ? {
9384 borderColor : componentTheme . errorBorderColor
9485 }
9586 : { }
9687
97- const invalidAndFocusedStyle =
98- invalid && focused
99- ? {
100- borderColor : componentTheme . errorBorderColor
101- }
102- : { }
103-
10488 const inputStyle = {
10589 all : 'initial' ,
10690 '&::-ms-clear' : {
@@ -150,6 +134,16 @@ const generateStyle = (
150134 flexDirection : 'row'
151135 }
152136
137+ let outlineColor
138+ if ( invalid ) {
139+ outlineColor = focused
140+ ? componentTheme . errorOutlineColor
141+ : alpha ( componentTheme . errorOutlineColor , 0 )
142+ } else {
143+ outlineColor = focused
144+ ? componentTheme . focusOutlineColor
145+ : alpha ( componentTheme . focusOutlineColor , 0 )
146+ }
153147 return {
154148 requiredInvalid : {
155149 color : componentTheme . requiredInvalidColor
@@ -166,27 +160,14 @@ const generateStyle = (
166160 display : 'block' ,
167161 boxSizing : 'border-box' ,
168162 border : `${ componentTheme . borderWidth } ${ componentTheme . borderStyle } ${ componentTheme . borderColor } ` ,
169- borderRadius : componentTheme . borderRadius ,
170163 background : componentTheme . background ,
171164 color : componentTheme . color ,
172-
173- '&::before' : {
174- content : '""' ,
175- pointerEvents : 'none' ,
176- position : 'absolute' ,
177- display : 'block' ,
178- boxSizing : 'border-box' ,
179- top : '0' ,
180- bottom : '0' ,
181- left : '0' ,
182- right : '0' ,
183- outline : `${ componentTheme . focusOutlineWidth } ${ componentTheme . focusOutlineStyle } ${ componentTheme . focusOutlineColor } ` ,
184- borderRadius : componentTheme . borderRadius ,
185- transition : 'opacity 0.2s, outline-offset 0.2s ease-out' ,
186-
187- ...focusedStyle , // properties to transition on :focus
188- ...invalidAndFocusedStyle
189- } ,
165+ borderRadius : componentTheme . borderRadius ,
166+ // animate the focus ring
167+ outline : `${ componentTheme . focusOutlineWidth } ${ componentTheme . focusOutlineStyle } ${ outlineColor } ` ,
168+ outlineOffset : '-0.8rem' ,
169+ transition : 'outline 0.2s, outline-offset 0.25s' ,
170+ ...( focused && { outlineOffset : '0.15rem' } ) ,
190171 ...disabledStyle ,
191172 ...invalidStyle
192173 } ,
0 commit comments