Skip to content

Commit

Permalink
feat(components/forms): file attachment automatically creates downloa…
Browse files Browse the repository at this point in the history
…d link for file uploads (#2608)
  • Loading branch information
Blackbaud-CoreyArcher authored Aug 15, 2024
1 parent dd59411 commit 321e93a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,12 @@
/>
<span
*ngIf="value || currentThemeName === 'default'"
class="sky-file-attachment-name"
class="sky-file-attachment-file-link"
>
<a
*ngIf="value; else noFileRef"
[href]="isData ? value.url : undefined"
[download]="isData ? value.file.name : undefined"
[attr.title]="fileName"
(click)="emitClick()"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
}
}

.sky-file-attachment-name {
.sky-file-attachment-file-link {
padding: 0 5px;

a {
Expand Down Expand Up @@ -105,7 +105,7 @@
display: flex;
align-items: flex-start;

.sky-file-attachment-name {
.sky-file-attachment-file-link {
margin: $sky-theme-modern-space-sm $sky-theme-modern-space-sm 0 0;
padding: 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,13 @@ describe('File attachment', () => {
}

function getFileNameLinkEl(): HTMLElement | null {
return el.querySelector('.sky-file-attachment-name a');
return el.querySelector('.sky-file-attachment-file-link a');
}

function getFileNameText(): string | undefined {
return el.querySelector('.sky-file-attachment-name')?.textContent?.trim();
return el
.querySelector('.sky-file-attachment-file-link')
?.textContent?.trim();
}

function getDeleteEl(): HTMLElement | null {
Expand Down Expand Up @@ -689,7 +691,9 @@ describe('File attachment', () => {
expect(getFileNameText()).toBe('abcdefghijklmnopqrstuvwxyz...');

expect(
el.querySelector('.sky-file-attachment-name > a')?.getAttribute('title'),
el
.querySelector('.sky-file-attachment-file-link > a')
?.getAttribute('title'),
).toBe(
'abcdefghijklmnopqrstuvwxyz12345.png',
'Expected the anchor title to display the full file name.',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,7 @@ export class SkyFileAttachmentComponent
public fileChange = new EventEmitter<SkyFileAttachmentChange>();

/**
* Fires when users select the file name link. Make sure to bind the event.
* If you do not, the file name link will be a dead link.
* Fires when users select the file name link.
*/
@Output()
public fileClick = new EventEmitter<SkyFileAttachmentClick>();
Expand Down Expand Up @@ -244,8 +243,10 @@ export class SkyFileAttachmentComponent

if (isNewValue) {
if (value) {
this.isData = value.url?.startsWith('data:');
this.isImage = this.#fileItemService.isImage(value);
} else {
this.isData = false;
this.isImage = false;
}
this.#setFileName(value);
Expand Down Expand Up @@ -278,6 +279,8 @@ export class SkyFileAttachmentComponent

public isImage = false;

protected isData = false;

protected get isRequired(): boolean {
return (
this.required ||
Expand Down

0 comments on commit 321e93a

Please sign in to comment.