@@ -297,7 +297,7 @@ describe("Icon general interaction", () => {
297297 cy . get ( "[ui5-icon][mode='Interactive']" ) . then ( $icon => {
298298 const icon = $icon [ 0 ] as any ;
299299 const accessibilityInfo = icon . accessibilityInfo ;
300-
300+
301301 // For Interactive mode, accessibilityInfo should have role, type and description
302302 expect ( accessibilityInfo ) . to . not . be . undefined ;
303303 expect ( accessibilityInfo . role ) . to . equal ( "button" ) ;
@@ -317,7 +317,7 @@ describe("Icon general interaction", () => {
317317 cy . get ( "[ui5-icon][mode='Decorative']" ) . then ( $icon => {
318318 const icon = $icon [ 0 ] as any ;
319319 const accessibilityInfo = icon . accessibilityInfo ;
320-
320+
321321 // For Decorative mode, accessibilityInfo should return an empty object
322322 expect ( accessibilityInfo ) . to . deep . equal ( { } ) ;
323323 } ) ;
@@ -334,7 +334,7 @@ describe("Icon general interaction", () => {
334334 cy . get ( "[ui5-icon][mode='Image']" ) . then ( $icon => {
335335 const icon = $icon [ 0 ] as any ;
336336 const accessibilityInfo = icon . accessibilityInfo ;
337-
337+
338338 // For Image mode, accessibilityInfo should have role, type and description
339339 expect ( accessibilityInfo ) . to . not . be . undefined ;
340340 expect ( accessibilityInfo . role ) . to . equal ( "img" ) ;
@@ -343,3 +343,143 @@ describe("Icon general interaction", () => {
343343 } ) ;
344344 } ) ;
345345} ) ;
346+
347+ describe ( "Icon fontIcon slot" , ( ) => {
348+ it ( "renders a span root instead of svg when fontIcon slot is used" , ( ) => {
349+ cy . mount (
350+ < Icon >
351+ < span slot = "fontIcon" > ★</ span >
352+ </ Icon >
353+ ) ;
354+
355+ cy . get ( "[ui5-icon]" ) . shadow ( ) . find ( "span.ui5-icon-root" ) . should ( "exist" ) ;
356+ cy . get ( "[ui5-icon]" ) . shadow ( ) . find ( "svg" ) . should ( "not.exist" ) ;
357+ } ) ;
358+
359+ it ( "Decorative mode: span root has role=presentation and aria-hidden=true" , ( ) => {
360+ cy . mount (
361+ < Icon >
362+ < span slot = "fontIcon" > ★</ span >
363+ </ Icon >
364+ ) ;
365+
366+ cy . get ( "[ui5-icon]" ) . shadow ( ) . find ( "span.ui5-icon-root" )
367+ . should ( "have.attr" , "role" , "presentation" )
368+ . should ( "have.attr" , "aria-hidden" , "true" ) ;
369+ } ) ;
370+
371+ it ( "Image mode: span root has role=img and aria-label" , ( ) => {
372+ cy . mount (
373+ < Icon mode = "Image" accessibleName = "Star" >
374+ < span slot = "fontIcon" > ★</ span >
375+ </ Icon >
376+ ) ;
377+
378+ cy . get ( "[ui5-icon]" ) . shadow ( ) . find ( "span.ui5-icon-root" )
379+ . should ( "have.attr" , "role" , "img" )
380+ . should ( "have.attr" , "aria-label" , "Star" )
381+ . should ( "not.have.attr" , "aria-hidden" ) ;
382+ } ) ;
383+
384+ it ( "Interactive mode: span root has role=button and tabindex=0" , ( ) => {
385+ cy . mount (
386+ < Icon mode = "Interactive" accessibleName = "Add" >
387+ < span slot = "fontIcon" > +</ span >
388+ </ Icon >
389+ ) ;
390+
391+ cy . get ( "[ui5-icon]" ) . shadow ( ) . find ( "span.ui5-icon-root" )
392+ . should ( "have.attr" , "role" , "button" )
393+ . should ( "have.attr" , "tabindex" , "0" )
394+ . should ( "have.attr" , "aria-label" , "Add" ) ;
395+ } ) ;
396+
397+ it ( "Interactive mode: fires ui5-click on mouse click" , ( ) => {
398+ cy . mount (
399+ < Icon mode = "Interactive" accessibleName = "Add" >
400+ < span slot = "fontIcon" > +</ span >
401+ </ Icon >
402+ ) ;
403+
404+ cy . get ( "[ui5-icon]" ) . then ( $icon => {
405+ $icon [ 0 ] . addEventListener ( "ui5-click" , cy . stub ( ) . as ( "ui5Click" ) ) ;
406+ } ) ;
407+
408+ cy . get ( "[ui5-icon]" ) . realClick ( ) ;
409+ cy . get ( "@ui5Click" ) . should ( "have.been.calledOnce" ) ;
410+ } ) ;
411+
412+ it ( "Interactive mode: fires ui5-click on Enter key" , ( ) => {
413+ cy . mount (
414+ < Icon mode = "Interactive" accessibleName = "Add" >
415+ < span slot = "fontIcon" > +</ span >
416+ </ Icon >
417+ ) ;
418+
419+ cy . get ( "[ui5-icon]" ) . then ( $icon => {
420+ $icon [ 0 ] . addEventListener ( "ui5-click" , cy . stub ( ) . as ( "ui5Click" ) ) ;
421+ } ) ;
422+
423+ cy . get ( "[ui5-icon]" ) . shadow ( ) . find ( "span.ui5-icon-root" ) . focus ( ) ;
424+ cy . realPress ( "Enter" ) ;
425+ cy . get ( "@ui5Click" ) . should ( "have.been.calledOnce" ) ;
426+ } ) ;
427+
428+ it ( "Interactive mode: fires ui5-click on Space key" , ( ) => {
429+ cy . mount (
430+ < Icon mode = "Interactive" accessibleName = "Add" >
431+ < span slot = "fontIcon" > +</ span >
432+ </ Icon >
433+ ) ;
434+
435+ cy . get ( "[ui5-icon]" ) . then ( $icon => {
436+ $icon [ 0 ] . addEventListener ( "ui5-click" , cy . stub ( ) . as ( "ui5Click" ) ) ;
437+ } ) ;
438+
439+ cy . get ( "[ui5-icon]" ) . shadow ( ) . find ( "span.ui5-icon-root" ) . focus ( ) ;
440+ cy . realPress ( "Space" ) ;
441+ cy . get ( "@ui5Click" ) . should ( "have.been.calledOnce" ) ;
442+ } ) ;
443+
444+ it ( "Decorative mode: does not fire ui5-click on click" , ( ) => {
445+ cy . mount (
446+ < Icon >
447+ < span slot = "fontIcon" > ★</ span >
448+ </ Icon >
449+ ) ;
450+
451+ cy . get ( "[ui5-icon]" ) . then ( $icon => {
452+ $icon [ 0 ] . addEventListener ( "ui5-click" , cy . stub ( ) . as ( "ui5Click" ) ) ;
453+ } ) ;
454+
455+ cy . get ( "[ui5-icon]" ) . realClick ( ) ;
456+ cy . get ( "@ui5Click" ) . should ( "not.have.been.called" ) ;
457+ } ) ;
458+
459+ it ( "no accessible-name: aria-label is not set" , ( ) => {
460+ cy . mount (
461+ < Icon mode = "Image" >
462+ < span slot = "fontIcon" > ★</ span >
463+ </ Icon >
464+ ) ;
465+
466+ cy . get ( "[ui5-icon]" ) . shadow ( ) . find ( "span.ui5-icon-root" )
467+ . should ( "not.have.attr" , "aria-label" ) ;
468+ } ) ;
469+
470+ it ( "accessible-name takes effect when set" , ( ) => {
471+ cy . mount (
472+ < Icon mode = "Image" accessibleName = "Initial" >
473+ < span slot = "fontIcon" > ★</ span >
474+ </ Icon >
475+ ) ;
476+
477+ cy . get ( "[ui5-icon]" ) . shadow ( ) . find ( "span.ui5-icon-root" )
478+ . should ( "have.attr" , "aria-label" , "Initial" ) ;
479+
480+ cy . get ( "[ui5-icon]" ) . invoke ( "prop" , "accessibleName" , "Updated" ) ;
481+
482+ cy . get ( "[ui5-icon]" ) . shadow ( ) . find ( "span.ui5-icon-root" )
483+ . should ( "have.attr" , "aria-label" , "Updated" ) ;
484+ } ) ;
485+ } ) ;
0 commit comments