-
Notifications
You must be signed in to change notification settings - Fork 204
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
Find suitable z-index for the adder #2585
Conversation
I have yet to figure out exactly why using diff --git a/src/annotator/test/adder-test.js b/src/annotator/test/adder-test.js
index 5ee39cc98..7f0d54cd5 100644
--- a/src/annotator/test/adder-test.js
+++ b/src/annotator/test/adder-test.js
@@ -32,6 +32,17 @@ function revertOffsetElement(el) {
}
describe('findHighestZindex', () => {
+ let container;
+
+ beforeEach(() => {
+ container = document.createElement('div');
+ document.body.appendChild(container);
+ });
+
+ afterEach(() => {
+ container.remove();
+ });
+
it('returns zero z-index (default value) if no element is passed)', () => {
assert.strictEqual(findHighestZindex(undefined), 0);
assert.strictEqual(findHighestZindex(null), 0);
@@ -44,7 +55,7 @@ describe('findHighestZindex', () => {
<div className="child1" style={{ zIndex: 5 }} />
<div className="child2" style={{ zIndex: 15 }} />
</div>,
- { attachTo: document.body }
+ { attachTo: container }
);
const parent = wrapper.find('.parent').getDOMNode(); The reason for the above pattern of putting the cleanup in an |
fc885b1
to
60793af
Compare
6ddbe36
to
3305dc5
Compare
Codecov Report
@@ Coverage Diff @@
## master #2585 +/- ##
=======================================
Coverage 97.28% 97.29%
=======================================
Files 197 197
Lines 7300 7311 +11
Branches 1615 1616 +1
=======================================
+ Hits 7102 7113 +11
Misses 198 198
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi Eduardo,
I had another look over this. I suggested some minor changes but I also noted a scenario which was highlighted by the test page that you added that might require re-thinking the approach a little.
da0d3c9
to
c46b549
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made a more robust and simple implementation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi Eduardo,
This looks nice and simple. We'll need a fallback for browsers that don't support document.elementsFromPoint
since it requires, for example, quite recent versions of Firefox and Safari (>= 12). Returning a static value in that case would be fine.
Can you also add a few tests. These can mock document.elementsFromPoint
to make things easier.
@robertknight, I fully agree about (1) returning a default static value (as we were doing previously) in case of |
ef8813a
to
228134a
Compare
On the second commit I provided a fallback option in case |
228134a
to
6acf985
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi Eduardo,
This looks good. I think the comment for _findZindex
could be improved though to explain why it is doing what it does. I believe the comments about Opera on MDN are out of date, although the value of 2^15 is a perfectly reasonable fallback value.
In tests we generally avoid testing private methods, although this may occasionally be OK if it is unlikely to get in the way of refactoring the code in future. I suggested a way that you could test the z-index without calling _findZindex
directly.
6acf985
to
e9e5ce8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi Eduardo - This looks good. Can you update the description of the describe(...
block in the test following the change to use only public API of the class. Also, I would suggest to remove the reference to MDN and Opera because that information is long out of date. 2^15 is effectively just "an arbitrary large value that will work almost all web pages". Other than these two small items, this is good to merge.
e9e5ce8
to
d5f7443
Compare
This PR incorporates a solution to programatically find a z-index for the adder. Before this, the z-index of the adder was a hard-coded value, which didn't work for some websites (see for example #2009).
We evaluated the option of finding the greatest z-index in the page. However, this takes too long for heavy pages.
This solution in this PR is not bulletproof, but probably works for the most part of the websites. It uses the greatest z-index of five nearby elements: left-top, left-bottom, middle-center, right-top, right-bottom elements around the adder.
Resolves #2009