diff --git a/packages/@ember/-internals/glimmer/lib/components/link-to.ts b/packages/@ember/-internals/glimmer/lib/components/link-to.ts index 40ee661d959..a139ba18c80 100644 --- a/packages/@ember/-internals/glimmer/lib/components/link-to.ts +++ b/packages/@ember/-internals/glimmer/lib/components/link-to.ts @@ -138,7 +138,7 @@ class LinkTo extends InternalComponent implements DeprecatingInternalComponent { return; } - let element = event.target; + let element = event.currentTarget; assert('[BUG] must be an element', element instanceof HTMLAnchorElement); let isSelf = element.target === '' || element.target === '_self'; diff --git a/packages/@ember/-internals/glimmer/tests/integration/components/link-to/routing-angle-test.js b/packages/@ember/-internals/glimmer/tests/integration/components/link-to/routing-angle-test.js index 60ac6577dac..fa7e4c22561 100644 --- a/packages/@ember/-internals/glimmer/tests/integration/components/link-to/routing-angle-test.js +++ b/packages/@ember/-internals/glimmer/tests/integration/components/link-to/routing-angle-test.js @@ -92,6 +92,47 @@ moduleFor( ); } + async ['@test [GH#19546] it navigates into the named route when containing other elements']( + assert + ) { + this.addTemplate( + 'about', + ` +

About

+ Home + Self + ` + ); + + await this.visit('/about'); + + assert.equal(this.$('h3.about').length, 1, 'The about template was rendered'); + assert.equal( + this.$('#self-link.active').length, + 1, + 'The self-link was rendered with active class' + ); + assert.equal( + this.$('#home-link:not(.active)').length, + 1, + 'The other link was rendered without active class' + ); + + await this.click('#inside'); + + assert.equal(this.$('h3.home').length, 1, 'The home template was rendered'); + assert.equal( + this.$('#self-link.active').length, + 1, + 'The self-link was rendered with active class' + ); + assert.equal( + this.$('#about-link:not(.active)').length, + 1, + 'The other link was rendered without active class' + ); + } + async [`@test [DEPRECATED] it doesn't add an href when the tagName isn't 'a'`](assert) { this.addTemplate( 'index', diff --git a/packages/@ember/-internals/glimmer/tests/integration/components/link-to/routing-curly-test.js b/packages/@ember/-internals/glimmer/tests/integration/components/link-to/routing-curly-test.js index 138a66f7068..2ecf5ae4cf0 100644 --- a/packages/@ember/-internals/glimmer/tests/integration/components/link-to/routing-curly-test.js +++ b/packages/@ember/-internals/glimmer/tests/integration/components/link-to/routing-curly-test.js @@ -92,6 +92,47 @@ moduleFor( ); } + async ['@test [GH#19546] it navigates into the named route when containing other elements']( + assert + ) { + this.addTemplate( + 'about', + ` +

About

+ + + ` + ); + + await this.visit('/about'); + + assert.equal(this.$('h3.about').length, 1, 'The about template was rendered'); + assert.equal( + this.$('#self-link > a.active').length, + 1, + 'The self-link was rendered with active class' + ); + assert.equal( + this.$('#home-link > a:not(.active)').length, + 1, + 'The other link was rendered without active class' + ); + + await this.click('#inside'); + + assert.equal(this.$('h3.home').length, 1, 'The home template was rendered'); + assert.equal( + this.$('#self-link > a.active').length, + 1, + 'The self-link was rendered with active class' + ); + assert.equal( + this.$('#about-link > a:not(.active)').length, + 1, + 'The other link was rendered without active class' + ); + } + async [`@test [DEPRECATED] it doesn't add an href when the tagName isn't 'a'`](assert) { this.addTemplate( 'index',