Skip to content

Commit

Permalink
fix(outlook.com): fix positioning of underlines on outlook.com
Browse files Browse the repository at this point in the history
This fixes an issue with the underlines in emails on outlook.com appearing above the words.
The root cause was that outlook.com changed the DOM structure, adding padding to the contenteditable div that was the normal parent
as well as adding another containing div with no `position` attribute to the hierarchy.
The new intermediate was being used as the parent for calculating coords but the coords of the words were relative to the contenteditable div.
Using offsetParent instead of parentNode skips the intermediate div and makes things line up properly.

fixes #134
  • Loading branch information
sbrudz committed Sep 29, 2021
1 parent ca7fcc1 commit cdbff91
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,10 @@
"^react$": "preact/compat",
"^react-dom/test-utils$": "preact/test-utils",
"^react-dom$": "preact/compat"
}
},
"setupFilesAfterEnv": [
"<rootDir>/spec/setupTests.js"
]
},
"snapshotSerializers": [
"preact-render-spy/snapshot"
Expand Down
7 changes: 7 additions & 0 deletions spec/setupTests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Work-around for jsdom not supporting offsetParent
// https://github.com/jsdom/jsdom/issues/1261
Object.defineProperty(HTMLElement.prototype, 'offsetParent', {
get() {
return this.parentNode;
},
});
4 changes: 2 additions & 2 deletions src/components/JustNotSorry.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ class JustNotSorry extends Component {
: findRanges(email, patterns);

this.setState(({ parentNode }) =>
parentNode.id !== email.parentNode.id
? { parentNode: email.parentNode, warnings: newWarnings }
parentNode.id !== email.offsetParent.id
? { parentNode: email.offsetParent, warnings: newWarnings }
: { parentNode, warnings: newWarnings }
);
}
Expand Down

0 comments on commit cdbff91

Please sign in to comment.