Skip to content

Commit

Permalink
Merge pull request #42 from acelaya/feature/extend-rel
Browse files Browse the repository at this point in the history
Feature/extend rel
  • Loading branch information
acelaya authored Jan 3, 2023
2 parents 06a4426 + 4dcbbed commit 44d658c
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 7 deletions.
File renamed without changes.
2 changes: 1 addition & 1 deletion .github/workflows/publish-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: ['16.x']
node-version: ['18.x']
steps:
- name: Checkout code
uses: actions/checkout@v2
Expand Down
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,23 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org).

## [2.0.1] - 2023-01-03
### Added
* *Nothing*

### Changed
* *Nothing*

### Deprecated
* *Nothing*

### Removed
* *Nothing*

### Fixed
* Ensured provided `rel` attribute does not overwrite `noopener noreferrer`, but it's appended instead.


## [2.0.0] - 2022-05-12
### Added
* *Nothing*
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# React External Link

[![Build Status](https://img.shields.io/github/workflow/status/acelaya/react-external-link/Continuous%20integration/main?logo=github&style=flat-square)](https://github.com/acelaya/react-external-link/actions?query=workflow%3A%22Continuous+integration%22)
[![Build Status](https://img.shields.io/github/actions/workflow/status/acelaya/react-external-link/ci.yml?branch=main&logo=github&style=flat-square)](https://github.com/acelaya/react-external-link/actions/workflows/ci.yml)
[![Code Coverage](https://img.shields.io/codecov/c/gh/acelaya/react-external-link/main?style=flat-square)](https://app.codecov.io/gh/acelaya/react-external-link)
[![npm](https://img.shields.io/npm/v/react-external-link?style=flat-square)](https://www.npmjs.com/package/react-external-link)
[![npm downloads](https://img.shields.io/npm/dt/react-external-link?style=flat-square)](https://www.npmjs.com/package/react-external-link)
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ version: '3'
services:
react_external_link:
container_name: react_external_link
image: node:16.14-alpine
image: node:18.12-alpine
volumes:
- ./:/react-external-link
4 changes: 2 additions & 2 deletions src/ExternalLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ export interface ExternalLinkProps extends AnchorHTMLAttributes<Element> {
children?: ReactNode;
}

export const ExternalLink: FC<ExternalLinkProps> = ({ href, children, ...rest }: ExternalLinkProps) => (
<a target="_blank" rel="noopener noreferrer" href={href} {...rest}>
export const ExternalLink: FC<ExternalLinkProps> = ({ href, children, rel, ...rest }: ExternalLinkProps) => (
<a target="_blank" rel={`noopener noreferrer${rel ? ` ${rel}` : ''}`} href={href} {...rest}>
{children ?? href}
</a>
);
11 changes: 9 additions & 2 deletions test/ExternalLink.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import '@testing-library/jest-dom/extend-expect';
import { ExternalLink } from '../src';

describe('<ExternalLink />', () => {
const setUp = (href = 'href', children?: ReactNode): ChildNode => {
const { container } = render(<ExternalLink href={href} children={children} />);
const setUp = (href = 'href', children?: ReactNode, rel?: string): ChildNode => {
const { container } = render(<ExternalLink href={href} children={children} rel={rel} />);
const { firstChild } = container;

if (!firstChild) {
Expand Down Expand Up @@ -38,4 +38,11 @@ describe('<ExternalLink />', () => {
expect(externalLink).toHaveAttribute('href', href);
expect(externalLink).toHaveTextContent(children);
});

it('appends provided rel to protected one', () => {
const externalLink = setUp('href', undefined, 'me');

expect(externalLink).toHaveAttribute('target', '_blank');
expect(externalLink).toHaveAttribute('rel', 'noopener noreferrer me');
});
});

0 comments on commit 44d658c

Please sign in to comment.