From 93c7568ff3c2f9f2209992916eb2e3d2335eb341 Mon Sep 17 00:00:00 2001 From: Troy Morehouse Date: Fri, 29 Mar 2019 00:56:17 -0300 Subject: [PATCH 1/5] Update link.js --- src/components/link/link.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/components/link/link.js b/src/components/link/link.js index f0acb4bf39f..97b68e36376 100644 --- a/src/components/link/link.js +++ b/src/components/link/link.js @@ -114,6 +114,7 @@ function clickHandlerFactory({ disabled, tag, href, suppliedHandler, parent }) { // Stop event from bubbling up. evt.stopPropagation() // Kill the event loop attached to this specific EventTarget. + // Needed to prevent vue-router for doing its thing evt.stopImmediatePropagation() } else { if (isRouterLink(tag) && evt.target.__vue__) { @@ -121,9 +122,12 @@ function clickHandlerFactory({ disabled, tag, href, suppliedHandler, parent }) { // add in an $emit('click', evt) on it's vue instance evt.target.__vue__.$emit('click', evt) } - if (typeof suppliedHandler === 'function') { - suppliedHandler(...arguments) - } + // Call the suppliedHanlder(s), if any provided + concat(suppliedHandler) + .filter(h => typeof h === 'function') + .forEach(handler => { + handler(...arguments) + }) parent.$root.$emit('clicked::link', evt) } From 98cb9ec9229f2a0c691c98797073124440ff0c05 Mon Sep 17 00:00:00 2001 From: Troy Morehouse Date: Fri, 29 Mar 2019 01:05:13 -0300 Subject: [PATCH 2/5] Update link.html --- src/components/link/fixtures/link.html | 1 + 1 file changed, 1 insertion(+) diff --git a/src/components/link/fixtures/link.html b/src/components/link/fixtures/link.html index 22c223ad357..ffb06b946f6 100644 --- a/src/components/link/fixtures/link.html +++ b/src/components/link/fixtures/link.html @@ -22,6 +22,7 @@ disabled>Link Link Date: Fri, 29 Mar 2019 01:07:23 -0300 Subject: [PATCH 3/5] Update link.js --- src/components/link/fixtures/link.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/components/link/fixtures/link.js b/src/components/link/fixtures/link.js index 4cebc42519c..569ea9c0591 100644 --- a/src/components/link/fixtures/link.js +++ b/src/components/link/fixtures/link.js @@ -1,5 +1,6 @@ const clickSpy = jest.fn() const disabledClickSpy = jest.fn() +const btnHrefClick = jest.fn() window.app = new Vue({ el: '#app', @@ -16,6 +17,9 @@ window.app = new Vue({ handleDisabledClick(e) { this.testData.disabled_event = e disabledClickSpy.apply(this, arguments) + }, + handleBtnHrefClick(e) { + btnHrefClick.apply(this, arguments) } } }) From 748449cf916530591b9c36a9fa938794205c32e5 Mon Sep 17 00:00:00 2001 From: Troy Morehouse Date: Fri, 29 Mar 2019 01:09:39 -0300 Subject: [PATCH 4/5] Update link.js --- src/components/link/fixtures/link.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/components/link/fixtures/link.js b/src/components/link/fixtures/link.js index 569ea9c0591..e869c3efe9a 100644 --- a/src/components/link/fixtures/link.js +++ b/src/components/link/fixtures/link.js @@ -8,6 +8,7 @@ window.app = new Vue({ href: 'https://bootstrap-vue.github.io/', clickSpy, disabledClickSpy, + btnHrefClick, testData: {} }, methods: { From bc83319f5411f5883c443eeace3229699b28d7fc Mon Sep 17 00:00:00 2001 From: Troy Morehouse Date: Fri, 29 Mar 2019 01:11:09 -0300 Subject: [PATCH 5/5] Update link.spec.js --- src/components/link/link.spec.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/components/link/link.spec.js b/src/components/link/link.spec.js index 4f55d7b6976..ba47d7adeb2 100644 --- a/src/components/link/link.spec.js +++ b/src/components/link/link.spec.js @@ -90,6 +90,13 @@ describe('link', () => { expect(firstCallArguments[0]).toBeInstanceOf(Event) }) + it('btn with href should invoke click handler when clicked on', async () => { + // https://github.com/bootstrap-vue/bootstrap-vue/issues/2938 + const { app } = window + app.$refs.href.click() + expect(app.btnHrefClick).toHaveBeenCalled() + }) + it("should emit 'clicked::link' on $root when clicked on", async () => { const { app } = window const spy = jest.fn()