@@ -21,6 +21,8 @@ const RADIO_BUTTON_CLASS = 'dx-radiobutton';
2121const RADIO_BUTTON_CHECKED_CLASS = 'dx-radiobutton-checked' ;
2222const RADIO_GROUP_VERTICAL_CLASS = 'dx-radiogroup-vertical' ;
2323const RADIO_GROUP_HORIZONTAL_CLASS = 'dx-radiogroup-horizontal' ;
24+ const RADIO_VALUE_CONTAINER_CLASS = 'dx-radio-value-container' ;
25+ const ITEM_CONTENT_CLASS = 'dx-item-content' ;
2426
2527const moduleConfig = {
2628 beforeEach : function ( ) {
@@ -319,23 +321,101 @@ QUnit.module('Aria accessibility', {
319321 helper . checkAttributes ( helper . $widget , { role : 'radiogroup' , tabindex : '0' } , 'widget' ) ;
320322 } ) ;
321323
322- QUnit . test ( 'Items: [1, 2, 3], Item.selected: true' , function ( ) {
324+ QUnit . test ( 'Items: [1, 2, 3], Item.selected: true' , function ( assert ) {
323325 helper . createWidget ( { items : [ 1 , 2 , 3 ] , value : 1 } ) ;
324326
325327 helper . checkAttributes ( helper . $widget , { role : 'radiogroup' , tabindex : '0' } , 'widget' ) ;
326- helper . checkItemsAttributes ( [ 0 ] , { attributes : [ 'aria-checked' ] , role : 'radio' } ) ;
328+ helper . checkItemsAttributes ( [ ] , { } ) ;
329+
330+ helper . getItems ( ) . each ( ( index , item ) => {
331+ const $radioContainer = $ ( item ) . find ( `.${ RADIO_VALUE_CONTAINER_CLASS } ` ) ;
332+ const $itemContent = $ ( item ) . find ( `.${ ITEM_CONTENT_CLASS } ` ) ;
333+ const contentId = $itemContent . attr ( 'id' ) ;
334+
335+ assert . ok ( contentId , `item[${ index } ] content element has an id` ) ;
336+ assert . strictEqual ( $radioContainer . attr ( 'role' ) , 'radio' , `item[${ index } ] radio container has role="radio"` ) ;
337+ assert . strictEqual ( $radioContainer . attr ( 'aria-checked' ) , index === 0 ? 'true' : 'false' , `item[${ index } ] radio container has correct aria-checked` ) ;
338+ assert . strictEqual ( $radioContainer . attr ( 'aria-labelledby' ) , contentId , `item[${ index } ] radio container aria-labelledby references content id` ) ;
339+ } ) ;
327340 } ) ;
328341
329- QUnit . test ( 'Items: [1, 2, 3], Item.selected: true, set focusedElement -> clean focusedElement' , function ( ) {
342+ QUnit . test ( 'Items: [1, 2, 3], Item.selected: true, set focusedElement -> clean focusedElement' , function ( assert ) {
330343 helper . createWidget ( { items : [ 1 , 2 , 3 ] , value : 1 } ) ;
331344
332345 helper . widget . option ( 'focusedElement' , helper . getItems ( ) . eq ( 0 ) ) ;
333346 helper . checkAttributes ( helper . $widget , { role : 'radiogroup' , tabindex : '0' } , 'widget' ) ;
334- helper . checkItemsAttributes ( [ 0 ] , { attributes : [ 'aria-checked' ] , role : 'radio' } ) ;
347+ helper . checkItemsAttributes ( [ ] , { } ) ;
348+
349+ helper . getItems ( ) . each ( ( index , item ) => {
350+ const $radioContainer = $ ( item ) . find ( `.${ RADIO_VALUE_CONTAINER_CLASS } ` ) ;
351+ const $itemContent = $ ( item ) . find ( `.${ ITEM_CONTENT_CLASS } ` ) ;
352+ const contentId = $itemContent . attr ( 'id' ) ;
353+
354+ assert . ok ( contentId , `item[${ index } ] content element has an id` ) ;
355+ assert . strictEqual ( $radioContainer . attr ( 'role' ) , 'radio' , `item[${ index } ] radio container has role="radio"` ) ;
356+ assert . strictEqual ( $radioContainer . attr ( 'aria-checked' ) , index === 0 ? 'true' : 'false' , `item[${ index } ] radio container has correct aria-checked` ) ;
357+ assert . strictEqual ( $radioContainer . attr ( 'aria-labelledby' ) , contentId , `item[${ index } ] radio container aria-labelledby references content id` ) ;
358+ } ) ;
335359
336360 helper . widget . option ( 'focusedElement' , null ) ;
337361 helper . checkAttributes ( helper . $widget , { role : 'radiogroup' , tabindex : '0' } , 'widget' ) ;
338- helper . checkItemsAttributes ( [ 0 ] , { attributes : [ 'aria-checked' ] , role : 'radio' } ) ;
362+ helper . checkItemsAttributes ( [ ] , { } ) ;
363+
364+ helper . getItems ( ) . each ( ( index , item ) => {
365+ const $radioContainer = $ ( item ) . find ( `.${ RADIO_VALUE_CONTAINER_CLASS } ` ) ;
366+ const $itemContent = $ ( item ) . find ( `.${ ITEM_CONTENT_CLASS } ` ) ;
367+ const contentId = $itemContent . attr ( 'id' ) ;
368+
369+ assert . ok ( contentId , `item[${ index } ] content element has an id after clearing focusedElement` ) ;
370+ assert . strictEqual ( $radioContainer . attr ( 'role' ) , 'radio' , `item[${ index } ] radio container has role="radio" after clearing focusedElement` ) ;
371+ assert . strictEqual ( $radioContainer . attr ( 'aria-checked' ) , index === 0 ? 'true' : 'false' , `item[${ index } ] radio container has correct aria-checked after clearing focusedElement` ) ;
372+ assert . strictEqual ( $radioContainer . attr ( 'aria-labelledby' ) , contentId , `item[${ index } ] radio container aria-labelledby references content id after clearing focusedElement` ) ;
373+ } ) ;
374+ } ) ;
375+
376+ QUnit . test ( 'Items with itemTemplate: radio container has correct aria attributes' , function ( assert ) {
377+ helper . createWidget ( {
378+ items : [ { text : 'custom 1' } , { text : 'custom 2' } ] ,
379+ itemTemplate ( itemData , _ , itemElement ) {
380+ const $button = $ ( '<button>' ) . text ( itemData . text ) ;
381+ itemElement . append ( $button ) ;
382+ } ,
383+ } ) ;
384+
385+ helper . checkAttributes ( helper . $widget , { role : 'radiogroup' , tabindex : '0' } , 'widget' ) ;
386+ helper . checkItemsAttributes ( [ ] , { } ) ;
387+
388+ helper . getItems ( ) . each ( ( index , item ) => {
389+ const $radioContainer = $ ( item ) . find ( `.${ RADIO_VALUE_CONTAINER_CLASS } ` ) ;
390+ const $itemContent = $ ( item ) . find ( `.${ ITEM_CONTENT_CLASS } ` ) ;
391+ const contentId = $itemContent . attr ( 'id' ) ;
392+
393+ assert . ok ( contentId , `item[${ index } ] content element has an id` ) ;
394+ assert . strictEqual ( $radioContainer . attr ( 'role' ) , 'radio' , `item[${ index } ] radio container has role="radio"` ) ;
395+ assert . strictEqual ( $radioContainer . attr ( 'aria-checked' ) , 'false' , `item[${ index } ] radio container has aria-checked="false" initially` ) ;
396+ assert . strictEqual ( $radioContainer . attr ( 'aria-labelledby' ) , contentId , `item[${ index } ] radio container aria-labelledby references content id` ) ;
397+ } ) ;
398+ } ) ;
399+
400+ QUnit . test ( 'Item with html: role="radio" is set on item element, no radio container created' , function ( assert ) {
401+ helper . createWidget ( {
402+ items : [
403+ { html : '<span>Option A</span>' } ,
404+ { html : '<span>Option B</span>' } ,
405+ ] ,
406+ } ) ;
407+
408+ helper . checkAttributes ( helper . $widget , { role : 'radiogroup' , tabindex : '0' } , 'widget' ) ;
409+
410+ helper . getItems ( ) . each ( ( index , item ) => {
411+ const $item = $ ( item ) ;
412+ const $radioContainer = $item . find ( `.${ RADIO_VALUE_CONTAINER_CLASS } ` ) ;
413+
414+ assert . strictEqual ( $radioContainer . length , 0 , `item[${ index } ] has no radio container when html is provided` ) ;
415+ assert . strictEqual ( $item . attr ( 'role' ) , 'radio' , `item[${ index } ] element itself has role="radio"` ) ;
416+ assert . strictEqual ( $item . attr ( 'aria-checked' ) , 'false' , `item[${ index } ] element has aria-checked="false" by default` ) ;
417+ assert . strictEqual ( $item . attr ( 'aria-labelledby' ) , undefined , `item[${ index } ] element has no aria-labelledby when html is provided` ) ;
418+ } ) ;
339419 } ) ;
340420} ) ;
341421
0 commit comments