Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fixed] element with display 'contents' is visible and is tabbable. #906

Closed

Conversation

diasbruno
Copy link
Collaborator

@diasbruno diasbruno commented Oct 11, 2021

Fixes #905.

Changes proposed:

  • element with display 'contents' is visible and is tabbable.

Upgrade Path (for changed or removed APIs):

  • None

Acceptance Checklist:

  • The commit message follows the guidelines in CONTRIBUTING.md.
  • Documentation (README.md) and examples have been updated as needed.
  • If this is a code change, a spec testing the functionality has been added.
  • If the commit message has [changed] or [removed], there is an upgrade path above.

@diasbruno
Copy link
Collaborator Author

@aloker Thanks for the patch...can you have a look on this?

src/helpers/tabbable.js Outdated Show resolved Hide resolved
Copy link

@aloker aloker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just a few comments

Comment on lines +18 to +23
function hasElementOverflow(element, style) {
return style.getPropertyValue("overflow") !== "visible" ||
// if 'overflow: visible' set, check if there is actually any overflow
(element.scrollWidth <= 0 && element.scrollHeight <= 0);
}

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't the naming backwards? If the function returns true, the element does not overflow (either because its content is clipped or its content is actually 0x0 in size)

Comment on lines +33 to +36
const displayValue = style.getPropertyValue("display");
return displayValue !== DISPLAY_CONTENTS && (zeroSize
? hasElementOverflow(element, style)
: displayValue === DISPLAY_NONE);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally, I'd go with

return zeroSize
      ? displayValue !== DISPLAY_CONTENTS && hasElementOverflow(element, style)
      : displayValue === DISPLAY_NONE;

but that's mostly a matter of taste. Either way works.

@diasbruno
Copy link
Collaborator Author

Nice. I'll just add a test and we are good to go...

@galexandrade
Copy link
Contributor

@diasbruno how can we help to get this PR out. We use the react-modal as a base for our Modal component this fix is what we need to unblock us for fixing the tab issue.

@diasbruno
Copy link
Collaborator Author

@galexandrade That's great! I believe the only thing missing here is to add a tests. You can take this PR and improve it.

@galexandrade
Copy link
Contributor

galexandrade commented Oct 12, 2022

@diasbruno @aloker I checked out the branch and tried to add some tests to cover the scenario but since the problem only happens on Safari, it is hard to simulate the same scenario on ReactDOM.

This is the problem I would like to have fixed here:
If there is an element that has the display: contents style applied, on Safari, it won't tab through the elements. The reason I am using display: contents is that I want my form tag to wrap the modal content and footer so the modal buttons are part of the form. However, it is messing with the modal layout so, I use the display: contents so the browser will "ignore" that form tag when painting the screen.

Screen.Recording.2022-10-12.at.3.06.32.PM.mov

You can check this example in Safari and Chrome.

That works fine, except for Safari where it won't tab through the elements. With this PR, the issue is fixed.

I'd like to offer help to move this PR forward. Please, how can I help to get this PR merged? 🙏

@diasbruno
Copy link
Collaborator Author

@galexandrade There are a few comments on the PR. You can take this patch and improve on it.

@diasbruno
Copy link
Collaborator Author

#969

@diasbruno diasbruno closed this Oct 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Tabbing not possible inside display: contents
3 participants