Skip to content

Commit a0100a0

Browse files
authored
feat(Label): allow isClickable to be set manually (#11549)
* feat(Label): allow isClickable to be set manually * update prop description with use case * update example name
1 parent b3a59bc commit a0100a0

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
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. This should be manually set when using the render prop. */
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: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ import './Label.css';
2929

3030
```
3131

32+
### Label with custom render
33+
34+
Labels may be passed a custom renderer to display customized content or for use with router components. When using a custom render, `isClickable` may also be passed to remove the underline text decoration of anchors or router links.
35+
36+
```ts file="LabelCustomRender.tsx"
37+
38+
```
39+
3240
### Editable labels
3341

3442
Click or press either enter or space to begin editing a label. After editing, click outside the label or press enter again to complete the edit. To cancel an edit, press escape.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import React from 'react';
2+
import { Label } from '@patternfly/react-core';
3+
import InfoCircleIcon from '@patternfly/react-icons/dist/esm/icons/info-circle-icon';
4+
5+
export const LabelCustomRender: React.FunctionComponent = () => (
6+
<Label
7+
color="blue"
8+
icon={<InfoCircleIcon />}
9+
onClose={() => Function.prototype}
10+
render={({ className, content, componentRef }) => (
11+
<a className={className} ref={componentRef}>
12+
{content}
13+
</a>
14+
)}
15+
textMaxWidth="16ch"
16+
isClickable
17+
>
18+
Blue label router link with icon that overflows
19+
</Label>
20+
);

0 commit comments

Comments
 (0)