carbon-components-svelte/src/Link/Link.svelte
Eric Liu 4b7d254560 feat(link): set rel to "noopener noreferrer" if target is "_blank"
Protects against cross-origin window.opener exploits when the target attribute is "_blank"
2020-09-04 17:05:47 -07:00

49 lines
1 KiB
Svelte

<script>
/**
* Set to `true` to use the inline variant
* @type {boolean} [inline=false]
*/
export let inline = false;
/**
* Set to `true` to disable the checkbox
* @type {boolean} [disabled=false]
*/
export let disabled = false;
/**
* Obtain a reference to the top-level HTML element
* @type {null | HTMLAnchorElement | HTMLParagraphElement} [ref=null]
*/
export let ref = null;
</script>
{#if disabled}
<p
bind:this="{ref}"
class:bx--link="{true}"
class:bx--link--disabled="{disabled}"
class:bx--link--inline="{inline}"
{...$$restProps}
on:click
on:mouseover
on:mouseenter
on:mouseleave>
<slot />
</p>
{:else}
<!-- svelte-ignore a11y-missing-attribute -->
<a
bind:this="{ref}"
class:bx--link="{true}"
class:bx--link--disabled="{disabled}"
class:bx--link--inline="{inline}"
rel="{$$restProps.target === '_blank' ? 'noopener noreferrer' : undefined}"
{...$$restProps}
on:click
on:mouseover
on:mouseenter
on:mouseleave>
<slot />
</a>
{/if}