Skip to content

Commit

Permalink
Merge pull request #14593 from AndrewAKovalenko/add-maxlength-to-chip…
Browse files Browse the repository at this point in the history
…s-component

Fix #14592: Added maxLength property to p-chips component
  • Loading branch information
cetincakiroglu authored Feb 23, 2024
2 parents dd3ca7b + 437a7b0 commit c785276
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/app/components/chips/chips.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,14 @@ describe('Chips', () => {
expect(inputEl.nativeElement.disabled).toEqual(false);
});

it('should set maxlength to input element', () => {
chips.max = 2;
fixture.detectChanges();

const inputEl = fixture.debugElement.query(By.css('input'));
expect(inputEl.attributes.maxlength).toEqual('2');
});

it('should delete item', () => {
chips.value = ['primeng'];
fixture.detectChanges();
Expand Down
6 changes: 6 additions & 0 deletions src/app/components/chips/chips.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export const CHIPS_VALUE_ACCESSOR: any = {
#inputtext
type="text"
[attr.id]="inputId"
[attr.maxlength]="maxLength"
[attr.placeholder]="value && value.length ? null : placeholder"
[attr.tabindex]="tabindex"
(keydown)="onKeyDown($event)"
Expand Down Expand Up @@ -140,6 +141,11 @@ export class Chips implements AfterContentInit, ControlValueAccessor {
* @group Props
*/
@Input() max: number | undefined;
/**
* Maximum length of a chip.
* @group Props
*/
@Input() maxLength: number | undefined;
/**
* Defines a string that labels the input for accessibility.
* @group Props
Expand Down
9 changes: 8 additions & 1 deletion src/app/showcase/doc/apidoc/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -7190,6 +7190,13 @@
"type": "number",
"description": "Maximum number of entries allowed."
},
{
"name": "maxLength",
"optional": false,
"readonly": false,
"type": "number",
"description": "Maximum length of a chip."
},
{
"name": "ariaLabel",
"optional": false,
Expand Down Expand Up @@ -27736,4 +27743,4 @@
}
}
}
}
}

0 comments on commit c785276

Please sign in to comment.