Link Ready
Links are used in content paragraphs to create pathways from one page to another. If you need a link with semi bold font-weight and/or icon, please use Button component instead.
Examples #
<duet-link url="https://www.duetds.com">Link text</duet-link>
<script>
// Select the above link
var link = document.querySelector("duet-link")
// Listen for clicks in the link
link.addEventListener("click", function (e) {
e.preventDefault()
console.log("Link clicked", e)
})
</script>
<duet-link url="https://www.duetds.com" external>Link that opens a new window</duet-link>
<duet-link url="/assets/downloads/localtapiola-brand-guidelines.pdf" download="Graafinen-ohjeisto.pdf">Download attribute with value</duet-link>
<duet-spacer size="x-large"></duet-spacer>
<duet-link url="/assets/downloads/localtapiola-brand-guidelines.pdf" download>Empty download attribute</duet-link>
<duet-spacer size="x-large"></duet-spacer>
<duet-link url="/assets/downloads/localtapiola-brand-guidelines.pdf" download="false">Any attribute value will be treated as file name</duet-link>
<duet-spacer size="x-large"></duet-spacer>
<duet-link url="/assets/downloads/localtapiola-brand-guidelines.pdf">No download attribute will make it simple link</duet-link>
<style>
duet-link::part(duet-link) {
text-decoration: none
}
</style>
<duet-link url="https://www.duetds.com">Link text</duet-link>
<duet-link variation="block" url="https://www.duetds.com">Basic block link</duet-link>
<duet-link variation="block" external url="https://www.duetds.com">External block link</duet-link>
<duet-link variation="block" url="https://www.duetds.com">Another block link with longer text. Another block link with longer text. Another block link with longer text.</duet-link>
<duet-link icon="messaging-alert" variation="block" url="https://www.duetds.com">Block link with an icon</duet-link>
<duet-link icon="messaging-alert" padding="none" variation="block" url="https://www.duetds.com">Block link without padding</duet-link>
Properties #
Property | Attribute | Description | Type | Default |
---|---|---|---|---|
accessibleExpanded | accessible-expanded | If a button expands or collapses adjacent content, then use the ariaExpanded prop to add the aria-expanded attribute to the button. Set the value to convey the current expanded (true) or collapsed (false) state of the content. Only works with empty url. | boolean | undefined |
accessibleLabel | accessible-label | Adds accessible label for the link that is only shown for screen readers. Typically, this label text replaces the visible text on the link for users who use assistive technology. | string | undefined |
accessibleLabelDownload | accessible-label-download | Adds accessible label for tooltip that is shown in external link (url & external have both been set) | string | getLocaleString(this.accessibleLabelDownloadDefaults) |
accessibleLabelDownloadDefaults | accessible-label-download-default | Defaults for accessibleLabelDownload | DuetLangObject | string | DuetStringsDownloadLinkDefaults |
accessibleLabelExternal | accessible-label-external | Adds accessible label for tooltip that is shown in external link (url & external have both been set) | string | getLocaleString(this.accessibleLabelExternalDefaults) |
accessibleLabelExternalDefaults | accessible-label-external-default | Defaults for accessibleLabelExternal | DuetLangObject | string | DuetStringsExternalDefaults |
accessiblePopup | accessible-popup | Use this property to add an aria-haspopup attribute to a button. Only works with empty url. | string | "false" |
download | download | Causes the browser to treat the linked URL as a download. Can be used with or without a filename value. With a value, it will be used as the name for the downloaded file. Without a value, the browser will suggest a name. NOTE: this attribute only works for same-origin URLs, or the blob: and data: schemes. | string | null |
external | external | Forces URL to open in a new browser tab. Used together with URL prop. | boolean | false |
icon | icon | Icon to display on the left side of the link text (only with "block" and "button" variations) | string | undefined |
iconBackground | icon-background | Color of the icon to display (only with "button" variation) | string | null |
iconColor | icon-color | Color of the icon to display (only with "block" and "button" variations) | string | "currentColor" |
iconResponsive | icon-responsive | Whether the icon changes its size responsively (only with "block" variation) | boolean | false |
identifier | identifier | Adds a unique identifier for the link. Please note that with this particular component this id is added inside Shadow DOM. If you need an id on the html element, use regular id attribute instead. | string | undefined |
language | language | [DEPRECATED] this is now handled via the html lang tag, and is no longer used - kept to avoid breaking changes and ease unit testing The currently active language. This setting changes the external link accessible label to match the chosen language. | "en" | "fi" | "sv" | getLanguage() |
margin | margin | Controls the margin of the component (only with "button" variation) | "auto" | "none" | "auto" |
padding | padding | Controls the padding of the component (only with "block" variation) | "auto" | "none" | "auto" |
tabToLink | tab-to-link | Initially visually hidden link, which is shown on focus. | boolean | false |
theme | theme | Theme of the button. | "" | "default" | "turva" | "" |
url | url | A destination to link to, rendered in the href attribute of a link. | string | "#" |
variation | variation | Style variation of the link. | "block" | "button" | "default" | "default" |
Methods #
setFocus(options?: FocusOptions) => Promise<void>
#
Sets focus on the specified duet-link
. Use this method instead of the global
link.focus()
.
Parameters #
Name | Type | Description |
---|---|---|
options | FocusOptions |
Returns #
Type: Promise<void>
Shadow Parts #
Part | Description |
---|---|
"block-chevron" | piercing selector for styling the block chevron |
"duet-link" | piercing selector for styling the link |
"duet-link-content" | piercing selector for styling the link content wrapper |
Usage #
This section includes guidelines for designers and developers about the usage of this component in different contexts.
When to use #
- For navigation where the link appears within or following a sentence. Like this link here.
- When you need to link to another page.
When not to use #
Accessibility #
This component has been validated to meet the WCAG 2.1 AA accessibility guidelines. You can find additional information regarding accessibility of this component below.
- You can use
accessibleLabel
property to add an accessible label for the link that is only shown for screen readers. Typically, this label text replaces the visible text on the link for users who use assistive technology. - Use
external
property for links that open into a new browser window. Using this property the component makes sure that this behaviour is communicated correctly to users of assistive technology as well. - Make sure to pass the correct language to the component when using the above funtionality (fi, sv or en).
Integration
For integration, event and theming guidelines, please see Using Components. This documentation explains how to implement and use Duet’s components across different technologies like Angular, React or Vanilla JavaScript.
Tutorials
Follow these practical tutorials to learn how to build simple page layouts using Duet’s CSS Framework, Web Components and other features:
Building Layouts
TutorialsUsing CLI Tools
TutorialsCreating Custom Patterns
TutorialsServer Side Rendering
TutorialsSharing Prototypes
TutorialsUsage With Markdown
Troubleshooting
If you experience any issues while using a component, please head over to the Support page for more guidelines and help.