Remove unnecessary tabindex attributes from offcanvas docs examples #41524
+10
−10
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
Adjusts code examples in the offcanvas component's documentation in order to avoid potential bugs in Safari due to its unusual focus handling.
Motivation & Context
Having copied the code examples of the offcanvas component in an implementation for a website, I was surprised to find the presence of the
tabindex
attribute on the wrapping<div>
caused unexpected behaviour in Safari. I had an event listener for thefocusin
event on an<a>
element within the offcanvas component. When clicking that link element, Safari sets the event target to the<div>
, unlike Chrome which sets it to the<a>
. (Safari has a history of unusual focus handling!) This meant my event listener acted on the wrong element, causing a bug report from my client.In an early commit of the original Offcanvas component's PR (#29017), the
tabindex
attribute on the wrapping<div>
was being manually adjusted in javascript. But that no longer happens (e.g. since #33865 changed the way keyboard navigation & focus was handled anyway), yet the initialtabindex
attribute remained in the code examples in its docs. Given that the wrapping<div>
element wouldn't be tabbable without thetabindex
attribute anyway, I believe the attribute is unnecessary. I suggest we remove it to save other developers who copy the examples from similar headaches!Type of changes
Checklist
npm run lint
)Live previews
Related issues