Skip to content

Commit

Permalink
Don't try to intercept links inside contenteditable
Browse files Browse the repository at this point in the history
  • Loading branch information
vpzomtrrfrt committed Jul 29, 2024
1 parent ee0ba49 commit 374deb6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ function delegateLinkHandler(e) {

let t = e.target;
do {
if (t.localName === 'a' && t.getAttribute('href')) {
if (t.localName === 'a' && t.getAttribute('href') && !t.isContentEditable) {
if (t.hasAttribute('data-native') || t.hasAttribute('native')) return;
// if link is handled by the router, prevent browser defaults
if (routeFromLink(t)) {
Expand Down
19 changes: 19 additions & 0 deletions test/dom.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,25 @@ describe('dom', () => {
expect(onChange).not.toHaveBeenCalled();
expect(location.href).toContain('#foo');
});

it('should not intercept links inside contenteditable', () => {
let onChange = jasmine.createSpy();
mount(
<div>
<div contenteditable>
<a href="#foo">foo</a>
</div>
<Router onChange={onChange}>
<div default />
</Router>
</div>
);
onChange.calls.reset();
act(() => {
$('a').click();
});
expect(onChange).not.toHaveBeenCalled();
});
});

describe('Router', () => {
Expand Down

0 comments on commit 374deb6

Please sign in to comment.