Skip to content

Commit

Permalink
[Link] underlined by default and add removeUnderline prop (#3705)
Browse files Browse the repository at this point in the history
Co-authored-by: Alex Page <alex@alexpage.com.au>
  • Loading branch information
ashwinnarayanan2001 and Alex Page committed Jan 20, 2021
1 parent d47c98a commit c44558b
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 11 deletions.
1 change: 1 addition & 0 deletions UNRELEASED.md
Expand Up @@ -4,6 +4,7 @@ Use [the changelog guidelines](https://git.io/polaris-changelog-guidelines) to f

### Breaking changes

- `Link` is underlined by default, added `removeUnderline` prop to remove underline ([#3705](https://github.com/Shopify/polaris-react/pull/3705))
- Remove `light` property from `Tooltip` as it now defaults to a light background ([#3846](https://github.com/Shopify/polaris-react/pull/3846))
- Made `title` property required in `Modal` for accessibility label, added `hideTitle` property ([#3803](https://github.com/Shopify/polaris-react/pull/3803))
- Added required `ariaLabel` property in `Sheet` ([#3852](https://github.com/Shopify/polaris-react/pull/3852))
Expand Down
36 changes: 30 additions & 6 deletions src/components/DataTable/README.md
Expand Up @@ -279,7 +279,11 @@ Use to help merchants find relevant, finer grained data sets.
function DataTableLinkExample() {
const rows = [
[
<Link url="https://www.example.com" key="emerald-silk-gown">
<Link
removeUnderline
url="https://www.example.com"
key="emerald-silk-gown"
>
Emerald Silk Gown
</Link>,
'$875.00',
Expand All @@ -288,7 +292,11 @@ function DataTableLinkExample() {
'$122,500.00',
],
[
<Link url="https://www.example.com" key="mauve-cashmere-scarf">
<Link
removeUnderline
url="https://www.example.com"
key="mauve-cashmere-scarf"
>
Mauve Cashmere Scarf
</Link>,
'$230.00',
Expand All @@ -297,7 +305,11 @@ function DataTableLinkExample() {
'$19,090.00',
],
[
<Link url="https://www.example.com" key="navy-merino-wool">
<Link
removeUnderline
url="https://www.example.com"
key="navy-merino-wool"
>
Navy Merino Wool Blazer with khaki chinos and yellow belt
</Link>,
'$445.00',
Expand Down Expand Up @@ -338,7 +350,11 @@ function FullDataTableExample() {

const initiallySortedRows = [
[
<Link url="https://www.example.com" key="emerald-silk-gown">
<Link
removeUnderline
url="https://www.example.com"
key="emerald-silk-gown"
>
Emerald Silk Gown
</Link>,
'$875.00',
Expand All @@ -347,7 +363,11 @@ function FullDataTableExample() {
'$121,500.00',
],
[
<Link url="https://www.example.com" key="mauve-cashmere-scarf">
<Link
removeUnderline
url="https://www.example.com"
key="mauve-cashmere-scarf"
>
Mauve Cashmere Scarf
</Link>,
'$230.00',
Expand All @@ -356,7 +376,11 @@ function FullDataTableExample() {
'$19,090.00',
],
[
<Link url="https://www.example.com" key="navy-merino-wool">
<Link
removeUnderline
url="https://www.example.com"
key="navy-merino-wool"
>
Navy Merino Wool Blazer with khaki chinos and yellow belt
</Link>,
'$445.00',
Expand Down
11 changes: 6 additions & 5 deletions src/components/Link/Link.scss
Expand Up @@ -9,18 +9,17 @@
border: 0;
font-size: inherit;
color: var(--p-interactive);
text-decoration: none;
text-decoration: underline;
cursor: pointer;

&:hover {
color: var(--p-interactive-hovered);
text-decoration: underline;
text-decoration: none;
}

&:focus {
$chrome-default-outline: rgba(0, 103, 244, 0.247) auto rem(4.5px);
outline: var(--p-override-none);
text-decoration: underline;
}

&:focus:not(:active) {
Expand All @@ -30,7 +29,6 @@
&:active {
position: relative;
color: var(--p-interactive-pressed);
text-decoration: underline;

&::before {
content: '';
Expand Down Expand Up @@ -68,11 +66,14 @@

.monochrome {
color: inherit;
text-decoration: underline;

&:hover,
&:focus,
&:active {
color: inherit;
}
}

.removeUnderline {
text-decoration: none;
}
4 changes: 4 additions & 0 deletions src/components/Link/Link.tsx
Expand Up @@ -20,6 +20,8 @@ export interface LinkProps {
external?: boolean;
/** Makes the link color the same as the current text color and adds an underline */
monochrome?: boolean;
/** Removes text decoration underline to the link*/
removeUnderline?: boolean;
/** Callback when a link is clicked */
onClick?(): void;
/** Descriptive text to be read to screenreaders */
Expand All @@ -33,6 +35,7 @@ export function Link({
external,
id,
monochrome,
removeUnderline,
accessibilityLabel,
}: LinkProps) {
const i18n = useI18n();
Expand Down Expand Up @@ -63,6 +66,7 @@ export function Link({
const className = classNames(
styles.Link,
shouldBeMonochrome && styles.monochrome,
removeUnderline && styles.removeUnderline,
);

return url ? (
Expand Down
25 changes: 25 additions & 0 deletions src/components/Link/README.md
Expand Up @@ -110,6 +110,31 @@ Use for text links that should open in a new browser tab (or window, depending o

Use the `url` prop to give the link component a valid `href` value. This allows the element to be identified as a link to assistive technologies and gives it default keyboard support.

The Link component is underlined to give interactive elements a shape. This allows links to not rely on color from being the only way users can tell if an element is interactive.

<!-- usageblock -->

#### Do

- Remove the link underline when link is repeated in a list or navigation
- Use underlines for links when used inline content

```jsx
<p>
Learn more about <Link>Fraud Protect</Link>.
</p>
```

#### Don’t

- Remove underlines when the user cannot determine it's interactivity

```jsx
<Link removeUnderline>Learn more about Fraud Protect.</Link>
```

<!-- end -->

### Submitting data

Merchants generally expect links to navigate, and not to submit data or take action. If you need a component that doesn’t have a URL associated with it, then use the [button component](https://polaris.shopify.com/components/actions/button) instead.
Expand Down
8 changes: 8 additions & 0 deletions src/components/Link/tests/Link.test.tsx
Expand Up @@ -140,4 +140,12 @@ describe('<Link />', () => {
});
});
});

describe('removesUnderline', () => {
it('adds removeUnderline class to the link', () => {
const link = mountWithAppProvider(<Link removeUnderline>Test</Link>);

expect(link.find('button').hasClass('removeUnderline')).toBe(true);
});
});
});

0 comments on commit c44558b

Please sign in to comment.