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>
<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" 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 |
---|---|---|---|---|
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 |
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 |
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 ink text. (only with variations other than "default") | string | undefined |
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() |
padding | padding | Controls the padding of the component (only with variations other than "default") | "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" | "default" | "default" |
Methods #
setFocus(options?: FocusOptions) => Promise<void>
#
Sets focus on the specified duet-link
. Use this method instead of the global
link.focus()
.
Returns #
Type: Promise<void>
Shadow Parts #
Part | Description |
---|---|
"duet-link" | piercing selector for styling the link |
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.