Skip to content

Commit

Permalink
Merge pull request #5769 from TonySpegel:feat/button-download-filename
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 723241863
  • Loading branch information
copybara-github committed Feb 4, 2025
2 parents 29d6763 + 9e84130 commit 919fe12
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
8 changes: 8 additions & 0 deletions button/internal/button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ export abstract class Button extends buttonBaseClass implements FormSubmitter {
*/
@property() href = '';

/**
* The filename to use when downloading the linked resource.
* If not specified, the browser will determine a filename.
* This is only applicable when the button is used as a link (`href` is set).
*/
@property() download = '';

/**
* Where to display the linked `href` URL for a link button. Common options
* include `_blank` to open in a new tab.
Expand Down Expand Up @@ -184,6 +191,7 @@ export abstract class Button extends buttonBaseClass implements FormSubmitter {
aria-haspopup="${ariaHasPopup || nothing}"
aria-expanded="${ariaExpanded || nothing}"
href=${this.href}
download=${this.download || nothing}
target=${this.target || nothing}
>${this.renderContent()}
</a>`;
Expand Down
7 changes: 7 additions & 0 deletions chips/internal/assist-chip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ import {Chip} from './chip.js';
export class AssistChip extends Chip {
@property({type: Boolean}) elevated = false;
@property() href = '';
/**
* The filename to use when downloading the linked resource.
* If not specified, the browser will determine a filename.
* This is only applicable when the chip is used as a link (`href` is set).
*/
@property() download = '';
@property() target: '_blank' | '_parent' | '_self' | '_top' | '' = '';

protected get primaryId() {
Expand Down Expand Up @@ -49,6 +55,7 @@ export class AssistChip extends Chip {
id="link"
aria-label=${ariaLabel || nothing}
href=${this.href}
download=${this.download || nothing}
target=${this.target || nothing}
>${content}</a
>
Expand Down
8 changes: 8 additions & 0 deletions iconbutton/internal/icon-button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,13 @@ export class IconButton extends iconButtonBaseClass implements FormSubmitter {
*/
@property() href = '';

/**
* The filename to use when downloading the linked resource.
* If not specified, the browser will determine a filename.
* This is only applicable when the icon button is used as a link (`href` is set).
*/
@property() download = '';

/**
* Sets the underlying `HTMLAnchorElement`'s `target` attribute.
*/
Expand Down Expand Up @@ -191,6 +198,7 @@ export class IconButton extends iconButtonBaseClass implements FormSubmitter {
class="link"
id="link"
href="${this.href}"
download="${this.download || nothing}"
target="${this.target || nothing}"
aria-label="${ariaLabel || nothing}">
${this.renderTouchTarget()}
Expand Down

0 comments on commit 919fe12

Please sign in to comment.