Skip to content

Bug - [Modal] - [ModalBoxcontent has the same id as the Modal itself] #9399

@jelly

Description

@jelly

Describe the problem

When providing a description to a Modal and setting the id property, the DOM will have two div's with an identical id.

How do you reproduce the problem?
A codesandbox

Or basically:

     <Modal
        title="Basic modal"
        id="basic-modal"
        isOpen={isModalOpen}
        onClose={handleModalToggle}
        description={<p>description</p>}
        actions={[
          <Button key="confirm" variant="primary" onClick={handleModalToggle}>
            Confirm
          </Button>,
          <Button key="cancel" variant="link" onClick={handleModalToggle}>
            Cancel
          </Button>
        ]}
        ouiaId="BasicModal"
      >

Expected behavior
There should only be one id in the DOM.

Is this issue blocking you?

Not at the moment.

Screenshots

image

What is your environment?

Any.

What is your product and what release date are you targeting?

Cockpit.

Any other information?

Looking at the code, it seems to be caused by the line below, as if there is no description, the id descriptorId instead of the passed id via props. (As the props of Modal` are passed down everywhere).

Actually no, it should not remove the !description check, as otherwise you'd get a duplicate id (again).

  const modalBody = hasNoBodyWrapper ? (
    children
  ) : (
    <ModalBoxBody
      aria-label={bodyAriaLabel}
      role={bodyAriaRole || defaultModalBodyAriaRole}
      {...props}
      {...(!description && !ariaDescribedby && { id: descriptorId })}
    >
      {children}
    </ModalBoxBody>
  );

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

Status

Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions