Skip to content
This repository has been archived by the owner on May 24, 2024. It is now read-only.

[terra-hyperlink] Hyperlink ellipses #4072

Merged
merged 10 commits into from
Mar 25, 2024
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
"wdio:lowlight": "terra wdio --themes clinical-lowlight-theme",
"wdio:fusion": "terra wdio --themes orion-fusion-theme",
"wdio:redwood": "terra wdio --themes redwood-theme",
"wdio": "terra wdio --themes terra-default-theme clinical-lowlight-theme orion-fusion-theme redwood-theme",
"wdio": "terra wdio --themes terra-default-theme clinical-lowlight-theme orion-fusion-theme",
"wdio:docker": "terra wdio --disable-selenium-service=true --themes terra-default-theme clinical-lowlight-theme orion-fusion-theme"
}
}
2 changes: 2 additions & 0 deletions packages/terra-core-docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

* Added
* Added an example for `terra-hyperlink` to demonstrate text ellipses when its content should overflow.
* Changed
* Fixed typos and imports in `terra-list` docs.

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/* eslint-disable react/forbid-dom-props */
import React from 'react';
import Hyperlink from 'terra-hyperlink';

const styles = {
truncated: {
width: '150px',
height: '50px',
borderStyle: 'dashed',
marginBottom: '10px',
},
};

export default () => (
<div role="main">
<div style={styles.truncated}>
Basic Test
<Hyperlink id="basic-hyperlink1" href="https://www.cerner.com" text="Default hyperlink that is really long and will get truncated" />
</div>
<div style={styles.truncated}>
<Hyperlink id="basic-hyperlink2" href="https://www.cerner.com" text="Default hyperlink that is really long and will get truncated" />
</div>

<div style={styles.truncated}>
External Test
<Hyperlink id="external-hyperlink1" href="https://www.cerner.com" variant="external" text="External Hyperlink that is really long and will get truncated" />
</div>
<div style={styles.truncated}>
<Hyperlink id="external-hyperlink2" href="https://www.cerner.com" variant="external" text="External Hyperlink that is really long and will get truncated" />
</div>

<div style={styles.truncated}>
Button Test
<Hyperlink id="button-hyperlink1" href="https://www.cerner.com" onClick={() => {}} text="Button Hyperlink that is really long and will get truncated" />
</div>
<div style={styles.truncated}>
<Hyperlink id="button-hyperlink2" href="https://www.cerner.com" onClick={() => {}} text="Button Hyperlink that is really long and will get truncated" />
</div>

<div style={styles.truncated}>
Document Test
<Hyperlink id="document-hyperlink1" href="https://www.cerner.com" onClick={() => {}} variant="document" text="Document Hyperlink that is really long and will get truncated" />
</div>
<div style={styles.truncated}>
<Hyperlink id="document-hyperlink2" href="https://www.cerner.com" onClick={() => {}} variant="document" text="Document Hyperlink that is really long and will get truncated" />
</div>
</div>
);
3 changes: 3 additions & 0 deletions packages/terra-hyperlink/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## Unreleased

* Changed
* Hyperlink now ellipses when its content should overflow.

## 2.67.1 - (February 27, 2024)

