Keep role="dialog"
after closing modal/offcanvas if already in the markup
#39941
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR is the result of a discussion that happened in https://github.com/orgs/twbs/discussions/39933.
TL;DR: if a
role="dialog"
is in the modal/offcanvas markup, our JavaScript will remove it when closing the element. The idea of this PR is to integrate a modification or our JavaScript behavior to keep this role if it is present in the markup.There was a scenario to handle that, which was to put back the
role="dialog"
in the markup and doing nothing in the JavaScript by expecting users to correctly use it. But I like the enforcement rule that is present right as a modal/offcanvas can't be used without JavaScript right now anyway.So I preferred the approach in this PR that doesn't change anything in the current behavior, but allows some flexibility for folks still wanting to add the
role="dialog"
in the markup for any reason.Please note that the documentation is not modified as it's still accurate (source: https://getbootstrap.com/docs/5.3/components/modal/#accessibility):
First, dear reviewers, what do you think of this approach, in terms of JavaScript and/or accessibility? As mentioned in the GH discussion, I deducted information in the history, but maybe it's wrong, and you have more history to share.
If we agree to go this way, is handling only
role="dialog"
this way enough, or do you think we also should do the same thing foraria-modal
which follows the same logic?While
Type of changes
Checklist
npm run lint
)Live previews
Related GH discussion