File tree Expand file tree Collapse file tree 5 files changed +30
-4
lines changed
projects/igniteui-angular/src/lib Expand file tree Collapse file tree 5 files changed +30
-4
lines changed Original file line number Diff line number Diff line change @@ -159,6 +159,17 @@ describe('Avatar', () => {
159159 expect ( hostEl . getAttribute ( 'aria-roledescription' ) ) . toEqual ( 'image avatar' ) ;
160160 expect ( hostEl . getAttribute ( 'aria-label' ) ) . toEqual ( 'avatar' ) ;
161161 } ) ;
162+
163+ it ( 'Normalizes the value of the `src` input' , ( ) => {
164+ const fixture = TestBed . createComponent ( InitImageAvatarComponent ) ;
165+ fixture . detectChanges ( ) ;
166+
167+ const instance = fixture . componentInstance . avatar ;
168+ instance . src = "/assets/Test - 17.jpg" ;
169+ fixture . detectChanges ( ) ;
170+
171+ expect ( instance . src ) . toEqual ( "/assets/Test%20-%2017.jpg" ) ;
172+ } ) ;
162173} ) ;
163174
164175@Component ( {
Original file line number Diff line number Diff line change 99 ViewChild
1010} from '@angular/core' ;
1111
12- import { mkenum } from '../core/utils' ;
12+ import { mkenum , normalizeURI } from '../core/utils' ;
1313import { IgxIconComponent } from '../icon/icon.component' ;
1414
1515let NEXT_ID = 0 ;
@@ -202,7 +202,13 @@ export class IgxAvatarComponent implements OnInit {
202202 * @igxFriendlyName Image URL
203203 */
204204 @Input ( )
205- public src : string ;
205+ public set src ( value : string ) {
206+ this . _src = normalizeURI ( value ) ;
207+ }
208+
209+ public get src ( ) {
210+ return this . _src ;
211+ }
206212
207213 /** @hidden @internal */
208214 @ViewChild ( 'defaultTemplate' , { read : TemplateRef , static : true } )
@@ -225,6 +231,7 @@ export class IgxAvatarComponent implements OnInit {
225231 * @internal
226232 */
227233 private _size : string | IgxAvatarSize ;
234+ private _src : string ;
228235
229236 /**
230237 * Returns the size of the avatar.
Original file line number Diff line number Diff line change @@ -639,3 +639,11 @@ export function getComponentCssSizeVar(size: string) {
639639 return 'var(--ig-size, var(--ig-size-large))' ;
640640 }
641641}
642+
643+ /**
644+ * @param path - The URI path to be normalized.
645+ * @returns string endoded using the encodeURI function.
646+ */
647+ export function normalizeURI ( path : string ) {
648+ return path . split ( '/' ) . map ( encodeURI ) . join ( '/' ) ;
649+ }
Original file line number Diff line number Diff line change @@ -17,7 +17,7 @@ <h4 class="sample-title">Circular Avatars</h4>
1717
1818 < igx-avatar src ="https://images.unsplash.com/photo-1514041790697-53f1f86214d2?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=b7ac79503fbe78855a346c8d814f95ba&auto=format&fit=crop&w=1650&q=80 " size ="small " shape ="circle "> </ igx-avatar >
1919
20- < igx-avatar src ="assets/images/avatar/17.jpg " size ="medium " shape ="circle "> </ igx-avatar >
20+ < igx-avatar src ="assets/images/avatar/17 - Test .jpg " size ="medium " shape ="circle "> </ igx-avatar >
2121
2222 < igx-avatar src ="https://images.unsplash.com/photo-1506804880640-f3205deb1b8b?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=2f8dd0c16478825034602dce63d9aaca&auto=format&fit=crop&w=1350&q=80 " size ="large " shape ="circle "> </ igx-avatar >
2323 </ article >
@@ -41,7 +41,7 @@ <h4 class="sample-title">Rounded Avatars</h4>
4141
4242 < igx-avatar src ="https://images.unsplash.com/photo-1514041790697-53f1f86214d2?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=b7ac79503fbe78855a346c8d814f95ba&auto=format&fit=crop&w=1650&q=80 " size ="small " shape ="rounded "> </ igx-avatar >
4343
44- < igx-avatar src ="assets/images/avatar/17.jpg " size ="medium "
44+ < igx-avatar src ="assets/images/avatar/17 - Test .jpg " size ="medium "
4545 shape ="rounded "> </ igx-avatar >
4646
4747 < igx-avatar src ="https://images.unsplash.com/photo-1506804880640-f3205deb1b8b?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=2f8dd0c16478825034602dce63d9aaca&auto=format&fit=crop&w=1350&q=80 " size ="large " shape ="rounded "> </ igx-avatar >
File renamed without changes.
You can’t perform that action at this time.
0 commit comments