With your code, you are adding/removing your <i>
from DOM depending on visibility
So you won't have any CSS-transition if your icon is removed from DOM, or if your icon has just been added to DOM.
Your icon needs to be on DOM everytime so CSS transitions can apply
<>
<i className={`fa fa-angle-up my-float ${visibility && 'hidden'} />
<i className={`fa fa-times my-float ${!visibility && 'hidden'} />
</>
Or using https://www.npmjs.com/package/clsx
import cn from 'clsx';
<>
<i className={cn('fa fa-angle-up my-float', visibility && 'hidden')} />
<i className={cn('fa fa-times my-float', !visibility && 'hidden'} />
</>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…