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

Optimizing displayCheck: "full" #604

Merged
merged 3 commits into from
Mar 5, 2022

Conversation

DaviDevMod
Copy link
Contributor

@DaviDevMod DaviDevMod commented Mar 2, 2022

Optimized displayCheck: "full" by replacing this DOM traversal (executed on every potential focusable element) with the following statement:

return !node.getClientRects().length;

which is a more general check for whether an elements has display boxes. display: "none" is only a special case of !node.getClientRects().length.

Another case of elements with no display boxes would be elements with display: "contents". And (since this case wasn't previosly handled) tests have been added to cover this possibility.

Fixes #592

PR Checklist

Please leave this checklist in your PR.

  • Source changes maintain stated browser compatibility.
  • Issue being fixed is referenced.
  • Unit test coverage added/updated.
  • E2E test coverage added/updated.
  • Typings added/updated.
  • Changes do not break SSR:
    • Careful to test typeof document/window !== 'undefined' before using it in code that gets executed on load.
  • README updated (API changes, instructions, etc.).
  • Changes to dependencies explained.
  • Changeset added (run yarn changeset locally to add one, and follow the prompts).
    • EXCEPTION: A Changeset is not required if the change does not affect any of the source files that produce the package bundle. For example, demo changes, tooling changes, test updates, or a new dev-only dependency to run tests more efficiently should not have a Changeset since it will not affect package consumers.

@changeset-bot
Copy link

changeset-bot bot commented Mar 2, 2022

🦋 Changeset detected

Latest commit: fe27341

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
tabbable Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@codecov
Copy link

codecov bot commented Mar 2, 2022

Codecov Report

Merging #604 (7594e8f) into master (38b2f51) will decrease coverage by 0.05%.
The diff coverage is 100.00%.

❗ Current head 7594e8f differs from pull request most recent head fe27341. Consider uploading reports for the commit fe27341 to get more accurate results

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #604      +/-   ##
==========================================
- Coverage   97.22%   97.16%   -0.06%     
==========================================
  Files           1        1              
  Lines         144      141       -3     
  Branches       60       59       -1     
==========================================
- Hits          140      137       -3     
  Misses          4        4              
Impacted Files Coverage Δ
src/index.js 97.16% <100.00%> (-0.06%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 38b2f51...fe27341. Read the comment docs.

@DaviDevMod DaviDevMod changed the title Perf/display check full Optimizing displayCheck: "full" Mar 2, 2022
@DaviDevMod
Copy link
Contributor Author

DaviDevMod commented Mar 2, 2022

Not sure why the coverage has decreased. It may be that there are cases other than the display: "full" and display: "contents" ones, in which an element has no display boxes. And we have no tests for these additional cases.

@stefcameron
Copy link
Member

Not sure why the coverage has decreased. It may be that there are cases other than the display: "full" and display: "contents" ones, in which an element has no display boxes. And we have no tests for these additional cases.

I think the reason it has decreased is because technically, there were 4 lines that were covered before, and now there is only one:

image

But this is a blind comparison between before (say 300 lines total) and now (say 296 lines total), so technically, coverage has decreased by a fraction, but that's not because there are lines that were covered before and aren't now. It's because there are just less lines covered.

Hopefully that makes sense. Not something to worry about in this case.

Copy link
Member

@stefcameron stefcameron left a comment

Choose a reason for hiding this comment

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

This looks good, thank you!

@DaviDevMod
Copy link
Contributor Author

I think the reason it has decreased is because technically, there were 4 lines that were covered before, and now there is only one

Oh so that's how the coverage is calculated.
I don't know what kind of smarter calculation I was expecting. But yes, recognising which lines are covered by tests, is already pretty clever.

Thank you for the clarification!

@stefcameron stefcameron merged commit dd6d0ec into focus-trap:master Mar 5, 2022
@stefcameron
Copy link
Member

@all-contributors add @DaviDevMod for code, test

@allcontributors
Copy link
Contributor

@stefcameron

I've put up a pull request to add @DaviDevMod! 🎉

stefcameron added a commit that referenced this pull request Mar 6, 2022
stefcameron added a commit that referenced this pull request Mar 6, 2022
TODO:
- fix the one failing test (see bunch of DEBUG comments)
- optimize/clarify getCandidate... loop (see DEBUG comment)
- clarify docs about getShadowRoot() === true that's meant for non-zero test
stefcameron added a commit that referenced this pull request Mar 11, 2022
TODO: Add support for `getShadowRoot: true` instead of function.
stefcameron added a commit that referenced this pull request Mar 11, 2022
TODO: Add support for `getShadowRoot: true` instead of function.
stefcameron added a commit that referenced this pull request Mar 11, 2022
stefcameron added a commit that referenced this pull request Mar 17, 2022
stefcameron added a commit that referenced this pull request Apr 16, 2022
stefcameron added a commit that referenced this pull request Apr 20, 2022
stefcameron added a commit that referenced this pull request Apr 20, 2022
* chore(dev): declarative shadow root test fixtures

- new development shadow-root-utils
- refactor setupFixture to render using new utils
- refactor current shadow dom tests to use declarative root
- debug page renders shadow root fixtures correctly

* feat: separate radio light/shadow dom groups

* feat: detect display across shadow boundaries

* feat: scan through shadow boundary

- iterate down dom instead of query when getShadowRoot is provided
- new candidate list/tree format with scoped lists

* chore(types): added getShadowDom to types

* fix: type of getShadowRoot option

* test: add test to locate tabbable host

* feat: slot elements are not focusable/tabbable

* chore: added some jsdocs

* refactor: modernize syntax

- as requested in PR

* Prepare for 5.3.0-beta.0

* 5.3.0-beta.0

* Adjusting code after #604 and comments

* Disable shadow DOM for isFocusable/isTabbable if getShadowRoot not given

This goes along with disabling it for `tabbable()` and `focusable()`
when the option isn't given.

* Clarify getShadowRoot must be set to enable shadow DOM support

* Add support for `getShadowRoot: true`

Note this is the equivalent of `getShadowRoot: () => false` which
simply enables shadow DOM support for all open shadows.

* Prepare for v5.3.0-beta.1

* 5.3.0-beta.1

* Add prepublishOnly script for manual publishing

* fix(index.js) The tabIndex of audio, video and details was left to the default if set to some NaN (#610)

* fix(index.js) The tabIndex of contentEditable elements was assumed to be zero in any case, not only in the case it was not specifically set.

* Simplified and optimized 'getTabIndex'.

* Made better use of short-circuit evaluation in 'isNodeMatchingSelectorTabbable', reducing the chances to call the computationally expensive 'isNodeMatchingSelectorFocusable'.

* (Re)Added 'isScope' parameter to 'getTabIndex'. This parameter wasn't present in the master branch, so I lost it in the rebase process.

* Added tests for a `contenteditable` with negative tab index.

* Fixed bug, now the getTabIndex can return 0 not only when the tabindex is not explicitly set, but also when is set to a value that gives NaN when parsed as integer (which would have been resulted in the default browser tabIndex, as if the tabindex wasn't set at all). Also added test for the case an element has a tab index that can't be turned into an integer.

* Added changeset, added entry in CHANGELOG.md and wrote more tests.

* Be consistent with asterisks

* Sync package.json/yarn.lock with beta-530 base branch

Co-authored-by: Stefan Cameron <stefan@stefcameron.com>

* [#632] Add test for radios in a form (#638)

Can't repro the issue, but might as well keep the test since we
seem to like fieldsets but not forms for some reason.

* Add changeset for shadow root support

Co-authored-by: Ido Rosenthal <idoros@gmail.com>
Co-authored-by: DaviDevMod <98312056+DaviDevMod@users.noreply.github.com>
@craigkovatch
Copy link

This broke ~all of our unit tests which touch code that uses tabbable, opening an issue...

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.

Optimizing displayCheck: 'full'
3 participants