Skip to content

Commit 742647b

Browse files
committed
Adds disabled prop to <Link> and <NavLink>
Fixes #8
1 parent 0e34db4 commit 742647b

File tree

6 files changed

+29
-9
lines changed

6 files changed

+29
-9
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
- NPM dependencies updated to the latest versions. In particular:
66
- Babel updated from v6 to v7;
77
- Misc related fixes.
8+
- Support of `npm link` for lib development;
9+
- `disabled` prop for `<Link>` and `<NavLink>`;
810

911
### v0.8.2
1012
- Adds [**`Modal`**](docs/modal.md) component.

__tests__/shared/components/__snapshots__/GenericLink.jsx.snap

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
exports[`Absolute link, starting with http:// 1`] = `
44
<a
5-
className={null}
5+
className="src-shared-components-GenericLink-___style__link___WVE0s"
6+
disabled={false}
67
href="http://www.domain.com/test"
78
onClick={null}
89
onMouseDown={null}
@@ -15,7 +16,8 @@ exports[`Absolute link, starting with http:// 1`] = `
1516

1617
exports[`Absolute link, starting with https:// 1`] = `
1718
<a
18-
className={null}
19+
className="src-shared-components-GenericLink-___style__link___WVE0s"
20+
disabled={false}
1921
href="https://www.domain.com/test"
2022
onClick={[Function]}
2123
onMouseDown={null}
@@ -28,7 +30,8 @@ exports[`Absolute link, starting with https:// 1`] = `
2830

2931
exports[`Anchor link 1`] = `
3032
<a
31-
className={null}
33+
className="src-shared-components-GenericLink-___style__link___WVE0s"
34+
disabled={false}
3235
href="#anchor"
3336
onClick={null}
3437
onMouseDown={null}
@@ -45,13 +48,14 @@ exports[`Relative link 1`] = `
4548
onClick={[Function]}
4649
type="button"
4750
>
48-
{"to":"http/relative/link","className":null,"onMouseDown":null,"replace":false,"children":"RELATIVE LINK"}
51+
{"to":"http/relative/link","className":null,"disabled":false,"onMouseDown":null,"replace":false,"children":"RELATIVE LINK"}
4952
</button>
5053
`;
5154

5255
exports[`Relative link, with \`enforceA\` 1`] = `
5356
<a
54-
className={null}
57+
className="src-shared-components-GenericLink-___style__link___WVE0s"
58+
disabled={false}
5559
href="/relative/link"
5660
onClick={null}
5761
onMouseDown={null}
@@ -64,7 +68,8 @@ exports[`Relative link, with \`enforceA\` 1`] = `
6468

6569
exports[`Relative link, with \`openNewTab\` 1`] = `
6670
<a
67-
className={null}
71+
className="src-shared-components-GenericLink-___style__link___WVE0s"
72+
disabled={false}
6873
href="relative/link"
6974
onClick={null}
7075
onMouseDown={null}

__tests__/shared/components/__snapshots__/Link.jsx.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
exports[`Matches snapshots 1`] = `
44
<GenericLink
55
className={null}
6+
disabled={false}
67
enforceA={false}
78
onClick={null}
89
onMouseDown={null}

docs/link-and-navlink.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ Router's components, along with some additional props:
3535
inside the link;
3636
- **`className`** &mdash; *String* &mdash; Optional. Class(es) to apply to the
3737
rendered link;
38+
- **`disabled`** &mdash; *Boolean* &mdash; Optional. Disables the link;
3839
- **`enforceA`** &mdash; *Boolean* &mdash; Optional. If *true* enforces
3940
rendering of the link as a simple `<a>` element;
4041
- **`onClick`** &mdash; *Function* &mdash; Optional. An event handler to trigger
@@ -56,6 +57,7 @@ additional ones, coming from React Router:
5657
the rendered link when it is active;
5758
- **`activeStyle`** &mdash; *String* &mdash; Optional. Styles to apply to the
5859
rendered link when it is active;
60+
- **`disabled`** &mdash; *Boolean* &mdash; Optional. Disables the link;
5961
- **`exact`** &mdash; *Boolean* &mdash; Optional. When *true*, the active
6062
class/style will only be applied if the location is matched exactly;
6163
- **`isActive`** &mdash; *Function* &mdash; Optional. A function to add extra

src/shared/components/GenericLink.jsx renamed to src/shared/components/GenericLink/index.jsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,13 @@ import _ from 'lodash';
1212
import PT from 'prop-types';
1313
import React from 'react';
1414

15+
import './style.scss';
16+
1517
export default function GenericLink(props) {
1618
const {
1719
children,
1820
className,
21+
disabled,
1922
enforceA,
2023
onClick,
2124
onMouseDown,
@@ -30,14 +33,16 @@ export default function GenericLink(props) {
3033
* - It should be opened in a new tab;
3134
* - It is an absolte URL (starts with http:// or https://);
3235
* - It is anchor link (starts with #). */
33-
if (enforceA || openNewTab || to.match(/^(#|(https?|mailto):)/)) {
36+
if (disabled || enforceA || openNewTab || to.match(/^(#|(https?|mailto):)/)) {
3437
return (
3538
<a
3639
className={className}
40+
disabled={disabled}
3741
href={to}
38-
onClick={onClick}
39-
onMouseDown={onMouseDown}
42+
onClick={disabled ? e => e.preventDefault() : onClick}
43+
onMouseDown={disabled ? e => e.preventDefault() : onMouseDown}
4044
rel="noopener noreferrer"
45+
styleName="link"
4146
target={openNewTab ? '_blank' : ''}
4247
>
4348
{children}
@@ -69,6 +74,7 @@ export default function GenericLink(props) {
6974
GenericLink.defaultProps = {
7075
children: null,
7176
className: null,
77+
disabled: false,
7278
enforceA: false,
7379
onClick: null,
7480
onMouseDown: null,
@@ -80,6 +86,7 @@ GenericLink.defaultProps = {
8086
GenericLink.propTypes = {
8187
children: PT.node,
8288
className: PT.string,
89+
disabled: PT.bool,
8390
enforceA: PT.bool,
8491
onClick: PT.func,
8592
onMouseDown: PT.func,
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.link[disabled] {
2+
cursor: not-allowed;
3+
}

0 commit comments

Comments
 (0)