-
Notifications
You must be signed in to change notification settings - Fork 77
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(calcite-link): Add support for download attribute. #3758 #3922
Changes from all commits
3eb886a
e440af4
0159ec6
d5e4961
d647223
10f9d02
bdcbb2a
3e88fb9
e65c7ce
c167ef1
ef08d97
50f615a
7e74af3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,12 @@ export class CalciteLink { | |
/** is the link disabled */ | ||
@Prop({ reflect: true }) disabled = false; | ||
|
||
/** Prompts the user to save the linked URL instead of navigating to it. Can be used with or without a value: | ||
* Without a value, the browser will suggest a filename/extension | ||
* See: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#attr-download | ||
*/ | ||
@Prop({ reflect: true }) download: string | boolean = false; | ||
|
||
/** optionally pass a href - used to determine if the component should render as a link or an anchor */ | ||
@Prop({ reflect: true }) href?: string; | ||
|
||
|
@@ -65,7 +71,8 @@ export class CalciteLink { | |
} | ||
|
||
render(): VNode { | ||
const dir = getElementDir(this.el); | ||
const { download, el } = this; | ||
const dir = getElementDir(el); | ||
|
||
const iconStartEl = ( | ||
<calcite-icon | ||
|
@@ -93,6 +100,11 @@ export class CalciteLink { | |
<Host role="presentation"> | ||
<Tag | ||
class={{ [CSS_UTILITY.rtl]: dir === "rtl" }} | ||
/* | ||
When the 'download' property of type 'boolean | string' is set to true, the value is "". | ||
This works around that issue for now. | ||
*/ | ||
download={Tag === "a" && (download === "" || download) ? download : null} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jcfranco @eriklharper have you run into the following before...
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When setting via a prop we also get this lovely warning.
I guess stencil just doesn't like mixed boolean string types? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wow, interesting find. Can you add a comment there for posterity? I'll create a repro case and send it over to the Stencil team. |
||
href={Tag === "a" && this.href} | ||
ref={this.storeTagRef} | ||
rel={Tag === "a" && this.rel} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For consistency, can these assertions use props vs attributes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but if I use the prop it will emit that console warning.