Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -105,7 +105,7 @@
let onChange = jasmine.createSpy();
mount(
<div>
<div dangerouslySetInnerHTML={{ __html: `<a href="#foo">foo</a>` }} />

Check warning on line 108 in test/dom.test.js

View workflow job for this annotation

GitHub Actions / build_test

Dangerous property 'dangerouslySetInnerHTML' found
<Router onChange={onChange}>
<div default />
</Router>
Expand All @@ -118,6 +118,25 @@
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
Loading