Skip to content

Commit

Permalink
Fixed #2334 - Chips component: add 'readOnly' property
Browse files Browse the repository at this point in the history
  • Loading branch information
mertsincan committed Nov 4, 2021
1 parent 0cc35e5 commit 33d03c3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/components/chips/Chips.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export interface ChipsProps {
value?: any[];
max?: number;
disabled?: boolean;
readOnly?: boolean;
removable?: ChipsRemovableType;
style?: object;
className?: string;
Expand Down
9 changes: 6 additions & 3 deletions src/components/chips/Chips.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export class Chips extends Component {
value: null,
max: null,
disabled: null,
readOnly: false,
removable: true,
style: null,
className: null,
Expand All @@ -37,6 +38,7 @@ export class Chips extends Component {
value: PropTypes.array,
max: PropTypes.number,
disabled: PropTypes.bool,
readOnly: PropTypes.bool,
removable: PropTypes.oneOfType([PropTypes.bool, PropTypes.func]),
style: PropTypes.object,
className: PropTypes.string,
Expand Down Expand Up @@ -70,7 +72,7 @@ export class Chips extends Component {
}

removeItem(event, index) {
if (this.props.disabled) {
if (this.props.disabled && this.props.readOnly) {
return;
}

Expand Down Expand Up @@ -280,7 +282,7 @@ export class Chips extends Component {
}

renderRemoveIcon(value, index) {
if (!this.props.disabled && this.isRemovable(value, index)) {
if (!this.props.disabled && !this.props.readOnly && this.isRemovable(value, index)) {
return (
<span className="p-chips-token-icon pi pi-times-circle" onClick={(event) => this.removeItem(event, index)}></span>
)
Expand All @@ -305,7 +307,8 @@ export class Chips extends Component {
return (
<li className="p-chips-input-token">
<input ref={this.inputRef} placeholder={this.props.placeholder} type="text" name={this.props.name} disabled={this.props.disabled||this.isMaxedOut()}
onKeyDown={this.onKeyDown} onPaste={this.onPaste} onFocus={this.onFocus} onBlur={this.onBlur} aria-labelledby={this.props.ariaLabelledBy}/>
onKeyDown={this.onKeyDown} onPaste={this.onPaste} onFocus={this.onFocus} onBlur={this.onBlur} aria-labelledby={this.props.ariaLabelledBy}
readOnly={this.props.readOnly} />
</li>
);
}
Expand Down
6 changes: 6 additions & 0 deletions src/showcase/chips/ChipsDoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,12 @@ customChip(item) {
<td>false</td>
<td>When present, it specifies that the element should be disabled.</td>
</tr>
<tr>
<td>readOnly</td>
<td>boolean</td>
<td>false</td>
<td>When present, it specifies that the element should be read-only.</td>
</tr>
<tr>
<td>removable</td>
<td>boolean</td>
Expand Down

0 comments on commit 33d03c3

Please sign in to comment.