Skip to content

Commit da2297d

Browse files
committed
feat(Label): allow isClickable to be set manually
1 parent 9b41c4f commit da2297d

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

packages/react-core/src/components/Label/Label.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ export interface LabelProps extends React.HTMLProps<HTMLSpanElement> {
3131
isDisabled?: boolean;
3232
/** Flag indicating the label is editable. */
3333
isEditable?: boolean;
34+
/** Flag indicating the label is clickable. This flag will automatically be set if a href is passed, or if an onClick handler is passed and the label is not an overflow or add variant. */
35+
isClickable?: boolean;
3436
/** Additional props passed to the editable label text div. Optionally passing onInput and onBlur callbacks will allow finer custom text input control. */
3537
editableProps?: any;
3638
/** Callback when an editable label completes an edit. */
@@ -110,6 +112,7 @@ export const Label: React.FunctionComponent<LabelProps> = ({
110112
isCompact = false,
111113
isDisabled = false,
112114
isEditable = false,
115+
isClickable: isClickableProp = false,
113116
editableProps,
114117
textMaxWidth,
115118
tooltipPosition,
@@ -132,7 +135,7 @@ export const Label: React.FunctionComponent<LabelProps> = ({
132135

133136
const isOverflowLabel = variant === 'overflow';
134137
const isAddLabel = variant === 'add';
135-
const isClickable = (onLabelClick && !isOverflowLabel && !isAddLabel) || href;
138+
const isClickable = isClickableProp || (onLabelClick && !isOverflowLabel && !isAddLabel) || href;
136139

137140
let _icon;
138141
if (status) {

packages/react-core/src/components/Label/examples/Label.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ import './Label.css';
3030

3131
```
3232

33-
### Label with router link
33+
### Label with custom render
34+
35+
Labels may be passed a custom renderer to display customized content or for use with router components.
3436

3537
```ts file="LabelRouterLink.tsx"
3638

packages/react-core/src/components/Label/examples/LabelRouterLink.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
11
import React from 'react';
22
import { Label } from '@patternfly/react-core';
33
import InfoCircleIcon from '@patternfly/react-icons/dist/esm/icons/info-circle-icon';
4-
import { Link } from '@reach/router';
54

65
export const LabelRouterLink: React.FunctionComponent = () => (
76
<Label
87
color="blue"
98
icon={<InfoCircleIcon />}
109
onClose={() => Function.prototype}
1110
render={({ className, content, componentRef }) => (
12-
<Link to="/" className={className} innerRef={componentRef}>
11+
<a className={className} ref={componentRef}>
1312
{content}
14-
</Link>
13+
</a>
14+
/** A router link would look like the following:
15+
* <Link to="/" className={className} ref={componentRef}>
16+
* {content}
17+
* </Link>
18+
*/
1519
)}
1620
textMaxWidth="16ch"
21+
isClickable // can be passed manually to remove the default underline text-decoration of links
1722
>
1823
Blue label router link with icon that overflows
1924
</Label>

0 commit comments

Comments
 (0)