Skip to content

Commit

Permalink
[fix] unselect before navigation (#2755)
Browse files Browse the repository at this point in the history
* fixes #1054. unselect all before navigating to another page.

* fixes #1054. unselect all before navigating to another page.

* #1054. removed unselect_all function. moved unselect logic to the renderer.js:update method. removed waitForTimeout calls from test.

* #1054. reverted indents

Co-authored-by: Senior <senior@dev.lan>
  • Loading branch information
treenoder and Senior committed Nov 11, 2021
1 parent 094bfc5 commit 2a97b03
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/seven-avocados-hug.md
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

remove all selection before navigating to the next page
2 changes: 2 additions & 0 deletions packages/kit/src/runtime/client/renderer.js
Expand Up @@ -275,6 +275,8 @@ export class Renderer {
this._init(navigation_result);
}

getSelection()?.removeAllRanges();

if (!opts) {
await 0;
} else {
Expand Down
@@ -0,0 +1,3 @@
<nav><a href="/selection/a">a</a> <a href="/selection/b">b</a></nav>

<slot />
32 changes: 32 additions & 0 deletions packages/kit/test/apps/basics/src/routes/selection/_tests.js
@@ -0,0 +1,32 @@
import * as assert from 'uvu/assert';

/** @type {import('test').TestMaker} */
export default function (test) {
test('reset selection', '/selection/a', async ({ page, clicknav }) => {
assert.equal(
await page.evaluate(() => {
const range = document.createRange();
range.selectNodeContents(document.body);
const selection = getSelection();
if (selection) {
selection.removeAllRanges();
selection.addRange(range);
return selection.rangeCount;
}
return 0;
}),
1
);
await clicknav('[href="/selection/b"]');
assert.equal(
await page.evaluate(() => {
const selection = getSelection();
if (selection) {
return selection.rangeCount;
}
return 1;
}),
0
);
});
}
5 changes: 5 additions & 0 deletions packages/kit/test/apps/basics/src/routes/selection/a.svelte
@@ -0,0 +1,5 @@
<svelte:head>
<title>a</title>
</svelte:head>

<h1>a</h1>
5 changes: 5 additions & 0 deletions packages/kit/test/apps/basics/src/routes/selection/b.svelte
@@ -0,0 +1,5 @@
<svelte:head>
<title>b</title>
</svelte:head>

<h1>b</h1>

0 comments on commit 2a97b03

Please sign in to comment.