* Fixed
Expand Down
8 changes: 6 additions & 2 deletions packages/terra-hyperlink/src/Hyperlink.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,9 @@ class Hyperlink extends React.Component {
ref={this.linkRef}
>
<span className={cx('button-inner')}>
{text || children}
<span className={cx('inner-text')}>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we be able to accomplish this with one span?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As per the requirements, we need to make only the text have an ellipsis while the icon stays at the same level. So we need to use 2 spans for this. Otherwise it will start wrapping around if we try to implement the ellipses without having an additional inner span.

{text || children}
</span>
{getHyperlinkIcon(intl, variant)}
</span>
</button>
Expand All @@ -271,7 +273,9 @@ class Hyperlink extends React.Component {
ref={this.linkRef}
title={title}
>
{text || children}
<span className={cx('inner-text')}>
{text || children}
</span>
{getHyperlinkIcon(intl, variant)}
</a>
);
Expand Down
17 changes: 15 additions & 2 deletions packages/terra-hyperlink/src/Hyperlink.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@
background-color: transparent; // Remove the gray background on active links in IE 10
color: var(--terra-hyperlink-color, #006fc3);
cursor: pointer;
display: inline-block; // prevents variant icon from breaking onto its own line
outline: none;
text-decoration: var(--terra-hyperlink-text-decoration, underline);
touch-action: manipulation; // Enable fast tap interaction in webkit browsers; see https://webkit.org/blog/5610/more-responsive-tapping-on-ios/
vertical-align: baseline;
display: inline-flex;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we changing the style from inline-block to inline-flex? I would not expect this change to be necessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we're needing to have 2 spans with 1 being an ellipses but another being on the same level, we'll need to go with this.

Copy link
Contributor

@BenBoersma BenBoersma Mar 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also inline-block wasn't allowing us to properly truncate without the hyperlink "clickable" area extending past the "visual" area of the hyperlink or other visual issues. Using inline-flex, we were able to properly have the "text" portion of hyperlink resize itself so it would truncate without issue while allowing the icon to always render at full size.

align-items: baseline;
max-width: min-content;
width: 100%;

&:visited,
&.is-visited {
Expand Down Expand Up @@ -129,14 +132,15 @@
line-height: inherit;
margin: 0; // reset for Safari, defaults to 2px
outline: none;
overflow: visible; // reset for IE
overflow: hidden; // reset for IE
padding: 0;
pointer-events: auto;
position: relative; // reset for IE
text-align: left;
top: 0; // reset for IE
touch-action: manipulation; // Enable fast tap interaction in webkit browsers; see https://webkit.org/blog/5610/more-responsive-tapping-on-ios/
vertical-align: baseline;
width: 100%;

.button-inner {
font-family: inherit;
Expand All @@ -145,6 +149,15 @@
min-width: 0;
position: relative; // reset for IE
top: 0; // reset for IE
display: flex;
min-width: 0;
max-width: min-content;
}
}

.inner-text {
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,11 @@ exports[`Hyperlink correctly applies the theme context className 1`] = `
onKeyUp={[Function]}
onMouseDown={[Function]}
>
Default hyperlink
<span
className="inner-text"
>
Default hyperlink
</span>
</a>
</Hyperlink>
</InjectIntl(Hyperlink)>
Expand All @@ -97,7 +101,11 @@ exports[`Hyperlink should render a audio hyperlink 1`] = `
data-focus-styles-enabled="true"
href="https://www.cerner.com"
>
Audio hyperlink
<span
class="inner-text"
>
Audio hyperlink
</span>
<span
class="icon"
>
Expand Down Expand Up @@ -127,7 +135,11 @@ exports[`Hyperlink should render a default hyperlink 1`] = `
data-focus-styles-enabled="true"
href="https://www.cerner.com"
>
Default hyperlink
<span
class="inner-text"
>
Default hyperlink
</span>
</a>
`;

Expand All @@ -138,7 +150,11 @@ exports[`Hyperlink should render a disabled hyperlink 1`] = `
data-focus-styles-enabled="true"
role="link"
>
Disabled hyperlink
<span
class="inner-text"
>
Disabled hyperlink
</span>
</a>
`;

Expand All @@ -149,7 +165,11 @@ exports[`Hyperlink should render a document hyperlink 1`] = `
data-focus-styles-enabled="true"
href="https://www.cerner.com"
>
Document hyperlink
<span
class="inner-text"
>
Document hyperlink
</span>
<span
class="icon"
>
Expand Down Expand Up @@ -182,7 +202,11 @@ exports[`Hyperlink should render a external hyperlink 1`] = `
rel="noopener noreferrer"
target="_blank"
>
External hyperlink
<span
class="inner-text"
>
External hyperlink
</span>
<span
class="icon"
>
Expand Down Expand Up @@ -214,7 +238,11 @@ exports[`Hyperlink should render a hyperlink button when oonClick is provided 1`
<span
class="button-inner"
>
Default hyperlink button
<span
class="inner-text"
>
Default hyperlink button
</span>
</span>
</button>
`;
Expand All @@ -226,7 +254,11 @@ exports[`Hyperlink should render a image hyperlink 1`] = `
data-focus-styles-enabled="true"
href="https://www.cerner.com"
>
Image hyperlink
<span
class="inner-text"
>
Image hyperlink
</span>
<span
class="icon"
>
Expand Down Expand Up @@ -256,7 +288,11 @@ exports[`Hyperlink should render a underline hidden hyperlink 1`] = `
data-focus-styles-enabled="true"
href="https://www.cerner.com"
>
Underline hidden hyperlink
<span
class="inner-text"
>
Underline hidden hyperlink
</span>
</a>
`;

Expand All @@ -267,7 +303,11 @@ exports[`Hyperlink should render a video hyperlink 1`] = `
data-focus-styles-enabled="true"
href="https://www.cerner.com"
>
Video hyperlink
<span
class="inner-text"
>
Video hyperlink
</span>
<span
class="icon"
>
Expand Down Expand Up @@ -299,7 +339,11 @@ exports[`Hyperlink should render with custom props 1`] = `
rel="nofollow"
target="_self"
>
Custom props hyperlink
<span
class="inner-text"
>
Custom props hyperlink
</span>
</a>
`;

Expand All @@ -312,7 +356,11 @@ exports[`Hyperlink should render with custom props with external variant 1`] = `
rel="external"
target="_parent"
>
Custom target and rel props external hyperlink
<span
class="inner-text"
>
Custom target and rel props external hyperlink
</span>
<span
class="icon"
>
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions packages/terra-hyperlink/tests/wdio/hyperlink-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,9 @@ Terra.describeViewports('Hyperlink', ['tiny'], () => {

Terra.validates.element('hyperlink-button');
});

it('should render Hyperlinks with ellipses when the context should overflow', () => {
browser.url('/raw/tests/cerner-terra-core-docs/hyperlink/truncated-hyperlink');
Terra.validates.element('truncated');
});
});
Loading