Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add posibility to open link in a new tab #36

Merged
merged 1 commit into from
May 16, 2018
Merged
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ You can also pass in the message into a named slot. This way you can for example
| buttonText | 'Got It!' | String | 🔘 Well, its the button text
| buttonLink | | String\|Object | Link to more infos. Simple href or a [vue-router](https://github.com/vuejs/vue-router) Location object
| buttonLinkText | 'More info' | String | Label of link button
| buttonLinkNewTab | false | Boolean | If true, it opens the link in a new tab/window (href)
| buttonClass | 'Cookie__button' | String | Custom class name for buttons
| message | 'This website uses cookies to ensure you get the best experience on our website.' | String | Your message in the content area
| theme | 'base' | String | Selected theme. You can also create a custom one
Expand Down
9 changes: 8 additions & 1 deletion src/components/CookieLaw.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<slot name="message">{{ message }}</slot>
</div>
<div class="Cookie__buttons">
<a :href="buttonLink" v-if="externalButtonLink" :class="buttonClass">{{ buttonLinkText }}</a>
<a :target="target" :href="buttonLink" v-if="externalButtonLink" :class="buttonClass">{{ buttonLinkText }}</a>
<router-link :to="buttonLink" v-if="internalButtonLink" :class="buttonClass">{{ buttonLinkText }}</router-link>
<div :class="buttonClass" @click="accept">{{ buttonText }}</div>
</div>
Expand All @@ -29,6 +29,10 @@
type: String,
default: 'More info'
},
buttonLinkNewTab: {
type: Boolean,
default: false
},
message: {
type: String,
default: 'This website uses cookies to ensure you get the best experience on our website.'
Expand Down Expand Up @@ -80,6 +84,9 @@
},
internalButtonLink () {
return typeof this.buttonLink === 'object' && this.buttonLink != null && Object.keys(this.buttonLink).length
},
target () {
return this.buttonLinkNewTab ? '_blank' : '_self'
}
},
created () {
Expand Down
6 changes: 6 additions & 0 deletions test/unit/specs/CookieLaw.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ describe('CookieLaw.vue', () => {

localStorage.clear()
})
it('should have an <a> tag with target="_blank" if buttonLinkNewTab prop is true', () => {
const Constructor = Vue.extend(CookieLaw)
const vm = new Constructor({ propsData: { buttonLink: 'link', buttonLinkNewTab: true } }).$mount()
expect(vm.$el.querySelector('.Cookie__buttons > a').getAttribute('target'))
.to.equal('_blank')
})
// it('should set a cookie when localstorage is not available', () => {
// const Constructor = Vue.extend(CookieLaw)
// const vm = new Constructor().$mount()
Expand Down