{% include '@bolt-elements-text-link/text-link.twig' with {
content: 'This is a text link',
attributes: {
href: 'https://google.com'
}
} only %}
Prop Name | Description | Type | Default Value | Option(s) |
---|---|---|---|---|
attributes
|
A Drupal-style attributes object with extra attributes to append to this component. |
object
| — |
|
content
*
|
Content of the text link. |
any
| — |
|
icon_before
|
Append an icon before the text. Icon element is recommended. However, <img> elements are also acceptable. |
any
| — |
|
icon_after
|
Append an icon after the text. Icon element is recommended. However, <img> elements are also acceptable. |
any
| — |
|
reversed_underline
|
Set the underline style to appear on hover instead of being always visible. |
boolean
|
false
|
|
expand_click_target
|
Expand the click target to cover up the entire area of its closest container that is not positioned static. |
boolean
|
false
|
|
npm install @bolt/elements-text-link
<a class="e-bolt-text-link">
and <a>
are acceptable at rendering a text link, though the Twig template is the recommended usage for Drupal.
class="e-bolt-text-link"
is required to get those features. Reference respective doc page for each feature.content
prop. <span>
, <em>
, and <strong>
tags are allowed.{% include '@bolt-elements-text-link/text-link.twig' with {
content: 'Click me to go to google.com',
attributes: {
href: 'https://google.com',
target: '_blank',
}
} only %}
<a href="https://google.com" target="_blank" class="e-bolt-text-link">Click me to go to google.com</a>
<a>
element or the <button>
element is being used, the proper HTML attributes should be passed.
<a>
requires the href
attribute.<button>
requires the type
attribute.{% include '@bolt-elements-text-link/text-link.twig' with {
content: 'This text link has the "href", "target", and "id" attributes',
attributes: {
href: 'https://google.com',
target: '_blank',
id: 'js-bolt-some-unique-id'
}
} only %}
<a href="https://google.com" target="_blank" id="js-bolt-some-unique-id" class="e-bolt-text-link">This text link has the "href", "target", and "id" attributes</a>
<img>
element is also acceptable.
size
and background
props for the icon component are not well supported in this scenario.<span class="e-bolt-text-link__icon-before">
and <span class="e-bolt-text-link__icon-after">
are required to wrap around the icon markup. The wrapper ensures that the icon will always wrap with the final word of the text. It will never wrap to the next line on its own.This is a text link with icons before and after
{% set icon_custom %}
<img src="/images/placeholders/500x500.jpg">
{% endset %}
{% set icon_chevron_down %}
{% include '@bolt-elements-icon/icon.twig' with {
name: 'chevron-down',
} only %}
{% endset %}
{% include '@bolt-elements-text-link/text-link.twig' with {
content: 'This is a text link with icons before and after',
icon_before: icon_custom,
icon_after: icon_chevron_down,
attributes: {
href: 'https://google.com',
}
} only %}
<a href="https://google.com" class="e-bolt-text-link"><span class="e-bolt-text-link__icon-before"><img src="/images/placeholders/500x500.jpg"></span>This is a text link with icons before and after<span class="e-bolt-text-link__icon-after"><bolt-icon name="chevron-down"></bolt-icon></span></a>
{% include '@bolt-elements-text-link/text-link.twig' with {
content: 'This is a reversed underline text link',
icon_after: icon_chevron_right,
reversed_underline: true,
attributes: {
href: 'https://google.com',
}
} only %}
<a href="https://google.com" class="e-bolt-text-link e-bolt-text-link--reversed-underline">This is a reversed underline text link</a>
expand_click_target
prop, the text link must be placed into a container that is not positioned static (e.g. absolute, fixed, relative, or sticky), and the text must explain clearly the block of content that it’s trying to cover.// Wrap this text link with a container that is not positioned static.
{% include '@bolt-elements-text-link/text-link.twig' with {
content: 'This is a block text link, its click target will cover the entire area of its closest container that is not positioned static.',
expand_click_target: true,
attributes: {
href: 'https://google.com',
}
} only %}
// Wrap this text link with a container that is not positioned static.
<a href="https://google.com" class="e-bolt-text-link e-bolt-text-link--expand-click-target">This is a block text link, its click target will cover the entire area of its closest container that is not positioned static.</a>