Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Chip): Add alt attribute #15008

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/app/components/chip/chip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { TimesCircleIcon } from 'primeng/icons/timescircle';
template: `
<div [ngClass]="containerClass()" [class]="styleClass" [ngStyle]="style" *ngIf="visible" [attr.data-pc-name]="'chip'" [attr.aria-label]="label" [attr.data-pc-section]="'root'">
<ng-content></ng-content>
<img [src]="image" *ngIf="image; else iconTemplate" (error)="imageError($event)" />
<img [src]="image" *ngIf="image; else iconTemplate" (error)="imageError($event)" [alt]="alt" />
<ng-template #iconTemplate><span *ngIf="icon" [class]="icon" [ngClass]="'p-chip-icon'" [attr.data-pc-section]="'icon'"></span></ng-template>
<div class="p-chip-text" *ngIf="label" [attr.data-pc-section]="'label'">{{ label }}</div>
<ng-container *ngIf="removable">
Expand Down Expand Up @@ -48,6 +48,11 @@ export class Chip implements AfterContentInit {
* @group Props
*/
@Input() image: string | undefined;
/**
* Alt attribute of the image.
* @group Props
*/
@Input() alt: string | undefined;
/**
* Inline style of the element.
* @group Props
Expand Down
7 changes: 7 additions & 0 deletions src/app/showcase/doc/apidoc/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -7076,6 +7076,13 @@
"type": "string",
"description": "Defines the image to display."
},
{
"name": "alt",
"optional": false,
"readonly": false,
"type": "string",
"description": "Alt attribute of the image."
},
{
"name": "style",
"optional": false,
Expand Down
18 changes: 9 additions & 9 deletions src/app/showcase/doc/chip/imagedoc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,23 @@ import { Code } from '../../domain/code';
<p>The <i>image</i> property is used to display an image like an avatar.</p>
</app-docsectiontext>
<div class="card flex align-items-center gap-2 flex-wrap">
<p-chip label="Amy Elsner" image="https://primefaces.org/cdn/primeng/images/demo/avatar/amyelsner.png"></p-chip>
<p-chip label="Asiya Javayant" image="https://primefaces.org/cdn/primeng/images/demo/avatar/asiyajavayant.png"></p-chip>
<p-chip label="Onyama Limba" image="https://primefaces.org/cdn/primeng/images/demo/avatar/onyamalimba.png"></p-chip>
<p-chip label="Xuxue Feng" image="https://primefaces.org/cdn/primeng/images/demo/avatar/xuxuefeng.png" [removable]="true"></p-chip>
<p-chip label="Amy Elsner" image="https://primefaces.org/cdn/primeng/images/demo/avatar/amyelsner.png" alt="Avatar image"></p-chip>
<p-chip label="Asiya Javayant" image="https://primefaces.org/cdn/primeng/images/demo/avatar/asiyajavayant.png" alt="Avatar image"></p-chip>
<p-chip label="Onyama Limba" image="https://primefaces.org/cdn/primeng/images/demo/avatar/onyamalimba.png" alt="Avatar image"></p-chip>
<p-chip label="Xuxue Feng" image="https://primefaces.org/cdn/primeng/images/demo/avatar/xuxuefeng.png" alt="Avatar image" [removable]="true"></p-chip>
</div>
<app-code [code]="code" selector="chip-image-demo"></app-code>
`
})
export class ImageDoc {
code: Code = {
basic: `<p-chip label="Amy Elsner" image="https://primefaces.org/cdn/primeng/images/demo/avatar/amyelsner.png"></p-chip>`,
basic: `<p-chip label="Amy Elsner" image="https://primefaces.org/cdn/primeng/images/demo/avatar/amyelsner.png" alt="Avatar image"></p-chip>`,
html: `
<div class="card flex align-items-center gap-2 flex-wrap">
<p-chip label="Amy Elsner" image="https://primefaces.org/cdn/primeng/images/demo/avatar/amyelsner.png"></p-chip>
<p-chip label="Asiya Javayant" image="https://primefaces.org/cdn/primeng/images/demo/avatar/asiyajavayant.png"></p-chip>
<p-chip label="Onyama Limba" image="https://primefaces.org/cdn/primeng/images/demo/avatar/onyamalimba.png"></p-chip>
<p-chip label="Xuxue Feng" image="https://primefaces.org/cdn/primeng/images/demo/avatar/xuxuefeng.png" [removable]="true"></p-chip>
<p-chip label="Amy Elsner" image="https://primefaces.org/cdn/primeng/images/demo/avatar/amyelsner.png" alt="Avatar image"></p-chip>
<p-chip label="Asiya Javayant" image="https://primefaces.org/cdn/primeng/images/demo/avatar/asiyajavayant.png" alt="Avatar image"></p-chip>
<p-chip label="Onyama Limba" image="https://primefaces.org/cdn/primeng/images/demo/avatar/onyamalimba.png" alt="Avatar image"></p-chip>
<p-chip label="Xuxue Feng" image="https://primefaces.org/cdn/primeng/images/demo/avatar/xuxuefeng.png" alt="Avatar image" [removable]="true"></p-chip>
</div>`,
typescript: `
import { Component } from '@angular/core';
Expand Down
Loading