Skip to content

Commit 90b501d

Browse files
authored
Merge pull request ItalyPaleAle#30 from TorstenDittmann/master
fixed bug when element is destroyed Fixes ItalyPaleAle#28
2 parents fe46fcd + 04f52cd commit 90b501d

File tree

3 files changed

+44
-1
lines changed

3 files changed

+44
-1
lines changed

active.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export default function active(node, path, className) {
7070
return {
7171
// When the element is destroyed, remove it from the list
7272
destroy() {
73-
nodes = nodes.splice(nodes.indexOf(el), 1)
73+
nodes.splice(nodes.indexOf(el), 1)
7474
}
7575
}
7676
}

example/src/App.svelte

+26
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,17 @@
2828
<!-- Show the router -->
2929
<Router {routes}/>
3030

31+
<h2>Dynamic links</h2>
32+
<ul class="navigation-dynamic-links">
33+
{#each dynamicLinks as dl (dl.id)}
34+
<li>
35+
<a id="dynamic-link-{dl.id}" href={dl.link} use:link use:active>Dynamic Link {dl.id}</a>
36+
-
37+
<i id="delete-link-{dl.id}" on:click={() => dynamicLinks = dynamicLinks.filter(e => e.id != dl.id)}>delete link</i>
38+
</li>
39+
{/each}
40+
</ul>
41+
3142
<style>
3243
/* Style for "active" links; need to mark this :global because the router adds the class directly */
3344
:global(a.active) {
@@ -48,4 +59,19 @@ import active from '../../active'
4859
4960
// Import the list of routes
5061
import routes from './routes'
62+
63+
let dynamicLinks = [
64+
{
65+
id: 1,
66+
link: '/hello/dynamic-link-1'
67+
},
68+
{
69+
id: 2,
70+
link: '/hello/dynamic-link-2'
71+
},
72+
{
73+
id: 3,
74+
link: '/hello/dynamic-link-3'
75+
}
76+
]
5177
</script>

test/02-active-action.test.js

+17
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,23 @@ describe('use:active action', function() {
4646
})
4747
})
4848

49+
it('active dynamic links', (browser) => {
50+
51+
// Check if elements are still tagged active after one is removed
52+
browser
53+
.url('http://localhost:5000/#/')
54+
.waitForElementVisible('ul.navigation-dynamic-links')
55+
// delete second link
56+
.click('i[id=delete-link-2]')
57+
.pause(1000)
58+
// click second link
59+
.click('a[id=dynamic-link-1]')
60+
.pause(1000)
61+
//check for active class on link-1
62+
.expect.element('a[id=dynamic-link-1]').to.have.attribute('class').which.contains('active')
63+
browser.end()
64+
})
65+
4966
it('navigating pages', (browser) => {
5067
browser
5168
.url('http://localhost:5000/#/hello/world')

0 commit comments

Comments
 (0)