@@ -395,6 +395,86 @@ describe('Modal', () => {
395395 expect ( container . firstChild ) . toHaveClass ( `${ prefix } --modal--slug` ) ;
396396 spy . mockRestore ( ) ;
397397 } ) ;
398+
399+ it ( 'should set correct focus if data-modal-primary-focus is used' , ( ) => {
400+ render (
401+ < Modal
402+ open
403+ id = "custom-modal-id"
404+ data-testid = "modal-4"
405+ loadingStatus = "active"
406+ loadingDescription = "loading..."
407+ primaryButtonText = "Save"
408+ secondaryButtonText = "Cancel" >
409+ < p >
410+ Custom domains direct requests for your apps in this Cloud Foundry
411+ organization to a URL that you own. A custom domain can be a shared
412+ domain, a shared subdomain, or a shared domain and host.
413+ </ p >
414+ < TextInput
415+ data-modal-primary-focus
416+ id = "text-input-1"
417+ data-testid = "text-input-1"
418+ labelText = "Domain name"
419+ />
420+ </ Modal >
421+ ) ;
422+
423+ expect ( screen . getByTestId ( 'text-input-1' ) ) . toHaveFocus ( ) ;
424+ } ) ;
425+
426+ it ( 'should set correct focus on a danger modal if data-modal-primary-focus is used' , ( ) => {
427+ render (
428+ < Modal
429+ open
430+ danger
431+ id = "custom-modal-id"
432+ data-testid = "modal-4"
433+ loadingStatus = "active"
434+ loadingDescription = "loading..."
435+ primaryButtonText = "Save"
436+ secondaryButtonText = "Cancel" >
437+ < p >
438+ Custom domains direct requests for your apps in this Cloud Foundry
439+ organization to a URL that you own. A custom domain can be a shared
440+ domain, a shared subdomain, or a shared domain and host.
441+ </ p >
442+ < TextInput
443+ data-modal-primary-focus
444+ id = "text-input-1"
445+ data-testid = "text-input-1"
446+ labelText = "Domain name"
447+ />
448+ </ Modal >
449+ ) ;
450+
451+ expect ( screen . getByTestId ( 'text-input-1' ) ) . toHaveFocus ( ) ;
452+ } ) ;
453+
454+ it ( 'should set focus on secondary button if danger modal is used' , ( ) => {
455+ render (
456+ < Modal
457+ open
458+ danger
459+ id = "custom-modal-id"
460+ data-testid = "modal-4"
461+ primaryButtonText = "Save"
462+ secondaryButtonText = "Cancel" >
463+ < p >
464+ Custom domains direct requests for your apps in this Cloud Foundry
465+ organization to a URL that you own. A custom domain can be a shared
466+ domain, a shared subdomain, or a shared domain and host.
467+ </ p >
468+ < TextInput
469+ id = "text-input-1"
470+ data-testid = "text-input-1"
471+ labelText = "Domain name"
472+ />
473+ </ Modal >
474+ ) ;
475+
476+ expect ( screen . getByText ( 'Cancel' ) ) . toHaveFocus ( ) ;
477+ } ) ;
398478} ) ;
399479
400480describe ( 'events' , ( ) => {
0 commit comments