File tree Expand file tree Collapse file tree
packages/ui-components/src/components/Modal Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -201,7 +201,15 @@ export const Modal: React.FC<ModalProps> = ({
201201 ) : (
202202 ""
203203 ) }
204- { isCloseable && ! disableCloseButton ? < Icon icon = "close" onClick = { handleCancelClick } /> : "" }
204+ { isCloseable ? (
205+ < Icon
206+ icon = "close"
207+ onClick = { handleCancelClick }
208+ disabled = { disableCancelButton || disableCloseButton }
209+ />
210+ ) : (
211+ ""
212+ ) }
205213 </ div >
206214 < div className = { `juno-modal-content ${ contentstyles } ${ unpad ? "" : contentpaddingstyles } ` } >
207215 { children }
Original file line number Diff line number Diff line change @@ -223,6 +223,15 @@ export const CloseOnBackdropClick: Story = {
223223 } ,
224224}
225225
226+ export const DisabledCloseButton : Story = {
227+ render : Template ,
228+ args : {
229+ title : "Disabled Close Button Modal" ,
230+ children : < p > This Modal has a disabled close button.</ p > ,
231+ disableCloseButton : true ,
232+ } ,
233+ }
234+
226235export const Login : Story = {
227236 render : Template ,
228237 args : {
Original file line number Diff line number Diff line change @@ -382,28 +382,21 @@ describe("Modal", () => {
382382 expect ( cancelButton ) . toBeInTheDocument ( )
383383 expect ( cancelButton ) . toHaveAttribute ( "disabled" )
384384
385+ expect ( screen . getByRole ( "button" , { name : "close" } ) ) . toBeDisabled ( )
386+
385387 await waitFor ( ( ) => userEvent . click ( cancelButton ) )
386388 expect ( mockOnCancel ) . not . toHaveBeenCalled ( )
387389 } )
388390
389- test ( "renders a modal without a close button in the header when disableCloseButton is true" , async ( ) => {
391+ test ( "renders a modal with no disabled close button if disableCloseButton is true" , async ( ) => {
390392 await waitFor ( ( ) =>
391393 render (
392394 < PortalProvider >
393395 < Modal open onCancel = { mockOnCancel } disableCloseButton />
394396 </ PortalProvider >
395397 )
396398 )
397-
398- expect ( screen . getByRole ( "dialog" ) ) . toBeInTheDocument ( )
399-
400- // Ensure header close button doesn't exist
401- const closeButton = screen . queryByRole ( "button" , { name : "close" } )
402- expect ( closeButton ) . not . toBeInTheDocument ( )
403-
404- // Confirm that the modal remains open and the cancel handler was not called
405399 expect ( screen . getByRole ( "dialog" ) ) . toBeInTheDocument ( )
406- await userEvent . click ( closeButton ! )
407- expect ( mockOnCancel ) . not . toHaveBeenCalled ( )
400+ expect ( screen . getByRole ( "button" , { name : "close" } ) ) . toBeDisabled ( )
408401 } )
409402} )
You can’t perform that action at this time.
0 commit comments